CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/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 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00035 
00036 #include "FWCore/Framework/interface/IOVSyncValue.h"
00037 #include "CondFormats/HcalObjects/interface/AllObjects.h"
00038 
00039 namespace edmtest
00040 {
00041   class HcalDumpConditions : public edm::EDAnalyzer
00042   {
00043   public:
00044     explicit  HcalDumpConditions(edm::ParameterSet const& p) 
00045     {
00046       front = p.getUntrackedParameter<std::string>("outFilePrefix","Dump");
00047       mDumpRequest = p.getUntrackedParameter <std::vector <std::string> > ("dump", std::vector<std::string>());
00048     }
00049 
00050     explicit  HcalDumpConditions(int i) 
00051     { }
00052     virtual ~ HcalDumpConditions() { }
00053     virtual void analyze(const edm::Event& e, const edm::EventSetup& c);
00054 
00055     template<class S, class SRcd> void dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name);
00056 
00057   private:
00058     std::string front;
00059     std::vector<std::string> mDumpRequest;
00060   };
00061   
00062 
00063   template<class S, class SRcd>
00064   void HcalDumpConditions::dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name)
00065   {
00066     int myrun = e.id().run();
00067     edm::ESHandle<S> p;
00068     context.get<SRcd>().get(p);
00069     S* myobject = new S(*p.product());
00070     
00071     std::ostringstream file;
00072     file << front << name.c_str() << "_Run" << myrun << ".txt";
00073     std::ofstream outStream(file.str().c_str() );
00074     std::cout << "HcalDumpConditions: ---- Dumping " << name.c_str() << " ----" << std::endl;
00075     HcalDbASCIIIO::dumpObject (outStream, (*myobject) );
00076 
00077     if ( context.get<SRcd>().validityInterval().first() == edm::IOVSyncValue::invalidIOVSyncValue() )
00078       std::cout << "error: invalid IOV sync value !" << std::endl;
00079 
00080   }
00081 
00082 
00083   void
00084    HcalDumpConditions::analyze(const edm::Event& e, const edm::EventSetup& context)
00085   {
00086     edm::ESHandle<HcalTopology> topology ;
00087     context.get<IdealGeometryRecord>().get( topology );
00088 
00089     using namespace edm::eventsetup;
00090     std::cout <<"HcalDumpConditions::analyze-> I AM IN RUN NUMBER "<<e.id().run() <<std::endl;
00091 
00092     if (mDumpRequest.empty()) return;
00093     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ElectronicsMap")) != mDumpRequest.end())
00094       dumpIt(new HcalElectronicsMap, new HcalElectronicsMapRcd, e,context,"ElectronicsMap");
00095     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("QIEData")) != mDumpRequest.end())
00096       dumpIt(new HcalQIEData(&(*topology)), new HcalQIEDataRcd, e,context,"QIEData");
00097     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Pedestals")) != mDumpRequest.end())
00098       dumpIt(new HcalPedestals(&(*topology)), new HcalPedestalsRcd, e,context,"Pedestals");
00099     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PedestalWidths")) != mDumpRequest.end())
00100       dumpIt(new HcalPedestalWidths(&(*topology)), new HcalPedestalWidthsRcd, e,context,"PedestalWidths");
00101     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Gains")) != mDumpRequest.end())
00102       dumpIt(new HcalGains(&(*topology)), new HcalGainsRcd, e,context,"Gains");
00103     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("GainWidths")) != mDumpRequest.end())
00104       dumpIt(new HcalGainWidths(&(*topology)), new HcalGainWidthsRcd, e,context,"GainWidths");
00105     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ChannelQuality")) != mDumpRequest.end())
00106       dumpIt(new HcalChannelQuality(&(*topology)), new HcalChannelQualityRcd, e,context,"ChannelQuality");
00107     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("RespCorrs")) != mDumpRequest.end())
00108       dumpIt(new HcalRespCorrs(&(*topology)), new HcalRespCorrsRcd, e,context,"RespCorrs");
00109     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ZSThresholds")) != mDumpRequest.end())
00110       dumpIt(new HcalZSThresholds(&(*topology)), new HcalZSThresholdsRcd, e,context,"ZSThresholds");
00111     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("L1TriggerObjects")) != mDumpRequest.end())
00112       dumpIt(new HcalL1TriggerObjects(&(*topology)), new HcalL1TriggerObjectsRcd, e,context,"L1TriggerObjects");
00113     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("TimeCorrs")) != mDumpRequest.end())
00114       dumpIt(new HcalTimeCorrs(&(*topology)), new HcalTimeCorrsRcd, e,context,"TimeCorrs");
00115     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("LUTCorrs")) != mDumpRequest.end())
00116       dumpIt(new HcalLUTCorrs(&(*topology)), new HcalLUTCorrsRcd, e,context,"LUTCorrs");
00117     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PFCorrs")) != mDumpRequest.end())
00118       dumpIt(new HcalPFCorrs(&(*topology)), new HcalPFCorrsRcd, e,context,"PFCorrs");
00119     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ValidationCorrs")) != mDumpRequest.end())
00120       dumpIt(new HcalValidationCorrs(&(*topology)), new HcalValidationCorrsRcd, e,context,"ValidationCorrs");
00121     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("LutMetadata")) != mDumpRequest.end())
00122       dumpIt(new HcalLutMetadata(&(*topology)), new HcalLutMetadataRcd, e,context,"LutMetadata");
00123     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("DcsValues")) != mDumpRequest.end())
00124       dumpIt(new HcalDcsValues, new HcalDcsRcd, e,context,"DcsValues");
00125     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("DcsMap")) != mDumpRequest.end())
00126       dumpIt(new HcalDcsMap, new HcalDcsMapRcd, e,context,"DcsMap");
00127     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("CholeskyMatrices")) != mDumpRequest.end())
00128       dumpIt(new HcalCholeskyMatrices(&(*topology)), new HcalCholeskyMatricesRcd, e,context,"CholeskyMatrices");
00129     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("RecoParams")) != mDumpRequest.end())
00130       dumpIt(new HcalRecoParams(&(*topology)), new HcalRecoParamsRcd, e,context,"RecoParams");
00131     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("TimingParams")) != mDumpRequest.end())
00132       dumpIt(new HcalTimingParams(&(*topology)), new HcalTimingParamsRcd, e,context,"TimingParams");
00133     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("LongRecoParams")) != mDumpRequest.end())
00134       dumpIt(new HcalLongRecoParams(&(*topology)), new HcalLongRecoParamsRcd, e,context,"LongRecoParams");
00135     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("MCParams")) != mDumpRequest.end())
00136       dumpIt(new HcalMCParams(&(*topology)), new HcalMCParamsRcd, e,context,"MCParams");
00137     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("FlagHFDigiTimeParams")) != mDumpRequest.end())
00138       dumpIt(new HcalFlagHFDigiTimeParams(&(*topology)), new HcalFlagHFDigiTimeParamsRcd, e,context,"FlagHFDigiTimeParams");
00139 
00140     
00141   }
00142   DEFINE_FWK_MODULE(HcalDumpConditions);
00143 }