Newer
Older
TB_Chris / TbUT / src / .svn / text-base / TbUTPedestalRetreiver.cpp.svn-base
  1. /*
  2. * TbUTPedestalRetreiver.cpp
  3. *
  4. * Created on: Jan 2, 2015
  5. * Author: ADendek
  6. */
  7. #include "TbUTPedestalRetreiver.h"
  8.  
  9. #include "TbUTRawData.h"
  10. #include <iostream>
  11. #include <fstream>
  12.  
  13. using namespace TbUT;
  14. using namespace std;
  15.  
  16. PedestalRetreiver::PedestalRetreiver(Pedestal& p_pedestal, IFileValidator& p_fileValidator, const std::string& p_filename):
  17. m_isFillingPedestalRequited(true),
  18. m_pedestal(p_pedestal),
  19. m_fileValidator(p_fileValidator),
  20. m_filename(p_filename)
  21. {
  22. }
  23.  
  24. void PedestalRetreiver::savePedestalToFile(const std::string& /*p_filename*/)
  25. {
  26. cout<<"Not saving Pedestal!"<<endl;
  27. // do not save nothing!
  28. }
  29.  
  30.  
  31. StatusCode PedestalRetreiver::processEvent(RawData<>* /*p_data*/)
  32. {
  33. if(!m_isFillingPedestalRequited){
  34. cout<<"PedestalRetreiver===> pedestals ok!"<<endl;
  35. return StatusCode::SUCCESS;
  36. }
  37.  
  38. if(!m_fileValidator.validateFile() ){
  39. cout<<"validation error!"<<endl;
  40. return StatusCode::FAILURE;
  41. }
  42. getPedestalFromFile();
  43. return StatusCode::SUCCESS;
  44. }
  45.  
  46. void PedestalRetreiver::getPedestalFromFile()
  47. {
  48. cout<<"PedestalRetreiver===>getting pedestals from file: "<< m_filename<<endl;
  49. int l_channelsNumber=RawData<>::getnChannelNumber();
  50. ifstream l_file(m_filename);
  51. if(!l_file.good()){
  52. std::string lerrorMsg="Cannot open input pedestal file: "+m_filename;
  53. throw PedestalCalculatorError(lerrorMsg);
  54. }
  55.  
  56. for(int channel=0;channel<l_channelsNumber;channel++)
  57. {
  58. double l_pedestalFromFile=0;
  59. l_file >> l_pedestalFromFile;
  60. m_pedestal.setPedestal(channel,l_pedestalFromFile);
  61. cout<<"PedestalRetreiver===> channel: "<< channel <<"pedestal: "<<l_pedestalFromFile<<endl;
  62. }
  63. m_pedestal.setNormalizationFlag(true);
  64. m_isFillingPedestalRequited=false;
  65. }