CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/CondTools/Hcal/plugins/HcalDumpConditions.cc

Go to the documentation of this file.
00001 
00002 /*----------------------------------------------------------------------
00003 
00004 R.Ofierzynski - 2.Oct. 2007
00005    modified to dump all pedestals on screen, see 
00006    testHcalDBFake.cfg
00007    testHcalDBFrontier.cfg
00008 
00009 July 29, 2009       Added HcalValidationCorrs - Gena Kukartsev
00010 September 21, 2009  Added HcalLutMetadata - Gena Kukartsev
00011    
00012 ----------------------------------------------------------------------*/
00013 
00014 #include <stdexcept>
00015 #include <string>
00016 #include <iostream>
00017 #include <fstream>
00018 #include <sstream>
00019 #include <map>
00020 #include "FWCore/Framework/interface/EDAnalyzer.h"
00021 #include "FWCore/Framework/interface/Event.h"
00022 #include "FWCore/Framework/interface/ESHandle.h"
00023 #include "FWCore/Framework/interface/MakerMacros.h"
00024 
00025 #include "FWCore/Framework/interface/EventSetup.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 
00028 #include "CondFormats/DataRecord/interface/HcalAllRcds.h"
00029 
00030 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
00031 
00032 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00033 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00034 
00035 #include "FWCore/Framework/interface/IOVSyncValue.h"
00036 #include "CondFormats/HcalObjects/interface/AllObjects.h"
00037 
00038 namespace edmtest
00039 {
00040   class HcalDumpConditions : public edm::EDAnalyzer
00041   {
00042   public:
00043     explicit  HcalDumpConditions(edm::ParameterSet const& p) 
00044     {
00045       front = p.getUntrackedParameter<std::string>("outFilePrefix","Dump");
00046       mDumpRequest = p.getUntrackedParameter <std::vector <std::string> > ("dump", std::vector<std::string>());
00047     }
00048 
00049     explicit  HcalDumpConditions(int i) 
00050     { }
00051     virtual ~ HcalDumpConditions() { }
00052     virtual void analyze(const edm::Event& e, const edm::EventSetup& c);
00053 
00054     template<class S, class SRcd> void dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name);
00055 
00056   private:
00057     std::string front;
00058     std::vector<std::string> mDumpRequest;
00059   };
00060   
00061 
00062   template<class S, class SRcd>
00063   void HcalDumpConditions::dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name)
00064   {
00065     int myrun = e.id().run();
00066     edm::ESHandle<S> p;
00067     context.get<SRcd>().get(p);
00068     S* myobject = new S(*p.product());
00069     
00070     std::ostringstream file;
00071     file << front << name.c_str() << "_Run" << myrun << ".txt";
00072     std::ofstream outStream(file.str().c_str() );
00073     std::cout << "HcalDumpConditions: ---- Dumping " << name.c_str() << " ----" << std::endl;
00074     HcalDbASCIIIO::dumpObject (outStream, (*myobject) );
00075 
00076     if ( context.get<SRcd>().validityInterval().first() == edm::IOVSyncValue::invalidIOVSyncValue() )
00077       std::cout << "error: invalid IOV sync value !" << std::endl;
00078 
00079   }
00080 
00081 
00082   void
00083    HcalDumpConditions::analyze(const edm::Event& e, const edm::EventSetup& context)
00084   {
00085     using namespace edm::eventsetup;
00086     std::cout <<"HcalDumpConditions::analyze-> I AM IN RUN NUMBER "<<e.id().run() <<std::endl;
00087 
00088     if (mDumpRequest.empty()) return;
00089     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ElectronicsMap")) != mDumpRequest.end())
00090       dumpIt(new HcalElectronicsMap, new HcalElectronicsMapRcd, e,context,"ElectronicsMap");
00091     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("QIEData")) != mDumpRequest.end())
00092       dumpIt(new HcalQIEData, new HcalQIEDataRcd, e,context,"QIEData");
00093     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Pedestals")) != mDumpRequest.end())
00094       dumpIt(new HcalPedestals(false), new HcalPedestalsRcd, e,context,"Pedestals");
00095     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PedestalWidths")) != mDumpRequest.end())
00096       dumpIt(new HcalPedestalWidths(false), new HcalPedestalWidthsRcd, e,context,"PedestalWidths");
00097     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Gains")) != mDumpRequest.end())
00098       dumpIt(new HcalGains, new HcalGainsRcd, e,context,"Gains");
00099     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("GainWidths")) != mDumpRequest.end())
00100       dumpIt(new HcalGainWidths, new HcalGainWidthsRcd, e,context,"GainWidths");
00101     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ChannelQuality")) != mDumpRequest.end())
00102       dumpIt(new HcalChannelQuality, new HcalChannelQualityRcd, e,context,"ChannelQuality");
00103     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("RespCorrs")) != mDumpRequest.end())
00104       dumpIt(new HcalRespCorrs, new HcalRespCorrsRcd, e,context,"RespCorrs");
00105     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ZSThresholds")) != mDumpRequest.end())
00106       dumpIt(new HcalZSThresholds, new HcalZSThresholdsRcd, e,context,"ZSThresholds");
00107     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("L1TriggerObjects")) != mDumpRequest.end())
00108       dumpIt(new HcalL1TriggerObjects, new HcalL1TriggerObjectsRcd, e,context,"L1TriggerObjects");
00109     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("TimeCorrs")) != mDumpRequest.end())
00110       dumpIt(new HcalTimeCorrs, new HcalTimeCorrsRcd, e,context,"TimeCorrs");
00111     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("LUTCorrs")) != mDumpRequest.end())
00112       dumpIt(new HcalLUTCorrs, new HcalLUTCorrsRcd, e,context,"LUTCorrs");
00113     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PFCorrs")) != mDumpRequest.end())
00114       dumpIt(new HcalPFCorrs, new HcalPFCorrsRcd, e,context,"PFCorrs");
00115     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ValidationCorrs")) != mDumpRequest.end())
00116       dumpIt(new HcalValidationCorrs, new HcalValidationCorrsRcd, e,context,"ValidationCorrs");
00117     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("LutMetadata")) != mDumpRequest.end())
00118       dumpIt(new HcalLutMetadata, new HcalLutMetadataRcd, e,context,"LutMetadata");
00119     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("DcsValues")) != mDumpRequest.end())
00120       dumpIt(new HcalDcsValues, new HcalDcsRcd, e,context,"DcsValues");
00121     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("DcsMap")) != mDumpRequest.end())
00122       dumpIt(new HcalDcsMap, new HcalDcsMapRcd, e,context,"DcsMap");
00123     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("CholeskyMatrices")) != mDumpRequest.end())
00124       dumpIt(new HcalCholeskyMatrices, new HcalCholeskyMatricesRcd, e,context,"CholeskyMatrices");
00125     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("RecoParams")) != mDumpRequest.end())
00126       dumpIt(new HcalRecoParams, new HcalRecoParamsRcd, e,context,"RecoParams");
00127     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("TimingParams")) != mDumpRequest.end())
00128       dumpIt(new HcalTimingParams, new HcalTimingParamsRcd, e,context,"TimingParams");
00129     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("LongRecoParams")) != mDumpRequest.end())
00130       dumpIt(new HcalLongRecoParams, new HcalLongRecoParamsRcd, e,context,"LongRecoParams");
00131     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("MCParams")) != mDumpRequest.end())
00132       dumpIt(new HcalMCParams, new HcalMCParamsRcd, e,context,"MCParams");
00133     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("FlagHFDigiTimeParams")) != mDumpRequest.end())
00134       dumpIt(new HcalFlagHFDigiTimeParams, new HcalFlagHFDigiTimeParamsRcd, e,context,"FlagHFDigiTimeParams");
00135 
00136     
00137   }
00138   DEFINE_FWK_MODULE(HcalDumpConditions);
00139 }