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&);
58 
59  template<class S, class SRcd> void dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name);
60 
61  private:
63  std::vector<std::string> mDumpRequest;
64  virtual void beginJob(const edm::EventSetup&) ;
65  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
66  virtual void endJob() override ;
67 
68  // ----------member data ---------------------------
69 };
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
83 
84 {
85  file_prefix = iConfig.getUntrackedParameter<std::string>("outFilePrefix","Dump");
86  mDumpRequest= iConfig.getUntrackedParameter<std::vector<std::string> >("dump",std::vector<std::string>());
87  if (mDumpRequest.empty()) {
88  std::cout << "CastorDumpConditions: No record to dump. Exiting." << std::endl;
89  exit(0);
90  }
91 
92 }
93 
94 
96 {
97 
98  // do anything here that needs to be done at desctruction time
99  // (e.g. close files, deallocate resources etc.)
100 
101 }
102 
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to for each event ------------
109 void
111 {
112  using namespace edm;
113 
114 #ifdef THIS_IS_AN_EVENT_EXAMPLE
116  iEvent.getByLabel("example",pIn);
117 #endif
118 
119 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
120  ESHandle<SetupData> pSetup;
121  iSetup.get<SetupRecord>().get(pSetup);
122 #endif
123  std::cout << "I AM IN THE RUN " << iEvent.id().run() << std::endl;
124  std::cout << "What to dump? "<< std::endl;
125  if (mDumpRequest.empty()) {
126  std::cout<< "CastorDumpConditions: Empty request" << std::endl;
127  return;
128  }
129 
130  for(std::vector<std::string>::const_iterator it=mDumpRequest.begin();it!=mDumpRequest.end();it++)
131  std::cout << *it << std::endl;
132 
133  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ElectronicsMap")) != mDumpRequest.end())
134  dumpIt(new CastorElectronicsMap(), new CastorElectronicsMapRcd(), iEvent,iSetup,"ElectronicsMap");
135 
136  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("QIEData")) != mDumpRequest.end())
137  dumpIt(new CastorQIEData(), new CastorQIEDataRcd(), iEvent,iSetup,"QIEData");
138 
139  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Pedestals")) != mDumpRequest.end())
140  dumpIt(new CastorPedestals(), new CastorPedestalsRcd(), iEvent,iSetup,"Pedestals");
141 
142  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PedestalWidths")) != mDumpRequest.end())
143  dumpIt(new CastorPedestalWidths(), new CastorPedestalWidthsRcd(), iEvent,iSetup,"PedestalWidths");
144 
145  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Gains")) != mDumpRequest.end())
146  dumpIt(new CastorGains(), new CastorGainsRcd(), iEvent,iSetup,"Gains");
147 
148  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("GainWidths")) != mDumpRequest.end())
149  dumpIt(new CastorGainWidths(), new CastorGainWidthsRcd(), iEvent,iSetup,"GainWidths");
150 
151  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ChannelQuality")) != mDumpRequest.end())
152  dumpIt(new CastorChannelQuality(), new CastorChannelQualityRcd(), iEvent,iSetup,"ChannelQuality");
153 
154  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("RecoParams")) != mDumpRequest.end())
155  dumpIt(new CastorRecoParams(), new CastorRecoParamsRcd(), iEvent,iSetup,"RecoParams");
156 
157  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("SaturationCorrs")) != mDumpRequest.end())
158  dumpIt(new CastorSaturationCorrs(), new CastorSaturationCorrsRcd(), iEvent,iSetup,"SaturationCorrs");
159 
160 /*
161  ESHandle<CastorPedestals> p;
162  iSetup.get<CastorPedestalsRcd>().get(p);
163  CastorPedestals* mypeds = new CastorPedestals(*p.product());
164  std::ostringstream file;
165  std::string name = "CastorPedestal";
166  file << file_prefix << name.c_str() << "_Run" << iEvent.id().run()<< ".txt";
167  std::ofstream outStream(file.str().c_str() );
168  std::cout << "CastorDumpConditions: ---- Dumping " << name.c_str() << " ----" << std::endl;
169  CastorDbASCIIIO::dumpObject (outStream, (*mypeds) );
170 
171 */
172 }
173 
174 
175 // ------------ method called once each job just before starting event loop ------------
176 void
178 {
179 }
180 
181 // ------------ method called once each job just after ending the event loop ------------
182 void
184 }
185 
186 template<class S, class SRcd>
187  void CastorDumpConditions::dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name) {
188  int myrun = e.id().run();
190  context.get<SRcd>().get(p);
191  S* myobject = new S(*p.product());
192 
193  std::ostringstream file;
194  file << file_prefix << name.c_str() << "_Run" << myrun << ".txt";
195  std::ofstream outStream(file.str().c_str() );
196  CastorDbASCIIIO::dumpObject (outStream, (*myobject) );
197  }
198 
199 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
virtual void beginJob()
Definition: EDAnalyzer.h:79
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void endJob() override
virtual 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:413
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
CastorDumpConditions(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:56
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
edm::EventID id() const
Definition: EventBase.h:58
HLT enums.
T const * product() const
Definition: ESHandle.h:86
void dumpIt(S *myS, SRcd *mySRcd, const edm::Event &e, const edm::EventSetup &context, std::string name)