CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
 
class EcalEndcapMonitorDbModule
 

Detailed Description

Definition at line 31 of file MonitorElementsDb.h.

Constructor & Destructor Documentation

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

Constructors.

Definition at line 38 of file MonitorElementsDb.cc.

References DQMStore::book1D(), DQMStore::book2D(), DQMStore::bookProfile(), DQMStore::bookProfile2D(), benchmark_cfg::cerr, dqmStore_, MonitorXMLParser::getDB_ME(), edm::ParameterSet::getUntrackedParameter(), i, MonitorXMLParser::load(), MEinfo_, MEs_, cmsCodeRules.cppFunctionSkipper::operator, parser_, prefixME_, DQMStore::setCurrentFolder(), indexGen::title, tmp, fw3dlego::xbins, xmlFile(), and xmlFile_.

38  {
39 
40  xmlFile_ = xmlFile;
41 
43 
44  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
45 
46  if ( dqmStore_ ) {
47 
49 
51  try {
52  parser_->load();
53  } catch( const std::runtime_error e ) {
54  std::cerr << "Error loading parser: " << e.what() << std::endl;
55  }
56 
58 
59  for( unsigned int i=0; i< MEinfo_.size(); i++ ) {
60 
62  tmp = 0;
63  if( strcmp(MEinfo_[i].type.c_str(), "th1d") == 0 ) {
64  tmp = dqmStore_->book1D( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto );
65  }
66  else if( strcmp(MEinfo_[i].type.c_str(), "th2d") == 0 ) {
67  tmp = dqmStore_->book2D( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto,
68  MEinfo_[i].ybins, MEinfo_[i].yfrom, MEinfo_[i].yto );
69  }
70  else if( strcmp(MEinfo_[i].type.c_str(), "tprofile") == 0 ) {
71  tmp = dqmStore_->bookProfile( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto,
72  MEinfo_[i].ybins, MEinfo_[i].yfrom, MEinfo_[i].yto );
73  }
74  else if( strcmp(MEinfo_[i].type.c_str(), "tprofile2d") == 0 ) {
75  tmp = dqmStore_->bookProfile2D( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto,
76  MEinfo_[i].ybins, MEinfo_[i].yfrom, MEinfo_[i].yto,
77  MEinfo_[i].zbins, MEinfo_[i].zfrom, MEinfo_[i].zto );
78  }
79 
80  MEs_.push_back( tmp );
81  }
82 
83  }
84 
85 }
type
Definition: HCALResponse.h:22
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
const double xbins[]
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
const std::vector< DB_ME > & getDB_ME(void) const
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:828
std::vector< DB_ME > MEinfo_
std::vector< MonitorElement * > MEs_
bool xmlFile(const std::string fParam)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:642
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
MonitorXMLParser * parser_
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:972
MonitorElementsDb::~MonitorElementsDb ( )
virtual

Destructor.

Definition at line 87 of file MonitorElementsDb.cc.

87  {
88 
89 }

Member Function Documentation

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

Analyze.

Definition at line 106 of file MonitorElementsDb.cc.

References benchmark_cfg::cerr, relativeConstraints::empty, cmsCodeRules.cppFunctionSkipper::exception, edm::hlt::Exception, cmsRelvalreport::exit, i, ievt_, j, gen::k, prof2calltree::l, MEinfo_, MEs_, o2o::query, and python.IdGenerator::schema.

Referenced by EcalBarrelMonitorDbModule::analyze(), and EcalEndcapMonitorDbModule::analyze().

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

Definition at line 91 of file MonitorElementsDb.cc.

References ievt_.

Referenced by EcalBarrelMonitorDbModule::beginJob(), and EcalEndcapMonitorDbModule::beginJob().

91  {
92 
93  ievt_ = 0;
94 
95 }
void MonitorElementsDb::endJob ( void  )
protected

Definition at line 97 of file MonitorElementsDb.cc.

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

Referenced by EcalBarrelMonitorDbModule::endJob(), and EcalEndcapMonitorDbModule::endJob().

97  {
98 
99  std::cout << "MonitorElementsDb: analyzed " << ievt_ << " events" << std::endl;
100  for( unsigned int i = 0; i<MEs_.size(); i++ ) {
101  if( MEs_[i] != 0 ) dqmStore_->removeElement( MEs_[i]->getName() );
102  }
103 
104 }
int i
Definition: DBlmapReader.cc:9
void removeElement(const std::string &name)
Definition: DQMStore.cc:2353
std::string getName(Reflex::Type &cc)
Definition: ClassFiller.cc:18
std::vector< MonitorElement * > MEs_
tuple cout
Definition: gather_cfg.py:41
void MonitorElementsDb::htmlOutput ( std::string &  htmlDir)
protected

Definition at line 210 of file MonitorElementsDb.cc.

References alignmentValidation::c1, h, i, ievt_, MEinfo_, MEs_, n, mergeVDriftHistosByStation::name, and fw3dlego::xbins.

Referenced by EcalBarrelMonitorDbModule::analyze(), and EcalEndcapMonitorDbModule::analyze().

210  {
211 
212  gStyle->SetOptStat(0);
213  gStyle->SetOptFit();
214  gStyle->SetPalette(1,0);
215 
216  for( unsigned int i=0; i<MEinfo_.size(); i++ ) {
217 
218  if( MEs_[i] != 0 && ( ievt_ % MEinfo_[i].ncycle ) == 0 ) {
219 
220  TCanvas* c1;
221  int n = MEinfo_[i].xbins > MEinfo_[i].ybins ? int( round( float( MEinfo_[i].xbins ) / float( MEinfo_[i].ybins ) ) ) :
222  int( round( float( MEinfo_[i].ybins ) / float( MEinfo_[i].xbins ) ) );
223  if( MEinfo_[i].xbins > MEinfo_[i].ybins ) {
224  c1 = new TCanvas( "c1", "dummy", 400*n, 400 );
225  }
226  else {
227  c1 = new TCanvas( "c1", "dummy", 400, 400*n );
228  }
229  c1->SetGrid();
230  c1->cd();
231 
232  const double histMax = 1.e15;
233 
234  TObject* ob = const_cast<MonitorElement*>(MEs_[i])->getRootObject();
235  if ( ob ) {
236  if( dynamic_cast<TH1F*>( ob ) ) {
237  TH1F* h = dynamic_cast<TH1F*> ( ob );
238  h->Draw( );
239  }
240  else if( dynamic_cast<TH2F*>( ob ) ) {
241  TH2F* h = dynamic_cast<TH2F*>( ob );
242  if( h->GetMaximum(histMax) > 1.e4 ) {
243  gPad->SetLogz(1);
244  } else {
245  gPad->SetLogz(0);
246  }
247  h->Draw( "colz" );
248  }
249  else if( dynamic_cast<TProfile*>( ob ) ) {
250  TProfile* h = dynamic_cast<TProfile*>( ob );
251  if( h->GetMaximum(histMax) > 1.e4 ) {
252  gPad->SetLogz(1);
253  } else {
254  gPad->SetLogz(0);
255  }
256  h->Draw( "colz" );
257  }
258  }
259 
260  c1->Update();
261  std::string name = htmlDir + "/" + MEinfo_[i].title + ".png";
262  c1->SaveAs( name.c_str() );
263 
264  delete c1;
265 
266  }
267  }
268 }
int i
Definition: DBlmapReader.cc:9
const double xbins[]
std::vector< DB_ME > MEinfo_
std::vector< MonitorElement * > MEs_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void MonitorElementsDb::startSession ( void  )
protected

Friends And Related Function Documentation

friend class EcalBarrelMonitorDbModule
friend

Definition at line 33 of file MonitorElementsDb.h.

friend class EcalEndcapMonitorDbModule
friend

Definition at line 34 of file MonitorElementsDb.h.

Member Data Documentation

DQMStore* MonitorElementsDb::dqmStore_
private

Definition at line 68 of file MonitorElementsDb.h.

Referenced by endJob(), and MonitorElementsDb().

int MonitorElementsDb::ievt_
private

Definition at line 67 of file MonitorElementsDb.h.

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

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

Definition at line 65 of file MonitorElementsDb.h.

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

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

Definition at line 66 of file MonitorElementsDb.h.

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

MonitorXMLParser* MonitorElementsDb::parser_
private

Definition at line 64 of file MonitorElementsDb.h.

Referenced by MonitorElementsDb().

std::string MonitorElementsDb::prefixME_
private

Definition at line 62 of file MonitorElementsDb.h.

Referenced by MonitorElementsDb().

std::string MonitorElementsDb::xmlFile_
private

Definition at line 63 of file MonitorElementsDb.h.

Referenced by MonitorElementsDb().