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"
18 
19 
20 /*
21  * \file HcalPedestalAnalyzer.cc
22  *
23  * $Date: 2012/11/13 03:30:20 $
24  * $Revision: 1.16 $
25  * \author S Stoynev / W Fisher
26  *
27 */
28 
29 namespace {
30  bool defaultsFile (const std::string fParam) {
31  return fParam == "defaults";
32  }
33 
34  bool asciiFile (const std::string fParam) {
35  return fParam.find (':') == std::string::npos && std::string (fParam, fParam.length () - 4) == ".txt";
36  }
37 
38  bool xmlFile (const std::string fParam) {
39  return fParam.find (':') == std::string::npos && std::string (fParam, fParam.length () - 4) == ".xml";
40  }
41 
42  bool dbFile (const std::string fParam) {
43  return fParam.find (':') != std::string::npos;
44  }
45 
46  bool masterDb (const std::string fParam) {
47  return fParam.find ('@') != std::string::npos;
48  }
49 
50  template <class T>
51  bool getObject (T* fObject, const std::string& fDb, const std::string& fTag, int fRun) {
52  if (!fObject) return false;
53  if (fDb.empty ()) return false;
54  if (asciiFile (fDb)) {
55  std::cout << "HcalPedestalAnalyzer-> USE INPUT: ASCII " << std::endl;
56  std::ifstream stream (fDb.c_str ());
57  HcalDbASCIIIO::getObject (stream, fObject);
58  return true;
59  }
60  else if (dbFile (fDb)) {
61  std::cout << "HcalPedestalAnalyzer-> USE INPUT: Pool " << fDb << std::endl;
62  std::cout << "HcalPedestalAnalyzer-> Pool interface is not supportet since 1.3.0" << fDb << std::endl;
63  return false;
64 // HcalDbTool poolDb (fDb);
65 // return poolDb.getObject (fObject, fTag, fRun);
66  }
67  else if (masterDb (fDb)) {
68  std::cout << "HcalPedestalAnalyzer-> USE INPUT: MasterDB " << fDb << std::endl;
69  HcalDbOnline masterDb (fDb);
70  return masterDb.getObject (fObject, fTag, fRun);
71  }
72  else {
73  std::cerr << "HcalPedestalAnalyzer-> Unknown input type " << fDb << std::endl;
74  return false;
75  }
76  }
77 
78  bool dumpXmlPedestals (const HcalPedestals& fObject, const HcalPedestalWidths& fWidth, const std::string& fXml, const std::string& fTag, int fRun) {
79  std::cout << "HcalPedestalAnalyzer-> USE OUTPUT: XML" << std::endl;
80  std::ofstream stream (fXml.c_str ());
81  bool result = HcalDbXml::dumpObject (stream, fRun, fRun, 0, fTag, fObject, fWidth);
82  stream.close ();
83  return result;
84  }
85 
86  template <class T>
87  bool putObject (T** fObject, const std::string& fDb, const std::string& fTag, int fRun) {
88  if (!fObject || !*fObject) return false;
89  if (fDb.empty ()) return false;
90  if (asciiFile (fDb)) {
91  std::cout << "HcalPedestalAnalyzer-> USE OUTPUT: ASCII " << std::endl;
92  std::ofstream stream (fDb.c_str ());
93  HcalDbASCIIIO::dumpObject (stream, **fObject);
94  return true;
95  }
96  else if (dbFile (fDb)) {
97  std::cout << "HcalPedestalAnalyzer-> USE OUTPUT: Pool " << fDb << std::endl;
98  std::cout << "HcalPedestalAnalyzer-> Pool interface is not supportet since 1.3.0" << fDb << std::endl;
99  return false;
100 // HcalDbTool poolDb (fDb);
101 // bool result = poolDb.putObject (*fObject, fTag, fRun);
102 // if (result) *fObject = 0; // owned by POOL
103 // return result;
104  }
105  else {
106  std::cerr << "HcalPedestalAnalyzer-> Unknown output type " << fDb << std::endl;
107  return false;
108  }
109  }
110 }
111 
113  hbheDigiCollectionTag_(ps.getParameter<edm::InputTag>("hbheDigiCollectionTag")),
114  hoDigiCollectionTag_(ps.getParameter<edm::InputTag>("hoDigiCollectionTag")),
115  hfDigiCollectionTag_(ps.getParameter<edm::InputTag>("hfDigiCollectionTag")) {
116 
118  m_pedAnal->setup(ps.getUntrackedParameter<std::string>("outputFileHist", "HcalPedestalAnalyzer.root"));
119 
120  m_startSample = ps.getUntrackedParameter<int>("firstSample", 0);
121  m_endSample = ps.getUntrackedParameter<int>("lastSample", 19);
122  m_inputPedestals_source = ps.getUntrackedParameter<std::string>("inputPedestalsSource", "");
123  m_inputPedestals_tag = ps.getUntrackedParameter<std::string>("inputPedestalsTag", "");
124  m_inputPedestals_run = ps.getUntrackedParameter<int>("inputPedestalsRun", 1);
125  m_inputPedestalWidths_source = ps.getUntrackedParameter<std::string>("inputPedestalWidthsSource", "");
126  m_inputPedestalWidths_tag = ps.getUntrackedParameter<std::string>("inputPedestalWidthsTag", "");
127  m_inputPedestalWidths_run = ps.getUntrackedParameter<int>("inputPedestalWidthsRun", 1);
128  m_outputPedestals_dest = ps.getUntrackedParameter<std::string>("outputPedestalsDest", "");
129  m_outputPedestals_tag = ps.getUntrackedParameter<std::string>("outputPedestalsTag", "");
130  m_outputPedestals_run = ps.getUntrackedParameter<int>("outputPedestalsRun", 99999);
131  m_outputPedestalWidths_dest = ps.getUntrackedParameter<std::string>("outputPedestalWidthsDest", "");
132  m_outputPedestalWidths_tag = ps.getUntrackedParameter<std::string>("outputPedestalWidthsTag", "");
133  m_outputPedestalWidths_run = ps.getUntrackedParameter<int>("outputPedestalWidthsRun", 99999);
134 
135  // CORAL required variables to be set, even if not needed
136  const char* foo1 = "CORAL_AUTH_USER=blaaah";
137  const char* foo2 = "CORAL_AUTH_PASSWORD=blaaah";
138  if (!::getenv("CORAL_AUTH_USER")) ::putenv(const_cast<char*>(foo1));
139  if (!::getenv("CORAL_AUTH_PASSWORD")) ::putenv(const_cast<char*>(foo2));
140 }
141 
143 // delete m_pedAnal;
144 }
145 
147  m_ievt = 0;
148  ped_sample = 1;
149 }
150 
152  // get input objects
153  HcalPedestals* inputPeds = 0;
154  if (!m_inputPedestals_source.empty ()) {
155  inputPeds = new HcalPedestals (m_topo);
157  std::cerr << "HcalPedestalAnalyzer-> Failed to get input Pedestals" << std::endl;
158  }
159  }
160  HcalPedestalWidths* inputPedWids = 0;
161  if (!m_inputPedestalWidths_source.empty ()) {
162  inputPedWids = new HcalPedestalWidths (m_topo);
164  std::cerr << "HcalPedestalAnalyzer-> Failed to get input PedestalWidths" << std::endl;
165  }
166  }
167 
168  // make output objects
169  HcalPedestals* outputPeds = (m_outputPedestals_dest.empty () && !xmlFile (m_outputPedestals_dest)) ? 0 : new HcalPedestals (m_topo);
171 
172  // run algorithm
173  int Flag=m_pedAnal->done(inputPeds, inputPedWids, outputPeds, outputPedWids);
174 
175  delete inputPeds;
176  delete inputPedWids;
177 
178 
179  // store new objects
180  // Flag=-2 indicates there were less than 100 events and output is meaningless
181  if (Flag>-2) {
182  if (xmlFile (m_outputPedestals_dest)) { // output pedestals and widths together
183  if (!dumpXmlPedestals (*outputPeds, *outputPedWids, m_outputPedestals_dest, m_outputPedestals_tag, m_outputPedestals_run)) {
184  std::cerr << "HcalPedestalAnalyzer-> Failed to put output Pedestals & Widths" << std::endl;
185  }
186  }
187  else {
188  if (outputPeds) {
189  if (!putObject (&outputPeds, m_outputPedestals_dest, m_outputPedestals_tag, m_outputPedestals_run)) {
190  std::cerr << "HcalPedestalAnalyzer-> Failed to put output Pedestals" << std::endl;
191  }
192  }
193  if (outputPedWids) {
195  std::cerr << "HcalPedestalAnalyzer-> Failed to put output PedestalWidths" << std::endl;
196  }
197  }
198  }
199  }
200  delete outputPeds;
201  delete outputPedWids;
202 }
203 
205 
206  m_ievt++;
207 
212 
213  // get conditions
214  edm::ESHandle<HcalDbService> conditions;
215  eventSetup.get<HcalDbRecord>().get(conditions);
216 
217  if (m_topo==0) {
218  const IdealGeometryRecord& record = eventSetup.get<IdealGeometryRecord>();
220  record.get (topology);
221  m_topo=new HcalTopology(*topology);
222  }
223 
224 
225  m_pedAnal->processEvent(*hbhe, *ho, *hf, *conditions);
226 
227  if(m_ievt%1000 == 0)
228  std::cout << "HcalPedestalAnalyzer: analyzed " << m_ievt << " events" << std::endl;
229 
230  return;
231 }
232 
233 // #include "FWCore/PluginManager/interface/ModuleDef.h"
234 // #include "FWCore/Framework/interface/MakerMacros.h"
235 
236 //
237 // DEFINE_FWK_MODULE(HcalPedestalAnalyzer);
std::string m_outputPedestalWidths_tag
T getUntrackedParameter(std::string const &, T const &) const
edm::InputTag hbheDigiCollectionTag_
~HcalPedestalAnalyzer()
Destructor.
TObject * getObject(TDirectory *fDir, const std::vector< std::string > &fObjectName)
Definition: compareHists.cc:44
JetCorrectorParameters::Record record
Definition: classes.h:13
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
edm::InputTag hfDigiCollectionTag_
void processEvent(const HBHEDigiCollection &hbhe, const HODigiCollection &ho, const HFDigiCollection &hf, const HcalDbService &cond)
const HcalTopology * m_topo
edm::InputTag hoDigiCollectionTag_
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
void get(HolderT &iHolder) const
Gather conditions data from online DB.
Definition: HcalDbOnline.h:34
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
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