CMS 3D CMS Logo

MonitorElementsDb.cc
Go to the documentation of this file.
1 
8 
9 #include <cmath>
10 #include <fstream>
11 #include <iostream>
12 
14 
15 #include "RelationalAccess/ICursor.h"
16 #include "RelationalAccess/IQuery.h"
17 #include "RelationalAccess/ISchema.h"
18 #include "RelationalAccess/ITransaction.h"
19 
20 #include "CoralBase/Attribute.h"
21 #include "CoralBase/AttributeList.h"
22 
23 #include "TCanvas.h"
24 #include "TStyle.h"
25 
26 #include "TH1.h"
27 #include "TH2.h"
28 #include "TProfile.h"
29 
31 
33  xmlFile_ = xmlFile;
34 
35  dqmStore_ = edm::Service<DQMStore>().operator->();
36 
37  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
38 
39  if (dqmStore_) {
41 
43  try {
44  parser_->load();
45  } catch (std::runtime_error const &e) {
46  delete parser_;
47  parser_ = nullptr;
48  std::cerr << "Error loading parser: " << e.what() << std::endl;
49  }
50 
51  if (parser_)
53 
54  for (unsigned int i = 0; i < MEinfo_.size(); i++) {
56  tmp = nullptr;
57  if (strcmp(MEinfo_[i].type.c_str(), "th1d") == 0) {
59  } else if (strcmp(MEinfo_[i].type.c_str(), "th2d") == 0) {
61  MEinfo_[i].title,
62  MEinfo_[i].xbins,
63  MEinfo_[i].xfrom,
64  MEinfo_[i].xto,
65  MEinfo_[i].ybins,
66  MEinfo_[i].yfrom,
67  MEinfo_[i].yto);
68  } else if (strcmp(MEinfo_[i].type.c_str(), "tprofile") == 0) {
70  MEinfo_[i].title,
71  MEinfo_[i].xbins,
72  MEinfo_[i].xfrom,
73  MEinfo_[i].xto,
74  MEinfo_[i].ybins,
75  MEinfo_[i].yfrom,
76  MEinfo_[i].yto);
77  } else if (strcmp(MEinfo_[i].type.c_str(), "tprofile2d") == 0) {
79  MEinfo_[i].title,
80  MEinfo_[i].xbins,
81  MEinfo_[i].xfrom,
82  MEinfo_[i].xto,
83  MEinfo_[i].ybins,
84  MEinfo_[i].yfrom,
85  MEinfo_[i].yto,
86  MEinfo_[i].zbins,
87  MEinfo_[i].zfrom,
88  MEinfo_[i].zto);
89  }
90 
91  MEs_.push_back(tmp);
92  }
93  }
94 
95  ievt_ = 0;
96 }
97 
99 
101 
102 void MonitorElementsDb::endJob(void) { std::cout << "MonitorElementsDb: analyzed " << ievt_ << " events" << std::endl; }
103 
104 void MonitorElementsDb::analyze(const edm::Event &e, const edm::EventSetup &c, coral::ISessionProxy *session) {
105  ievt_++;
106 
107  bool atLeastAQuery;
108  atLeastAQuery = false;
109 
110  std::vector<std::string> vars;
111 
112  if (session) {
113  for (unsigned int i = 0; i < MEinfo_.size(); i++) {
114  // i-th ME...
115 
116  if (MEs_[i] != nullptr && (ievt_ % MEinfo_[i].ncycle) == 0) {
117  MEs_[i]->Reset();
118 
119  vars.clear();
120 
121  try {
122  atLeastAQuery = true;
123 
124  session->transaction().start(true);
125 
126  coral::ISchema &schema = session->nominalSchema();
127 
128  coral::IQuery *query = schema.newQuery();
129 
130  for (unsigned int j = 0; j < MEinfo_[i].queries.size(); j++) {
131  if (strcmp(MEinfo_[i].queries[j].query.c_str(), "addToTableList") == 0) {
132  query->addToTableList(MEinfo_[i].queries[j].arg);
133  } else if (strcmp(MEinfo_[i].queries[j].query.c_str(), "addToOutputList") == 0) {
134  query->addToOutputList(MEinfo_[i].queries[j].arg, MEinfo_[i].queries[j].alias);
135  vars.push_back(MEinfo_[i].queries[j].alias);
136  } else if (strcmp(MEinfo_[i].queries[j].query.c_str(), "setCondition") == 0) {
137  query->setCondition(MEinfo_[i].queries[j].arg, coral::AttributeList());
138  } else if (strcmp(MEinfo_[i].queries[j].query.c_str(), "addToOrderList") == 0) {
139  query->addToOrderList(MEinfo_[i].queries[j].arg);
140  }
141  }
142 
143  coral::ICursor &cursor = query->execute();
144 
145  unsigned int k = 0;
146 
147  while (cursor.next() && k < MEinfo_[i].loop) {
148  // while ( cursor.next() ) {
149 
150  const coral::AttributeList &row = cursor.currentRow();
151 
152  std::vector<float> vvars;
153  vvars.clear();
154  for (unsigned int l = 0; l < vars.size(); l++) {
155  if (!vars[l].empty()) {
156  vvars.push_back(row[vars[l]].data<float>());
157  }
158  }
159  if (vvars.size() == 2) {
160  // std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] <<
161  // std::endl;
162  MEs_[i]->Fill(vvars[0], vvars[1]);
163  } else if (vvars.size() == 3) {
164  // std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] << "
165  // -- " << vvars[2] << std::endl;
166  MEs_[i]->Fill(vvars[0], vvars[1], vvars[2]);
167  } else if (vvars.size() == 4) {
168  // std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] << "
169  // -- " << vvars[2] << " -- " << vvars[3] << std::endl;
170  MEs_[i]->Fill(vvars[0], vvars[1], vvars[2], vvars[3]);
171  } else {
172  std::cerr << "Too many variables to plot..." << std::endl;
173  exit(1);
174  }
175 
176  k++;
177  }
178 
179  delete query;
180 
181  } catch (coral::Exception &e) {
182  std::cerr << "CORAL Exception : " << e.what() << std::endl;
183  } catch (std::exception &e) {
184  std::cerr << "Standard C++ exception : " << e.what() << std::endl;
185  }
186  }
187  }
188 
189  if (atLeastAQuery)
190  session->transaction().commit();
191  }
192 }
193 
195  gStyle->SetOptStat(0);
196  gStyle->SetOptFit();
197  gStyle->SetPalette(1, nullptr);
198 
199  for (unsigned int i = 0; i < MEinfo_.size(); i++) {
200  if (MEs_[i] != nullptr && (ievt_ % MEinfo_[i].ncycle) == 0) {
201  TCanvas *c1;
202  int n = MEinfo_[i].xbins > MEinfo_[i].ybins ? int(round(float(MEinfo_[i].xbins) / float(MEinfo_[i].ybins)))
203  : int(round(float(MEinfo_[i].ybins) / float(MEinfo_[i].xbins)));
204  if (MEinfo_[i].xbins > MEinfo_[i].ybins) {
205  c1 = new TCanvas("c1", "dummy", 400 * n, 400);
206  } else {
207  c1 = new TCanvas("c1", "dummy", 400, 400 * n);
208  }
209  c1->SetGrid();
210  c1->cd();
211 
212  const double histMax = 1.e15;
213 
214  TObject *ob = const_cast<MonitorElement *>(MEs_[i])->getRootObject();
215  if (ob) {
216  if (dynamic_cast<TH1F *>(ob)) {
217  TH1F *h = dynamic_cast<TH1F *>(ob);
218  h->Draw();
219  } else if (dynamic_cast<TH2F *>(ob)) {
220  TH2F *h = dynamic_cast<TH2F *>(ob);
221  if (h->GetMaximum(histMax) > 1.e4) {
222  gPad->SetLogz(1);
223  } else {
224  gPad->SetLogz(0);
225  }
226  h->Draw("colz");
227  } else if (dynamic_cast<TProfile *>(ob)) {
228  TProfile *h = dynamic_cast<TProfile *>(ob);
229  if (h->GetMaximum(histMax) > 1.e4) {
230  gPad->SetLogz(1);
231  } else {
232  gPad->SetLogz(0);
233  }
234  h->Draw("colz");
235  }
236  }
237 
238  c1->Update();
239  std::string name = htmlDir + "/" + MEinfo_[i].title + ".png";
240  c1->SaveAs(name.c_str());
241 
242  delete c1;
243  }
244  }
245 }
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
fw3dlego::xbins
const double xbins[]
Definition: fw3dlego_xbins.cc:16
mps_fire.i
i
Definition: mps_fire.py:428
MonitorElementsDb::MEinfo_
std::vector< DB_ME > MEinfo_
Definition: MonitorElementsDb.h:57
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
dqm::implementation::IBooker::bookProfile2D
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
gather_cfg.cout
cout
Definition: gather_cfg.py:144
MonitorElementsDb::~MonitorElementsDb
virtual ~MonitorElementsDb()
Destructor.
Definition: MonitorElementsDb.cc:98
MonitorXMLParser
Definition: MonitorXMLParser.h:154
DQMStore.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
MonitorElementsDb::MEs_
std::vector< MonitorElement * > MEs_
Definition: MonitorElementsDb.h:58
MonitorElementsDb::htmlOutput
void htmlOutput(std::string &htmlDir)
Definition: MonitorElementsDb.cc:194
MonitorXMLParser::load
void load() noexcept(false)
Definition: MonitorXMLParser.cc:402
globals_cff.zbins
zbins
Definition: globals_cff.py:17
query
Definition: query.py:1
vars
vars
Definition: DeepTauId.cc:164
Service.h
dqm::implementation::IBooker::bookProfile
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:322
dqm::implementation::DQMStore::setCurrentFolder
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:569
h
dqmdumpme.k
k
Definition: dqmdumpme.py:60
MonitorElementsDb.h
Generate a Monitor Element from DB data.
MonitorElementsDb::MonitorElementsDb
MonitorElementsDb(const edm::ParameterSet &ps, std::string &xmlFile)
Constructors.
Definition: MonitorElementsDb.cc:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
MonitorElementsDb::dqmStore_
DQMStore * dqmStore_
Definition: MonitorElementsDb.h:60
edm::ParameterSet
Definition: ParameterSet.h:47
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
MonitorElementsDb::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c, coral::ISessionProxy *s)
Analyze.
Definition: MonitorElementsDb.cc:104
edm::Service
Definition: Service.h:30
createfilelist.int
int
Definition: createfilelist.py:10
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
edm::EventSetup
Definition: EventSetup.h:58
MonitorElementsDb::endJob
void endJob(void)
Definition: MonitorElementsDb.cc:102
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
MonitorXMLParser::getDB_ME
const std::vector< DB_ME > & getDB_ME(void) const
Definition: MonitorXMLParser.h:167
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
SiStripOfflineCRack_cfg.alias
alias
Definition: SiStripOfflineCRack_cfg.py:128
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
Exception
Definition: hltDiff.cc:245
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
funct::arg
A arg
Definition: Factorize.h:31
contentValuesFiles.query
query
Definition: contentValuesFiles.py:38
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
MonitorElementsDb::parser_
MonitorXMLParser * parser_
Definition: MonitorElementsDb.h:56
edm::Event
Definition: Event.h:73
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
MonitorElementsDb::prefixME_
std::string prefixME_
Definition: MonitorElementsDb.h:54
MonitorElementsDb::xmlFile_
std::string xmlFile_
Definition: MonitorElementsDb.h:55
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
MonitorElementsDb::ievt_
int ievt_
Definition: MonitorElementsDb.h:59
MonitorElementsDb::beginJob
void beginJob(void)
Definition: MonitorElementsDb.cc:100