CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/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.1 2011/05/09 19:38:47 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/CastorObjects/interface/AllObjects.h"
00047 
00048 #include "CalibCalorimetry/CastorCalib/interface/CastorDbASCIIIO.h"
00049 //
00050 // class decleration
00051 //
00052 
00053 class CastorDumpConditions : public edm::EDAnalyzer {
00054    public:
00055       explicit CastorDumpConditions(const edm::ParameterSet&);
00056       ~CastorDumpConditions();
00057 
00058        template<class S, class SRcd> void dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name);
00059 
00060    private:
00061       std::string file_prefix;
00062       std::vector<std::string> mDumpRequest;
00063       virtual void beginJob(const edm::EventSetup&) ;
00064       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00065       virtual void endJob() ;
00066 
00067       // ----------member data ---------------------------
00068 };
00069 
00070 //
00071 // constants, enums and typedefs
00072 //
00073 
00074 //
00075 // static data member definitions
00076 //
00077 
00078 //
00079 // constructors and destructor
00080 //
00081 CastorDumpConditions::CastorDumpConditions(const edm::ParameterSet& iConfig)
00082 
00083 {
00084    file_prefix = iConfig.getUntrackedParameter<std::string>("outFilePrefix","Dump");
00085    mDumpRequest= iConfig.getUntrackedParameter<std::vector<std::string> >("dump",std::vector<std::string>());
00086    if (mDumpRequest.empty()) {
00087       std::cout << "CastorDumpConditions: No record to dump. Exiting." << std::endl;
00088       exit(0);
00089    }
00090 
00091 }
00092 
00093 
00094 CastorDumpConditions::~CastorDumpConditions()
00095 {
00096  
00097    // do anything here that needs to be done at desctruction time
00098    // (e.g. close files, deallocate resources etc.)
00099 
00100 }
00101 
00102 
00103 //
00104 // member functions
00105 //
00106 
00107 // ------------ method called to for each event  ------------
00108 void
00109 CastorDumpConditions::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00110 {
00111    using namespace edm;
00112 
00113 #ifdef THIS_IS_AN_EVENT_EXAMPLE
00114    Handle<ExampleData> pIn;
00115    iEvent.getByLabel("example",pIn);
00116 #endif
00117    
00118 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
00119    ESHandle<SetupData> pSetup;
00120    iSetup.get<SetupRecord>().get(pSetup);
00121 #endif
00122    std::cout << "I AM IN THE RUN " << iEvent.id().run() << std::endl;
00123    std::cout << "What to dump? "<< std::endl;
00124    if (mDumpRequest.empty()) {
00125       std::cout<< "CastorDumpConditions: Empty request" << std::endl;
00126       return;
00127    }
00128 
00129    for(std::vector<std::string>::const_iterator it=mDumpRequest.begin();it!=mDumpRequest.end();it++)
00130       std::cout << *it << std::endl;
00131 
00132     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ElectronicsMap")) != mDumpRequest.end())
00133       dumpIt(new CastorElectronicsMap(), new CastorElectronicsMapRcd(), iEvent,iSetup,"ElectronicsMap");
00134 
00135     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("QIEData")) != mDumpRequest.end())
00136       dumpIt(new CastorQIEData(), new CastorQIEDataRcd(), iEvent,iSetup,"QIEData"); 
00137 
00138     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Pedestals")) != mDumpRequest.end()) 
00139       dumpIt(new CastorPedestals(), new CastorPedestalsRcd(), iEvent,iSetup,"Pedestals");
00140 
00141     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PedestalWidths")) != mDumpRequest.end())
00142       dumpIt(new CastorPedestalWidths(), new CastorPedestalWidthsRcd(), iEvent,iSetup,"PedestalWidths");
00143 
00144     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Gains")) != mDumpRequest.end())
00145       dumpIt(new CastorGains(), new CastorGainsRcd(), iEvent,iSetup,"Gains");
00146 
00147     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("GainWidths")) != mDumpRequest.end())
00148       dumpIt(new CastorGainWidths(), new CastorGainWidthsRcd(), iEvent,iSetup,"GainWidths");
00149 
00150     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ChannelQuality")) != mDumpRequest.end())
00151       dumpIt(new CastorChannelQuality(), new CastorChannelQualityRcd(), iEvent,iSetup,"ChannelQuality");
00152 
00153     if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("RecoParams")) != mDumpRequest.end())
00154       dumpIt(new CastorRecoParams(), new CastorRecoParamsRcd(), iEvent,iSetup,"RecoParams");
00155 
00156 /*
00157    ESHandle<CastorPedestals> p;
00158    iSetup.get<CastorPedestalsRcd>().get(p);
00159    CastorPedestals* mypeds = new CastorPedestals(*p.product());
00160    std::ostringstream file;
00161    std::string name = "CastorPedestal";
00162    file << file_prefix << name.c_str() << "_Run" << iEvent.id().run()<< ".txt";
00163    std::ofstream outStream(file.str().c_str() );
00164    std::cout << "CastorDumpConditions: ---- Dumping " << name.c_str() << " ----" << std::endl;
00165    CastorDbASCIIIO::dumpObject (outStream, (*mypeds) );
00166 
00167 */   
00168 }
00169 
00170 
00171 // ------------ method called once each job just before starting event loop  ------------
00172 void 
00173 CastorDumpConditions::beginJob(const edm::EventSetup&)
00174 {
00175 }
00176 
00177 // ------------ method called once each job just after ending the event loop  ------------
00178 void 
00179 CastorDumpConditions::endJob() {
00180 }
00181 
00182 template<class S, class SRcd>
00183   void CastorDumpConditions::dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name) {
00184     int myrun = e.id().run();
00185     edm::ESHandle<S> p;
00186     context.get<SRcd>().get(p);
00187     S* myobject = new S(*p.product());
00188 
00189     std::ostringstream file;
00190     file << file_prefix << name.c_str() << "_Run" << myrun << ".txt";
00191     std::ofstream outStream(file.str().c_str() );
00192     CastorDbASCIIIO::dumpObject (outStream, (*myobject) );
00193   }
00194 
00195 //define this as a plug-in
00196 DEFINE_FWK_MODULE(CastorDumpConditions);