CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/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   hbheDigiCollectionTag_(ps.getParameter<edm::InputTag>("hbheDigiCollectionTag")),
00054   hoDigiCollectionTag_(ps.getParameter<edm::InputTag>("hoDigiCollectionTag")),
00055   hfDigiCollectionTag_(ps.getParameter<edm::InputTag>("hfDigiCollectionTag")),
00056   hcalCalibDigiCollectionTag_ (ps.getParameter<edm::InputTag>("hcalCalibDigiCollectionTag")) {
00057 
00058   m_ledAnal = new HcalLedAnalysis(ps);
00059   m_ledAnal->LedSetup(ps.getUntrackedParameter<std::string>("outputFileHist", "HcalLedAnalyzer.root"));
00060 //  m_startSample = ps.getUntrackedParameter<int>("firstSample", 0);
00061 //  m_endSample = ps.getUntrackedParameter<int>("lastSample", 19);
00062   m_inputPedestals_source = ps.getUntrackedParameter<std::string>("inputPedestalsSource", "");
00063   m_inputPedestals_tag = ps.getUntrackedParameter<std::string>("inputPedsTag", "");
00064   m_inputPedestals_run = ps.getUntrackedParameter<int>("inputPedsRun", 1);
00065 
00066   // CORAL required variables to be set, even if not needed
00067   const char* foo1 = "CORAL_AUTH_USER=blah";
00068   const char* foo2 = "CORAL_AUTH_PASSWORD=blah";
00069   if (!::getenv("CORAL_AUTH_USER")) ::putenv(const_cast<char*>(foo1));
00070   if (!::getenv("CORAL_AUTH_PASSWORD")) ::putenv(const_cast<char*>(foo2)); 
00071 }
00072 
00073 HcalLedAnalyzer::~HcalLedAnalyzer(){
00074 //  delete m_ledAnal;
00075 }
00076 
00077 void HcalLedAnalyzer::beginJob(){
00078   m_ievt = 0;
00079   led_sample = 1;
00080 }
00081 
00082 void HcalLedAnalyzer::endJob(void) {
00083   m_ledAnal->LedDone();
00084   std::cout<<"Getting out"<<std::endl;
00085 }
00086 
00087 void HcalLedAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& eventSetup){
00088 
00089   m_ievt++;
00090 
00092   edm::Handle<HBHEDigiCollection> hbhe; e.getByLabel(hbheDigiCollectionTag_, hbhe);
00093   edm::Handle<HODigiCollection> ho;     e.getByLabel(hoDigiCollectionTag_, ho);
00094   edm::Handle<HFDigiCollection> hf;     e.getByLabel(hfDigiCollectionTag_, hf);
00095 
00096   // get calib digis
00097   edm::Handle<HcalCalibDigiCollection> calib;  e.getByLabel(hcalCalibDigiCollectionTag_, calib);
00098 
00099   // get testbeam specific laser info from the TDC.  This probably will not work
00100   // outside of the testbeam, but it should be easy to modify the Handle/getByType
00101   // to get the correct stuff 
00102 
00103   //edm::Handle<HcalTBTiming> timing; e.getByType(timing);
00104 
00105   // get conditions
00106   edm::ESHandle<HcalDbService> conditions;
00107   eventSetup.get<HcalDbRecord>().get(conditions);
00108 
00109 //  int runNumber = e.id().run();
00110 //  m_ledAnal->processLedEvent(*hbhe, *ho, *hf, *calib, *conditions, *runNumber);
00111 
00112   m_ledAnal->processLedEvent(*hbhe, *ho, *hf, *calib, *conditions);
00113 
00114 
00115   if(m_ievt%1000 == 0)
00116     std::cout << "HcalLedAnalyzer: analyzed " << m_ievt << " events" << std::endl;
00117 
00118   return;
00119 }
00120