CMS 3D CMS Logo

CastorDumpConditions.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Castor
4 // Class: CastorDumpConditions
5 //
13 //
14 // Original Author: Luiz Mundim Filho
15 // Created: Thu Mar 12 14:45:44 CET 2009
16 // $Id: CastorDumpConditions.cc,v 1.1 2011/05/09 19:38:47 mundim Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 #include <iostream>
24 #include <fstream>
25 #include <sstream>
26 #include <string>
27 
28 // user include files
32 
36 
48 
50 //
51 // class decleration
52 //
53 
55  public:
56  explicit CastorDumpConditions(const edm::ParameterSet&);
57  ~CastorDumpConditions() override;
58 
59  template<class S, class SRcd> void dumpIt(const std::vector<std::string>& mDumpRequest,
60  const edm::Event& e,
61  const edm::EventSetup& context,
62  const std::string name);
63 
64  private:
66  std::vector<std::string> mDumpRequest;
67  virtual void beginJob(const edm::EventSetup&) ;
68  void analyze(const edm::Event&, const edm::EventSetup&) override;
69  void endJob() override ;
70 
71  // ----------member data ---------------------------
72 };
73 
74 //
75 // constants, enums and typedefs
76 //
77 
78 //
79 // static data member definitions
80 //
81 
82 //
83 // constructors and destructor
84 //
86 
87 {
88  file_prefix = iConfig.getUntrackedParameter<std::string>("outFilePrefix","Dump");
89  mDumpRequest= iConfig.getUntrackedParameter<std::vector<std::string> >("dump",std::vector<std::string>());
90  if (mDumpRequest.empty()) {
91  std::cout << "CastorDumpConditions: No record to dump. Exiting." << std::endl;
92  exit(0);
93  }
94 
95 }
96 
97 
99 {
100 
101  // do anything here that needs to be done at desctruction time
102  // (e.g. close files, deallocate resources etc.)
103 
104 }
105 
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called to for each event ------------
112 void
114 {
115  using namespace edm;
116 
117 #ifdef THIS_IS_AN_EVENT_EXAMPLE
119  iEvent.getByLabel("example",pIn);
120 #endif
121 
122 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
123  ESHandle<SetupData> pSetup;
124  iSetup.get<SetupRecord>().get(pSetup);
125 #endif
126  std::cout << "I AM IN THE RUN " << iEvent.id().run() << std::endl;
127  std::cout << "What to dump? "<< std::endl;
128  if (mDumpRequest.empty()) {
129  std::cout<< "CastorDumpConditions: Empty request" << std::endl;
130  return;
131  }
132 
133  for(std::vector<std::string>::const_iterator it=mDumpRequest.begin();it!=mDumpRequest.end();it++)
134  std::cout << *it << std::endl;
135 
136  // dumpIt called for all possible ValueMaps. The function checks if the dump is actually requested.
137  dumpIt<CastorElectronicsMap , CastorElectronicsMapRcd> (mDumpRequest, iEvent,iSetup,"ElectronicsMap" );
138  dumpIt<CastorQIEData , CastorQIEDataRcd> (mDumpRequest, iEvent,iSetup,"QIEData" );
139  dumpIt<CastorPedestals , CastorPedestalsRcd> (mDumpRequest, iEvent,iSetup,"Pedestals" );
140  dumpIt<CastorPedestalWidths , CastorPedestalWidthsRcd> (mDumpRequest, iEvent,iSetup,"PedestalWidths" );
141  dumpIt<CastorGains , CastorGainsRcd> (mDumpRequest, iEvent,iSetup,"Gains" );
142  dumpIt<CastorGainWidths , CastorGainWidthsRcd> (mDumpRequest, iEvent,iSetup,"GainWidths" );
143  dumpIt<CastorChannelQuality , CastorChannelQualityRcd> (mDumpRequest, iEvent,iSetup,"ChannelQuality" );
144  dumpIt<CastorRecoParams , CastorRecoParamsRcd> (mDumpRequest, iEvent,iSetup,"RecoParams" );
145  dumpIt<CastorSaturationCorrs, CastorSaturationCorrsRcd>(mDumpRequest, iEvent,iSetup,"SaturationCorrs");
146 }
147 
148 
149 // ------------ method called once each job just before starting event loop ------------
150 void
152 {
153 }
154 
155 // ------------ method called once each job just after ending the event loop ------------
156 void
158 }
159 
160 template<class S, class SRcd>
161 void CastorDumpConditions::dumpIt(const std::vector<std::string>& mDumpRequest,
162  const edm::Event& e,
163  const edm::EventSetup& context,
164  const std::string name) {
165  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), name) != mDumpRequest.end())
166  {
167  int myrun = e.id().run();
169  context.get<SRcd>().get(p);
170  S myobject(*p.product());
171 
172  std::ostringstream file;
173  file << file_prefix << name.c_str() << "_Run" << myrun << ".txt";
174  std::ofstream outStream(file.str().c_str() );
175  CastorDbASCIIIO::dumpObject (outStream, myobject );
176  }
177 }
178 
179 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
virtual void beginJob()
Definition: EDAnalyzer.h:85
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void analyze(const edm::Event &, const edm::EventSetup &) override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
int iEvent
Definition: GenABIO.cc:230
std::vector< std::string > mDumpRequest
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
void dumpIt(const std::vector< std::string > &mDumpRequest, const edm::Event &e, const edm::EventSetup &context, const std::string name)
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
CastorDumpConditions(const edm::ParameterSet &)
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
T get() const
Definition: EventSetup.h:62
T const * product() const
Definition: ESHandle.h:86