CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/CondTools/Hcal/plugins/CastorDumpConditions.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    Castor
00004 // Class:      CastorDumpConditions
00005 // 
00013 //
00014 // Original Author:  Luiz Mundim Filho
00015 //         Created:  Thu Mar 12 14:45:44 CET 2009
00016 // $Id: CastorDumpConditions.cc,v 1.2 2012/11/14 13:55:13 mundim Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <iostream>
00024 #include <fstream>
00025 #include <sstream>
00026 #include <string>
00027 
00028 // user include files
00029 #include "FWCore/Framework/interface/Frameworkfwd.h"
00030 #include "FWCore/Framework/interface/EDAnalyzer.h"
00031 #include "FWCore/Framework/interface/ESHandle.h"
00032 
00033 #include "FWCore/Framework/interface/Event.h"
00034 #include "FWCore/Framework/interface/EventSetup.h"
00035 #include "FWCore/Framework/interface/MakerMacros.h"
00036 
00037 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00038 #include "CondFormats/DataRecord/interface/CastorPedestalsRcd.h"
00039 #include "CondFormats/DataRecord/interface/CastorPedestalWidthsRcd.h"
00040 #include "CondFormats/DataRecord/interface/CastorGainsRcd.h"
00041 #include "CondFormats/DataRecord/interface/CastorGainWidthsRcd.h"
00042 #include "CondFormats/DataRecord/interface/CastorQIEDataRcd.h"
00043 #include "CondFormats/DataRecord/interface/CastorChannelQualityRcd.h"
00044 #include "CondFormats/DataRecord/interface/CastorElectronicsMapRcd.h"
00045 #include "CondFormats/DataRecord/interface/CastorRecoParamsRcd.h"
00046 #include "CondFormats/DataRecord/interface/CastorSaturationCorrsRcd.h"
00047 #include "CondFormats/CastorObjects/interface/AllObjects.h"
00048 
00049 #include "CalibCalorimetry/CastorCalib/interface/CastorDbASCIIIO.h"
00050 //
00051 // class decleration
00052 //
00053 
00054 class CastorDumpConditions : public edm::EDAnalyzer {
00055    public:
00056       explicit CastorDumpConditions(const edm::ParameterSet&);
00057       ~CastorDumpConditions();
00058 
00059        template<class S, class SRcd> void dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name);
00060 
00061    private:
00062       std::string file_prefix;
00063       std::vector<std::string> mDumpRequest;
00064       virtual void beginJob(const edm::EventSetup&) ;
00065       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00066       virtual void endJob() ;
00067 
00068       // ----------member data ---------------------------
00069 };
00070 
00071 //
00072 // constants, enums and typedefs
00073 //
00074 
00075 //
00076 // static data member definitions
00077 //
00078 
00079 //
00080 // constructors and destructor
00081 //
00082 CastorDumpConditions::CastorDumpConditions(const edm::ParameterSet& iConfig)
00083 
00084 {
00085    file_prefix = iConfig.getUntrackedParameter<std::string>("outFilePrefix","Dump");
00086    mDumpRequest= iConfig.getUntrackedParameter<std::vector<std::string> >("dump",std::vector<std::string>());
00087    if (mDumpRequest.empty()) {
00088       std::cout << "CastorDumpConditions: No record to dump. Exiting." << std::endl;
00089       exit(0);
00090    }
00091 
00092 }
00093 
00094 
00095 CastorDumpConditions::~CastorDumpConditions()
00096 {
00097  
00098    // do anything here that needs to be done at desctruction time
00099    // (e.g. close files, deallocate resources etc.)
00100 
00101 }
00102 
00103 
00104 //
00105 // member functions
00106 //
00107 
00108 // ------------ method called to for each event  ------------
00109 void
00110 CastorDumpConditions::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00111 {
00112    using namespace edm;
00113 
00114 #ifdef THIS_IS_AN_EVENT_EXAMPLE
00115    Handle<ExampleData> pIn;
00116    iEvent.getByLabel("example",pIn);
00117 #endif
00118    
00119 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
00120    ESHandle<SetupData> pSetup;
00121    iSetup.get<SetupRecord>().get(pSetup);
00122 #endif
00123    std::cout << "I AM IN THE RUN " << iEvent.id().run() << std::endl;
00124    std::cout << "What to dump? "<< std::endl;
00125    if (mDumpRequest.empty()) {
00126       std::cout<< "CastorDumpConditions: Empty request" << std::endl;
00127       return;
00128    }
00129 
00130    for(std::vector<std::string>::const_iterator it=mDumpRequest.begin();it!=mDumpRequest.end();it++)
00131       std::cout << *it << std::endl;
00132 
00133     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ElectronicsMap")) != mDumpRequest.end())
00134       dumpIt(new CastorElectronicsMap(), new CastorElectronicsMapRcd(), iEvent,iSetup,"ElectronicsMap");
00135 
00136     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("QIEData")) != mDumpRequest.end())
00137       dumpIt(new CastorQIEData(), new CastorQIEDataRcd(), iEvent,iSetup,"QIEData"); 
00138 
00139     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Pedestals")) != mDumpRequest.end()) 
00140       dumpIt(new CastorPedestals(), new CastorPedestalsRcd(), iEvent,iSetup,"Pedestals");
00141 
00142     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PedestalWidths")) != mDumpRequest.end())
00143       dumpIt(new CastorPedestalWidths(), new CastorPedestalWidthsRcd(), iEvent,iSetup,"PedestalWidths");
00144 
00145     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Gains")) != mDumpRequest.end())
00146       dumpIt(new CastorGains(), new CastorGainsRcd(), iEvent,iSetup,"Gains");
00147 
00148     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("GainWidths")) != mDumpRequest.end())
00149       dumpIt(new CastorGainWidths(), new CastorGainWidthsRcd(), iEvent,iSetup,"GainWidths");
00150 
00151     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ChannelQuality")) != mDumpRequest.end())
00152       dumpIt(new CastorChannelQuality(), new CastorChannelQualityRcd(), iEvent,iSetup,"ChannelQuality");
00153 
00154     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("RecoParams")) != mDumpRequest.end())
00155       dumpIt(new CastorRecoParams(), new CastorRecoParamsRcd(), iEvent,iSetup,"RecoParams");
00156       
00157     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("SaturationCorrs")) != mDumpRequest.end())
00158       dumpIt(new CastorSaturationCorrs(), new CastorSaturationCorrsRcd(), iEvent,iSetup,"SaturationCorrs");
00159 
00160 /*
00161    ESHandle<CastorPedestals> p;
00162    iSetup.get<CastorPedestalsRcd>().get(p);
00163    CastorPedestals* mypeds = new CastorPedestals(*p.product());
00164    std::ostringstream file;
00165    std::string name = "CastorPedestal";
00166    file << file_prefix << name.c_str() << "_Run" << iEvent.id().run()<< ".txt";
00167    std::ofstream outStream(file.str().c_str() );
00168    std::cout << "CastorDumpConditions: ---- Dumping " << name.c_str() << " ----" << std::endl;
00169    CastorDbASCIIIO::dumpObject (outStream, (*mypeds) );
00170 
00171 */   
00172 }
00173 
00174 
00175 // ------------ method called once each job just before starting event loop  ------------
00176 void 
00177 CastorDumpConditions::beginJob(const edm::EventSetup&)
00178 {
00179 }
00180 
00181 // ------------ method called once each job just after ending the event loop  ------------
00182 void 
00183 CastorDumpConditions::endJob() {
00184 }
00185 
00186 template<class S, class SRcd>
00187   void CastorDumpConditions::dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name) {
00188     int myrun = e.id().run();
00189     edm::ESHandle<S> p;
00190     context.get<SRcd>().get(p);
00191     S* myobject = new S(*p.product());
00192 
00193     std::ostringstream file;
00194     file << file_prefix << name.c_str() << "_Run" << myrun << ".txt";
00195     std::ofstream outStream(file.str().c_str() );
00196     CastorDbASCIIIO::dumpObject (outStream, (*myobject) );
00197   }
00198 
00199 //define this as a plug-in
00200 DEFINE_FWK_MODULE(CastorDumpConditions);