Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:11

0001 // -*- C++ -*-
0002 //
0003 // Package:    Castor
0004 // Class:      CastorDumpConditions
0005 //
0006 /**\class Castor CastorDumpConditions.cc CondTools/Castor/src/CastorDumpConditions.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Luiz Mundim Filho
0015 //         Created:  Thu Mar 12 14:45:44 CET 2009
0016 // $Id: CastorDumpConditions.cc,v 1.1 2011/05/09 19:38:47 mundim Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 #include <iostream>
0023 #include <fstream>
0024 #include <sstream>
0025 #include <string>
0026 
0027 // user include files
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0030 
0031 #include "FWCore/Framework/interface/Event.h"
0032 #include "FWCore/Framework/interface/EventSetup.h"
0033 #include "FWCore/Framework/interface/MakerMacros.h"
0034 
0035 #include "FWCore/Utilities/interface/Exception.h"
0036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0037 
0038 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0039 #include "CondFormats/DataRecord/interface/CastorPedestalsRcd.h"
0040 #include "CondFormats/DataRecord/interface/CastorPedestalWidthsRcd.h"
0041 #include "CondFormats/DataRecord/interface/CastorGainsRcd.h"
0042 #include "CondFormats/DataRecord/interface/CastorGainWidthsRcd.h"
0043 #include "CondFormats/DataRecord/interface/CastorQIEDataRcd.h"
0044 #include "CondFormats/DataRecord/interface/CastorChannelQualityRcd.h"
0045 #include "CondFormats/DataRecord/interface/CastorElectronicsMapRcd.h"
0046 #include "CondFormats/DataRecord/interface/CastorRecoParamsRcd.h"
0047 #include "CondFormats/DataRecord/interface/CastorSaturationCorrsRcd.h"
0048 #include "CondFormats/CastorObjects/interface/AllObjects.h"
0049 
0050 #include "CalibCalorimetry/CastorCalib/interface/CastorDbASCIIIO.h"
0051 //
0052 // class decleration
0053 //
0054 
0055 class CastorDumpConditions : public edm::one::EDAnalyzer<> {
0056 public:
0057   explicit CastorDumpConditions(const edm::ParameterSet&);
0058 
0059   template <class S, class SRcd>
0060   void dumpIt(const std::vector<std::string>& mDumpRequest,
0061               const edm::Event& e,
0062               const edm::EventSetup& context,
0063               const std::string name);
0064 
0065 private:
0066   std::string file_prefix;
0067   std::vector<std::string> mDumpRequest;
0068   void analyze(const edm::Event&, const edm::EventSetup&) override;
0069 
0070   // ----------member data ---------------------------
0071 };
0072 
0073 //
0074 // constants, enums and typedefs
0075 //
0076 
0077 //
0078 // static data member definitions
0079 //
0080 
0081 //
0082 // constructors and destructor
0083 //
0084 CastorDumpConditions::CastorDumpConditions(const edm::ParameterSet& iConfig)
0085 
0086 {
0087   file_prefix = iConfig.getUntrackedParameter<std::string>("outFilePrefix", "Dump");
0088   mDumpRequest = iConfig.getUntrackedParameter<std::vector<std::string> >("dump", std::vector<std::string>());
0089   if (mDumpRequest.empty()) {
0090     throw cms::Exception("Bad Config") << "CastorDumpConditions: No record to dump.";
0091   }
0092 }
0093 
0094 //
0095 // member functions
0096 //
0097 
0098 // ------------ method called to for each event  ------------
0099 void CastorDumpConditions::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0100   using namespace edm;
0101 
0102   {
0103     edm::LogAbsolute log("CastorDumpConditions");
0104     log << "I AM IN THE RUN " << iEvent.id().run() << "\n";
0105     log << "What to dump? " << std::endl;
0106     if (mDumpRequest.empty()) {
0107       log << "CastorDumpConditions: Empty request \n";
0108       return;
0109     }
0110   }
0111 
0112   for (std::vector<std::string>::const_iterator it = mDumpRequest.begin(); it != mDumpRequest.end(); it++)
0113     LogAbsolute("CastorDumpConditions") << *it << "\n";
0114 
0115   // dumpIt called for all possible ValueMaps. The function checks if the dump is actually requested.
0116   dumpIt<CastorElectronicsMap, CastorElectronicsMapRcd>(mDumpRequest, iEvent, iSetup, "ElectronicsMap");
0117   dumpIt<CastorQIEData, CastorQIEDataRcd>(mDumpRequest, iEvent, iSetup, "QIEData");
0118   dumpIt<CastorPedestals, CastorPedestalsRcd>(mDumpRequest, iEvent, iSetup, "Pedestals");
0119   dumpIt<CastorPedestalWidths, CastorPedestalWidthsRcd>(mDumpRequest, iEvent, iSetup, "PedestalWidths");
0120   dumpIt<CastorGains, CastorGainsRcd>(mDumpRequest, iEvent, iSetup, "Gains");
0121   dumpIt<CastorGainWidths, CastorGainWidthsRcd>(mDumpRequest, iEvent, iSetup, "GainWidths");
0122   dumpIt<CastorChannelQuality, CastorChannelQualityRcd>(mDumpRequest, iEvent, iSetup, "ChannelQuality");
0123   dumpIt<CastorRecoParams, CastorRecoParamsRcd>(mDumpRequest, iEvent, iSetup, "RecoParams");
0124   dumpIt<CastorSaturationCorrs, CastorSaturationCorrsRcd>(mDumpRequest, iEvent, iSetup, "SaturationCorrs");
0125 }
0126 
0127 template <class S, class SRcd>
0128 void CastorDumpConditions::dumpIt(const std::vector<std::string>& mDumpRequest,
0129                                   const edm::Event& e,
0130                                   const edm::EventSetup& context,
0131                                   const std::string name) {
0132   if (std::find(mDumpRequest.begin(), mDumpRequest.end(), name) != mDumpRequest.end()) {
0133     int myrun = e.id().run();
0134     edm::ESGetToken<S, SRcd> tok = esConsumes<S, SRcd>();
0135     const S& myobject = context.getData(tok);
0136 
0137     std::ostringstream file;
0138     file << file_prefix << name.c_str() << "_Run" << myrun << ".txt";
0139     std::ofstream outStream(file.str().c_str());
0140     CastorDbASCIIIO::dumpObject(outStream, myobject);
0141   }
0142 }
0143 
0144 //define this as a plug-in
0145 DEFINE_FWK_MODULE(CastorDumpConditions);