CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Attributes | Friends
MonitorElementsDb Class Reference

#include <MonitorElementsDb.h>

Public Member Functions

 MonitorElementsDb (const edm::ParameterSet &ps, std::string &xmlFile)
 Constructors. More...
 
virtual ~MonitorElementsDb ()
 Destructor. More...
 

Protected Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c, coral::ISessionProxy *s)
 Analyze. More...
 
void beginJob (void)
 
void endJob (void)
 
void htmlOutput (std::string &htmlDir)
 
void startSession (void)
 

Private Attributes

DQMStoredqmStore_
 
int ievt_
 
std::vector< DB_MEMEinfo_
 
std::vector< MonitorElement * > MEs_
 
MonitorXMLParserparser_
 
std::string prefixME_
 
std::string xmlFile_
 

Friends

class EcalBarrelMonitorDbModule
 

Detailed Description

Definition at line 27 of file MonitorElementsDb.h.

Constructor & Destructor Documentation

MonitorElementsDb::MonitorElementsDb ( const edm::ParameterSet ps,
std::string &  xmlFile 
)

Constructors.

Definition at line 34 of file MonitorElementsDb.cc.

References DQMStore::book1D(), DQMStore::book2D(), DQMStore::bookProfile(), DQMStore::bookProfile2D(), MessageLogger_cfi::cerr, dqmStore_, MillePedeFileConverter_cfg::e, MonitorXMLParser::getDB_ME(), edm::ParameterSet::getUntrackedParameter(), mps_fire::i, ievt_, MonitorXMLParser::load(), MEinfo_, MEs_, Utilities::operator, parser_, prefixME_, DQMStore::setCurrentFolder(), AlCaHLTBitMon_QueryRunRegistry::string, runGCPTkAlMap::title, tmp, fw3dlego::xbins, xmlFile_, and globals_cff::zbins.

34  {
35  xmlFile_ = xmlFile;
36 
38 
39  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
40 
41  if (dqmStore_) {
43 
45  try {
46  parser_->load();
47  } catch (std::runtime_error const &e) {
48  delete parser_;
49  parser_ = nullptr;
50  std::cerr << "Error loading parser: " << e.what() << std::endl;
51  }
52 
53  if (parser_)
55 
56  for (unsigned int i = 0; i < MEinfo_.size(); i++) {
58  tmp = nullptr;
59  if (strcmp(MEinfo_[i].type.c_str(), "th1d") == 0) {
60  tmp = dqmStore_->book1D(MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto);
61  } else if (strcmp(MEinfo_[i].type.c_str(), "th2d") == 0) {
62  tmp = dqmStore_->book2D(MEinfo_[i].title,
63  MEinfo_[i].title,
64  MEinfo_[i].xbins,
65  MEinfo_[i].xfrom,
66  MEinfo_[i].xto,
67  MEinfo_[i].ybins,
68  MEinfo_[i].yfrom,
69  MEinfo_[i].yto);
70  } else if (strcmp(MEinfo_[i].type.c_str(), "tprofile") == 0) {
72  MEinfo_[i].title,
73  MEinfo_[i].xbins,
74  MEinfo_[i].xfrom,
75  MEinfo_[i].xto,
76  MEinfo_[i].ybins,
77  MEinfo_[i].yfrom,
78  MEinfo_[i].yto);
79  } else if (strcmp(MEinfo_[i].type.c_str(), "tprofile2d") == 0) {
81  MEinfo_[i].title,
82  MEinfo_[i].xbins,
83  MEinfo_[i].xfrom,
84  MEinfo_[i].xto,
85  MEinfo_[i].ybins,
86  MEinfo_[i].yfrom,
87  MEinfo_[i].yto,
88  MEinfo_[i].zbins,
89  MEinfo_[i].zfrom,
90  MEinfo_[i].zto);
91  }
92 
93  MEs_.push_back(tmp);
94  }
95  }
96 
97  ievt_ = 0;
98 }
MonitorElement * book2D(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1173
MonitorElement * bookProfile2D(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s")
Definition: DQMStore.cc:1379
type
Definition: HCALResponse.h:21
T getUntrackedParameter(std::string const &, T const &) const
const double xbins[]
const std::vector< DB_ME > & getDB_ME(void) const
MonitorElement * book1D(char_string const &name, char_string const &title, int const nchX, double const lowX, double const highX)
Book 1D histogram.
Definition: DQMStore.cc:1098
void load() noexcept(false)
std::vector< MonitorElement * > MEs_
std::vector< DB_ME > MEinfo_
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:571
MonitorElement * bookProfile(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:1285
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
MonitorXMLParser * parser_
MonitorElementsDb::~MonitorElementsDb ( )
virtual

Destructor.

Definition at line 100 of file MonitorElementsDb.cc.

References parser_.

100 { delete parser_; }
MonitorXMLParser * parser_

Member Function Documentation

void MonitorElementsDb::analyze ( const edm::Event e,
const edm::EventSetup c,
coral::ISessionProxy *  s 
)
protected

Analyze.

Definition at line 112 of file MonitorElementsDb.cc.

References egammaCTFFinalFitWithMaterial_cff::alias, MessageLogger_cfi::cerr, relativeConstraints::empty, cppFunctionSkipper::exception, Exception, cmsRelvalreport::exit, mps_fire::i, ievt_, gen::k, checklumidiff::l, MEinfo_, MEs_, das::query(), and dataDML::schema.

Referenced by EcalBarrelMonitorDbModule::analyze().

112  {
113  ievt_++;
114 
115  bool atLeastAQuery;
116  atLeastAQuery = false;
117 
118  std::vector<std::string> vars;
119 
120  if (session) {
121  for (unsigned int i = 0; i < MEinfo_.size(); i++) {
122  // i-th ME...
123 
124  if (MEs_[i] != nullptr && (ievt_ % MEinfo_[i].ncycle) == 0) {
125  MEs_[i]->Reset();
126 
127  vars.clear();
128 
129  try {
130  atLeastAQuery = true;
131 
132  session->transaction().start(true);
133 
134  coral::ISchema &schema = session->nominalSchema();
135 
136  coral::IQuery *query = schema.newQuery();
137 
138  for (unsigned int j = 0; j < MEinfo_[i].queries.size(); j++) {
139  if (strcmp(MEinfo_[i].queries[j].query.c_str(), "addToTableList") == 0) {
140  query->addToTableList(MEinfo_[i].queries[j].arg);
141  } else if (strcmp(MEinfo_[i].queries[j].query.c_str(), "addToOutputList") == 0) {
142  query->addToOutputList(MEinfo_[i].queries[j].arg, MEinfo_[i].queries[j].alias);
143  vars.push_back(MEinfo_[i].queries[j].alias);
144  } else if (strcmp(MEinfo_[i].queries[j].query.c_str(), "setCondition") == 0) {
145  query->setCondition(MEinfo_[i].queries[j].arg, coral::AttributeList());
146  } else if (strcmp(MEinfo_[i].queries[j].query.c_str(), "addToOrderList") == 0) {
147  query->addToOrderList(MEinfo_[i].queries[j].arg);
148  }
149  }
150 
151  coral::ICursor &cursor = query->execute();
152 
153  unsigned int k = 0;
154 
155  while (cursor.next() && k < MEinfo_[i].loop) {
156  // while ( cursor.next() ) {
157 
158  const coral::AttributeList &row = cursor.currentRow();
159 
160  std::vector<float> vvars;
161  vvars.clear();
162  for (unsigned int l = 0; l < vars.size(); l++) {
163  if (!vars[l].empty()) {
164  vvars.push_back(row[vars[l]].data<float>());
165  }
166  }
167  if (vvars.size() == 2) {
168  // std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] <<
169  // std::endl;
170  MEs_[i]->Fill(vvars[0], vvars[1]);
171  } else if (vvars.size() == 3) {
172  // std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] << "
173  // -- " << vvars[2] << std::endl;
174  MEs_[i]->Fill(vvars[0], vvars[1], vvars[2]);
175  } else if (vvars.size() == 4) {
176  // std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] << "
177  // -- " << vvars[2] << " -- " << vvars[3] << std::endl;
178  MEs_[i]->Fill(vvars[0], vvars[1], vvars[2], vvars[3]);
179  } else {
180  std::cerr << "Too many variables to plot..." << std::endl;
181  exit(1);
182  }
183 
184  k++;
185  }
186 
187  delete query;
188 
189  } catch (coral::Exception &e) {
190  std::cerr << "CORAL Exception : " << e.what() << std::endl;
191  } catch (std::exception &e) {
192  std::cerr << "Standard C++ exception : " << e.what() << std::endl;
193  }
194  }
195  }
196 
197  if (atLeastAQuery)
198  session->transaction().commit();
199  }
200 }
A arg
Definition: Factorize.h:38
def query(query_str, verbose=False)
Definition: das.py:6
Definition: query.py:1
std::vector< MonitorElement * > MEs_
std::vector< DB_ME > MEinfo_
int k[5][pyjets_maxn]
vars
Definition: DeepTauId.cc:77
void MonitorElementsDb::beginJob ( void  )
protected

Definition at line 102 of file MonitorElementsDb.cc.

References ievt_.

Referenced by EcalBarrelMonitorDbModule::beginJob().

102 { ievt_ = 0; }
void MonitorElementsDb::endJob ( void  )
protected

Definition at line 104 of file MonitorElementsDb.cc.

References gather_cfg::cout, dqmStore_, getName(), mps_fire::i, ievt_, MEs_, and DQMStore::removeElement().

Referenced by EcalBarrelMonitorDbModule::endJob().

104  {
105  std::cout << "MonitorElementsDb: analyzed " << ievt_ << " events" << std::endl;
106  for (unsigned int i = 0; i < MEs_.size(); i++) {
107  if (MEs_[i] != nullptr)
109  }
110 }
void removeElement(std::string const &name)
Definition: DQMStore.cc:3126
std::vector< MonitorElement * > MEs_
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:167
void MonitorElementsDb::htmlOutput ( std::string &  htmlDir)
protected

Definition at line 202 of file MonitorElementsDb.cc.

References alignmentValidation::c1, h, mps_fire::i, ievt_, createfilelist::int, MEinfo_, MEs_, gen::n, dataset::name, AlCaHLTBitMon_QueryRunRegistry::string, and fw3dlego::xbins.

Referenced by EcalBarrelMonitorDbModule::analyze().

202  {
203  gStyle->SetOptStat(0);
204  gStyle->SetOptFit();
205  gStyle->SetPalette(1, nullptr);
206 
207  for (unsigned int i = 0; i < MEinfo_.size(); i++) {
208  if (MEs_[i] != nullptr && (ievt_ % MEinfo_[i].ncycle) == 0) {
209  TCanvas *c1;
210  int n = MEinfo_[i].xbins > MEinfo_[i].ybins ? int(round(float(MEinfo_[i].xbins) / float(MEinfo_[i].ybins)))
211  : int(round(float(MEinfo_[i].ybins) / float(MEinfo_[i].xbins)));
212  if (MEinfo_[i].xbins > MEinfo_[i].ybins) {
213  c1 = new TCanvas("c1", "dummy", 400 * n, 400);
214  } else {
215  c1 = new TCanvas("c1", "dummy", 400, 400 * n);
216  }
217  c1->SetGrid();
218  c1->cd();
219 
220  const double histMax = 1.e15;
221 
222  TObject *ob = const_cast<MonitorElement *>(MEs_[i])->getRootObject();
223  if (ob) {
224  if (dynamic_cast<TH1F *>(ob)) {
225  TH1F *h = dynamic_cast<TH1F *>(ob);
226  h->Draw();
227  } else if (dynamic_cast<TH2F *>(ob)) {
228  TH2F *h = dynamic_cast<TH2F *>(ob);
229  if (h->GetMaximum(histMax) > 1.e4) {
230  gPad->SetLogz(1);
231  } else {
232  gPad->SetLogz(0);
233  }
234  h->Draw("colz");
235  } else if (dynamic_cast<TProfile *>(ob)) {
236  TProfile *h = dynamic_cast<TProfile *>(ob);
237  if (h->GetMaximum(histMax) > 1.e4) {
238  gPad->SetLogz(1);
239  } else {
240  gPad->SetLogz(0);
241  }
242  h->Draw("colz");
243  }
244  }
245 
246  c1->Update();
247  std::string name = htmlDir + "/" + MEinfo_[i].title + ".png";
248  c1->SaveAs(name.c_str());
249 
250  delete c1;
251  }
252  }
253 }
const double xbins[]
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::vector< MonitorElement * > MEs_
std::vector< DB_ME > MEinfo_
void MonitorElementsDb::startSession ( void  )
protected

Friends And Related Function Documentation

friend class EcalBarrelMonitorDbModule
friend

Definition at line 28 of file MonitorElementsDb.h.

Member Data Documentation

DQMStore* MonitorElementsDb::dqmStore_
private

Definition at line 59 of file MonitorElementsDb.h.

Referenced by endJob(), and MonitorElementsDb().

int MonitorElementsDb::ievt_
private

Definition at line 58 of file MonitorElementsDb.h.

Referenced by analyze(), beginJob(), endJob(), htmlOutput(), and MonitorElementsDb().

std::vector<DB_ME> MonitorElementsDb::MEinfo_
private

Definition at line 56 of file MonitorElementsDb.h.

Referenced by analyze(), htmlOutput(), and MonitorElementsDb().

std::vector<MonitorElement *> MonitorElementsDb::MEs_
private

Definition at line 57 of file MonitorElementsDb.h.

Referenced by analyze(), endJob(), htmlOutput(), and MonitorElementsDb().

MonitorXMLParser* MonitorElementsDb::parser_
private

Definition at line 55 of file MonitorElementsDb.h.

Referenced by MonitorElementsDb(), and ~MonitorElementsDb().

std::string MonitorElementsDb::prefixME_
private

Definition at line 53 of file MonitorElementsDb.h.

Referenced by MonitorElementsDb().

std::string MonitorElementsDb::xmlFile_
private

Definition at line 54 of file MonitorElementsDb.h.

Referenced by MonitorElementsDb().