CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalPedestalAnalyzer.cc
Go to the documentation of this file.
1 
4 
6 //#include "CondTools/Hcal/interface/HcalDbTool.h"
11 
12 
13 /*
14  * \file HcalPedestalAnalyzer.cc
15  *
16  * $Date: 2010/02/25 00:28:13 $
17  * $Revision: 1.14 $
18  * \author S Stoynev / W Fisher
19  *
20 */
21 
22 namespace {
23  bool defaultsFile (const std::string fParam) {
24  return fParam == "defaults";
25  }
26 
27  bool asciiFile (const std::string fParam) {
28  return fParam.find (':') == std::string::npos && std::string (fParam, fParam.length () - 4) == ".txt";
29  }
30 
31  bool xmlFile (const std::string fParam) {
32  return fParam.find (':') == std::string::npos && std::string (fParam, fParam.length () - 4) == ".xml";
33  }
34 
35  bool dbFile (const std::string fParam) {
36  return fParam.find (':') != std::string::npos;
37  }
38 
39  bool masterDb (const std::string fParam) {
40  return fParam.find ('@') != std::string::npos;
41  }
42 
43  template <class T>
44  bool getObject (T* fObject, const std::string& fDb, const std::string& fTag, int fRun) {
45  if (!fObject) return false;
46  if (fDb.empty ()) return false;
47  if (asciiFile (fDb)) {
48  std::cout << "HcalPedestalAnalyzer-> USE INPUT: ASCII " << std::endl;
49  std::ifstream stream (fDb.c_str ());
50  HcalDbASCIIIO::getObject (stream, fObject);
51  return true;
52  }
53  else if (dbFile (fDb)) {
54  std::cout << "HcalPedestalAnalyzer-> USE INPUT: Pool " << fDb << std::endl;
55  std::cout << "HcalPedestalAnalyzer-> Pool interface is not supportet since 1.3.0" << fDb << std::endl;
56  return false;
57 // HcalDbTool poolDb (fDb);
58 // return poolDb.getObject (fObject, fTag, fRun);
59  }
60  else if (masterDb (fDb)) {
61  std::cout << "HcalPedestalAnalyzer-> USE INPUT: MasterDB " << fDb << std::endl;
62  HcalDbOnline masterDb (fDb);
63  return masterDb.getObject (fObject, fTag, fRun);
64  }
65  else {
66  std::cerr << "HcalPedestalAnalyzer-> Unknown input type " << fDb << std::endl;
67  return false;
68  }
69  }
70 
71  bool dumpXmlPedestals (const HcalPedestals& fObject, const HcalPedestalWidths& fWidth, const std::string& fXml, const std::string& fTag, int fRun) {
72  std::cout << "HcalPedestalAnalyzer-> USE OUTPUT: XML" << std::endl;
73  std::ofstream stream (fXml.c_str ());
74  bool result = HcalDbXml::dumpObject (stream, fRun, fRun, 0, fTag, fObject, fWidth);
75  stream.close ();
76  return result;
77  }
78 
79  template <class T>
80  bool putObject (T** fObject, const std::string& fDb, const std::string& fTag, int fRun) {
81  if (!fObject || !*fObject) return false;
82  if (fDb.empty ()) return false;
83  if (asciiFile (fDb)) {
84  std::cout << "HcalPedestalAnalyzer-> USE OUTPUT: ASCII " << std::endl;
85  std::ofstream stream (fDb.c_str ());
86  HcalDbASCIIIO::dumpObject (stream, **fObject);
87  return true;
88  }
89  else if (dbFile (fDb)) {
90  std::cout << "HcalPedestalAnalyzer-> USE OUTPUT: Pool " << fDb << std::endl;
91  std::cout << "HcalPedestalAnalyzer-> Pool interface is not supportet since 1.3.0" << fDb << std::endl;
92  return false;
93 // HcalDbTool poolDb (fDb);
94 // bool result = poolDb.putObject (*fObject, fTag, fRun);
95 // if (result) *fObject = 0; // owned by POOL
96 // return result;
97  }
98  else {
99  std::cerr << "HcalPedestalAnalyzer-> Unknown output type " << fDb << std::endl;
100  return false;
101  }
102  }
103 }
104 
106 
108  m_pedAnal->setup(ps.getUntrackedParameter<std::string>("outputFileHist", "HcalPedestalAnalyzer.root"));
109 
110  m_startSample = ps.getUntrackedParameter<int>("firstSample", 0);
111  m_endSample = ps.getUntrackedParameter<int>("lastSample", 19);
112  m_inputPedestals_source = ps.getUntrackedParameter<std::string>("inputPedestalsSource", "");
113  m_inputPedestals_tag = ps.getUntrackedParameter<std::string>("inputPedestalsTag", "");
114  m_inputPedestals_run = ps.getUntrackedParameter<int>("inputPedestalsRun", 1);
115  m_inputPedestalWidths_source = ps.getUntrackedParameter<std::string>("inputPedestalWidthsSource", "");
116  m_inputPedestalWidths_tag = ps.getUntrackedParameter<std::string>("inputPedestalWidthsTag", "");
117  m_inputPedestalWidths_run = ps.getUntrackedParameter<int>("inputPedestalWidthsRun", 1);
118  m_outputPedestals_dest = ps.getUntrackedParameter<std::string>("outputPedestalsDest", "");
119  m_outputPedestals_tag = ps.getUntrackedParameter<std::string>("outputPedestalsTag", "");
120  m_outputPedestals_run = ps.getUntrackedParameter<int>("outputPedestalsRun", 99999);
121  m_outputPedestalWidths_dest = ps.getUntrackedParameter<std::string>("outputPedestalWidthsDest", "");
122  m_outputPedestalWidths_tag = ps.getUntrackedParameter<std::string>("outputPedestalWidthsTag", "");
123  m_outputPedestalWidths_run = ps.getUntrackedParameter<int>("outputPedestalWidthsRun", 99999);
124 
125  // CORAL required variables to be set, even if not needed
126  const char* foo1 = "CORAL_AUTH_USER=blaaah";
127  const char* foo2 = "CORAL_AUTH_PASSWORD=blaaah";
128  if (!::getenv("CORAL_AUTH_USER")) ::putenv(const_cast<char*>(foo1));
129  if (!::getenv("CORAL_AUTH_PASSWORD")) ::putenv(const_cast<char*>(foo2));
130 }
131 
133 // delete m_pedAnal;
134 }
135 
137  m_ievt = 0;
138  ped_sample = 1;
139 }
140 
142  // get input objects
143  HcalPedestals* inputPeds = 0;
144  if (!m_inputPedestals_source.empty ()) {
145  inputPeds = new HcalPedestals ();
147  std::cerr << "HcalPedestalAnalyzer-> Failed to get input Pedestals" << std::endl;
148  }
149  }
150  HcalPedestalWidths* inputPedWids = 0;
151  if (!m_inputPedestalWidths_source.empty ()) {
152  inputPedWids = new HcalPedestalWidths ();
154  std::cerr << "HcalPedestalAnalyzer-> Failed to get input PedestalWidths" << std::endl;
155  }
156  }
157 
158  // make output objects
159  HcalPedestals* outputPeds = (m_outputPedestals_dest.empty () && !xmlFile (m_outputPedestals_dest)) ? 0 : new HcalPedestals ();
161 
162  // run algorithm
163  int Flag=m_pedAnal->done(inputPeds, inputPedWids, outputPeds, outputPedWids);
164 
165  delete inputPeds;
166  delete inputPedWids;
167 
168 
169  // store new objects
170  // Flag=-2 indicates there were less than 100 events and output is meaningless
171  if (Flag>-2) {
172  if (xmlFile (m_outputPedestals_dest)) { // output pedestals and widths together
173  if (!dumpXmlPedestals (*outputPeds, *outputPedWids, m_outputPedestals_dest, m_outputPedestals_tag, m_outputPedestals_run)) {
174  std::cerr << "HcalPedestalAnalyzer-> Failed to put output Pedestals & Widths" << std::endl;
175  }
176  }
177  else {
178  if (outputPeds) {
179  if (!putObject (&outputPeds, m_outputPedestals_dest, m_outputPedestals_tag, m_outputPedestals_run)) {
180  std::cerr << "HcalPedestalAnalyzer-> Failed to put output Pedestals" << std::endl;
181  }
182  }
183  if (outputPedWids) {
185  std::cerr << "HcalPedestalAnalyzer-> Failed to put output PedestalWidths" << std::endl;
186  }
187  }
188  }
189  }
190  delete outputPeds;
191  delete outputPedWids;
192 }
193 
195 
196  m_ievt++;
197 
202 
203  // get conditions
204  edm::ESHandle<HcalDbService> conditions;
205  eventSetup.get<HcalDbRecord>().get(conditions);
206 
207  m_pedAnal->processEvent(*hbhe, *ho, *hf, *conditions);
208 
209  if(m_ievt%1000 == 0)
210  std::cout << "HcalPedestalAnalyzer: analyzed " << m_ievt << " events" << std::endl;
211 
212  return;
213 }
214 
215 // #include "FWCore/PluginManager/interface/ModuleDef.h"
216 // #include "FWCore/Framework/interface/MakerMacros.h"
217 
218 //
219 // DEFINE_FWK_MODULE(HcalPedestalAnalyzer);
std::string m_outputPedestalWidths_tag
T getUntrackedParameter(std::string const &, T const &) const
~HcalPedestalAnalyzer()
Destructor.
TObject * getObject(TDirectory *fDir, const std::vector< std::string > &fObjectName)
Definition: compareHists.cc:44
bool defaultsFile(const std::string fParam)
bool dumpObject(std::ostream &fOutput, unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string &fTag, unsigned fVersion, const HcalPedestals &fObject, const HcalPedestalWidths &fError)
Definition: HcalDbXml.cc:169
bool getByType(Handle< PROD > &result) const
Definition: Event.h:398
void processEvent(const HBHEDigiCollection &hbhe, const HODigiCollection &ho, const HFDigiCollection &hf, const HcalDbService &cond)
std::string m_outputPedestalWidths_dest
int done(const HcalPedestals *fInputPedestals, const HcalPedestalWidths *fInputWidths, HcalPedestals *fOutputPedestals, HcalPedestalWidths *fOutputWidths)
void setup(const std::string &m_outputFileROOT)
std::string m_inputPedestalWidths_source
tuple result
Definition: query.py:137
Gather conditions data from online DB.
Definition: HcalDbOnline.h:34
std::string m_outputPedestals_dest
bool dbFile(const std::string fParam)
std::string m_inputPedestalWidths_tag
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
const T & get() const
Definition: EventSetup.h:55
bool xmlFile(const std::string fParam)
bool getObject(std::istream &fInput, HcalPedestals *fObject)
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
bool asciiFile(const std::string fParam)
std::string m_inputPedestals_source
tuple cout
Definition: gather_cfg.py:121
long double T
HcalPedestalAnalyzer(const edm::ParameterSet &ps)
Constructor.
HcalPedestalAnalysis * m_pedAnal