CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CalibCalorimetry/HcalStandardModules/src/HcalLedAnalyzer.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EventSetup.h"
00002 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00003 
00004 #include <CalibCalorimetry/HcalStandardModules/interface/HcalLedAnalyzer.h>
00005 //#include "CondTools/Hcal/interface/HcalDbTool.h"
00006 #include "CondFormats/HcalObjects/interface/HcalPedestals.h"
00007 
00008 
00009 
00010 namespace {
00011   bool defaultsFile (const std::string fParam) {
00012     return fParam == "defaults";
00013   }
00014 
00015   bool asciiFile (const std::string fParam) {
00016     return fParam.find (':') == std::string::npos && std::string (fParam, fParam.length () - 4) == ".txt";
00017   }
00018   
00019   bool xmlFile (const std::string fParam) {
00020     return fParam.find (':') == std::string::npos && std::string (fParam, fParam.length () - 4) == ".xml";
00021   }
00022   
00023   bool dbFile (const std::string fParam) {
00024     return fParam.find (':') != std::string::npos;
00025   }
00026 
00027   template <class T> 
00028   bool getObject (T* fObject, const std::string& fDb, const std::string& fTag, int fRun) {
00029     if (!fObject) return false;
00030     if (fDb.empty ()) return false; 
00031     if (asciiFile (fDb)) {
00032       std::cout << "HcalLedAnalyzer-> USE INPUT: ASCII " << std::endl;
00033       std::ifstream stream (fDb.c_str ());
00034       HcalDbASCIIIO::getObject (stream, fObject); 
00035       return true;
00036     }
00037     else if (dbFile (fDb)) {
00038       std::cout << "HcalLedAnalyzer-> USE INPUT: Pool " << fDb << std::endl;
00039       std::cout << "HcalPedestalAnalyzer-> Pool interface is not supportet since 1.3.0" << fDb << std::endl;
00040       return false;
00041 //       HcalDbTool poolDb (fDb);
00042 //       return poolDb.getObject (fObject, fTag, fRun);
00043     }
00044     else {
00045       std::cerr << "HcalLedAnalyzer-> Unknown input type " << fDb << std::endl;
00046       return false;
00047     }
00048   }
00049   
00050 }
00051 
00052 HcalLedAnalyzer::HcalLedAnalyzer(const edm::ParameterSet& ps){
00053   m_ledAnal = new HcalLedAnalysis(ps);
00054   m_ledAnal->LedSetup(ps.getUntrackedParameter<std::string>("outputFileHist", "HcalLedAnalyzer.root"));
00055 //  m_startSample = ps.getUntrackedParameter<int>("firstSample", 0);
00056 //  m_endSample = ps.getUntrackedParameter<int>("lastSample", 19);
00057   m_inputPedestals_source = ps.getUntrackedParameter<std::string>("inputPedestalsSource", "");
00058   m_inputPedestals_tag = ps.getUntrackedParameter<std::string>("inputPedsTag", "");
00059   m_inputPedestals_run = ps.getUntrackedParameter<int>("inputPedsRun", 1);
00060 
00061   // CORAL required variables to be set, even if not needed
00062   const char* foo1 = "CORAL_AUTH_USER=blah";
00063   const char* foo2 = "CORAL_AUTH_PASSWORD=blah";
00064   if (!::getenv("CORAL_AUTH_USER")) ::putenv(const_cast<char*>(foo1));
00065   if (!::getenv("CORAL_AUTH_PASSWORD")) ::putenv(const_cast<char*>(foo2)); 
00066 }
00067 
00068 HcalLedAnalyzer::~HcalLedAnalyzer(){
00069 //  delete m_ledAnal;
00070 }
00071 
00072 void HcalLedAnalyzer::beginJob(){
00073   m_ievt = 0;
00074   led_sample = 1;
00075   HcalPedestals* inputPeds=0;
00076 // get pedestals
00077   if (!m_inputPedestals_source.empty ()) {
00078     inputPeds = new HcalPedestals ();
00079     if (!getObject (inputPeds, m_inputPedestals_source, m_inputPedestals_tag, m_inputPedestals_run)) {
00080       std::cerr << "HcalLedAnalyzer-> Failed to get pedestal values" << std::endl;
00081     }
00082     //m_ledAnal->doPeds(inputPeds);
00083     delete inputPeds;
00084   }
00085 }
00086 
00087 void HcalLedAnalyzer::endJob(void) {
00088   m_ledAnal->LedDone();
00089   std::cout<<"Getting out"<<std::endl;
00090 }
00091 
00092 void HcalLedAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& eventSetup){
00093 
00094   m_ievt++;
00095 
00097   edm::Handle<HBHEDigiCollection> hbhe; e.getByType(hbhe);
00098   edm::Handle<HODigiCollection> ho;     e.getByType(ho);
00099   edm::Handle<HFDigiCollection> hf;     e.getByType(hf);
00100 
00101   // get calib digis
00102   edm::Handle<HcalCalibDigiCollection> calib;  e.getByType(calib);
00103 
00104   // get testbeam specific laser info from the TDC.  This probably will not work
00105   // outside of the testbeam, but it should be easy to modify the Handle/getByType
00106   // to get the correct stuff 
00107 
00108   //edm::Handle<HcalTBTiming> timing; e.getByType(timing);
00109 
00110   // get conditions
00111   edm::ESHandle<HcalDbService> conditions;
00112   eventSetup.get<HcalDbRecord>().get(conditions);
00113 
00114 //  int runNumber = e.id().run();
00115 //  m_ledAnal->processLedEvent(*hbhe, *ho, *hf, *calib, *conditions, *runNumber);
00116 
00117   m_ledAnal->processLedEvent(*hbhe, *ho, *hf, *calib, *conditions);
00118 
00119 
00120   if(m_ievt%1000 == 0)
00121     std::cout << "HcalLedAnalyzer: analyzed " << m_ievt << " events" << std::endl;
00122 
00123   return;
00124 }
00125