test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MonitorElementsDb.cc
Go to the documentation of this file.
1 
8 
9 #include <iostream>
10 #include <fstream>
11 #include <cmath>
12 
14 
16 
17 #include "RelationalAccess/ITransaction.h"
18 #include "RelationalAccess/ISchema.h"
19 #include "RelationalAccess/IQuery.h"
20 #include "RelationalAccess/ICursor.h"
21 
22 #include "CoralBase/Attribute.h"
23 #include "CoralBase/AttributeList.h"
24 
25 #include "TCanvas.h"
26 #include "TStyle.h"
27 
28 #include "TH1.h"
29 #include "TH2.h"
30 #include "TProfile.h"
31 
32 #include "../interface/MonitorElementsDb.h"
33 
35 
36  xmlFile_ = xmlFile;
37 
39 
40  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
41 
42  if ( dqmStore_ ) {
43 
45 
47  try {
48  parser_->load();
49  } catch( const std::runtime_error e ) {
50  delete parser_;
51  parser_ = 0;
52  std::cerr << "Error loading parser: " << e.what() << std::endl;
53  }
54 
56 
57  for( unsigned int i=0; i< MEinfo_.size(); i++ ) {
58 
60  tmp = 0;
61  if( strcmp(MEinfo_[i].type.c_str(), "th1d") == 0 ) {
62  tmp = dqmStore_->book1D( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto );
63  }
64  else if( strcmp(MEinfo_[i].type.c_str(), "th2d") == 0 ) {
65  tmp = dqmStore_->book2D( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto,
66  MEinfo_[i].ybins, MEinfo_[i].yfrom, MEinfo_[i].yto );
67  }
68  else if( strcmp(MEinfo_[i].type.c_str(), "tprofile") == 0 ) {
69  tmp = dqmStore_->bookProfile( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto,
70  MEinfo_[i].ybins, MEinfo_[i].yfrom, MEinfo_[i].yto );
71  }
72  else if( strcmp(MEinfo_[i].type.c_str(), "tprofile2d") == 0 ) {
73  tmp = dqmStore_->bookProfile2D( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto,
74  MEinfo_[i].ybins, MEinfo_[i].yfrom, MEinfo_[i].yto,
75  MEinfo_[i].zbins, MEinfo_[i].zfrom, MEinfo_[i].zto );
76  }
77 
78  MEs_.push_back( tmp );
79  }
80 
81  }
82 
83  ievt_ = 0;
84 
85 }
86 
88 
89  delete parser_;
90 
91 }
92 
94 
95  ievt_ = 0;
96 
97 }
98 
100 
101  std::cout << "MonitorElementsDb: analyzed " << ievt_ << " events" << std::endl;
102  for( unsigned int i = 0; i<MEs_.size(); i++ ) {
103  if( MEs_[i] != 0 ) dqmStore_->removeElement( MEs_[i]->getName() );
104  }
105 
106 }
107 
108 void MonitorElementsDb::analyze( const edm::Event& e, const edm::EventSetup& c, coral::ISessionProxy* session ){
109 
110  ievt_++;
111 
112  bool atLeastAQuery;
113  atLeastAQuery = false;
114 
115  std::vector<std::string> vars;
116 
117  if ( session ) {
118 
119  for( unsigned int i=0; i<MEinfo_.size(); i++ ) {
120 
121  // i-th ME...
122 
123  if( MEs_[i] != 0 && ( ievt_ % MEinfo_[i].ncycle ) == 0 ) {
124 
125  MEs_[i]->Reset();
126 
127  vars.clear();
128 
129  try {
130 
131  atLeastAQuery = true;
132 
133  session->transaction().start(true);
134 
135  coral::ISchema& schema = session->nominalSchema();
136 
137  coral::IQuery* query = schema.newQuery();
138 
139  for( unsigned int j=0; j<MEinfo_[i].queries.size(); j++ ) {
140  if( strcmp(MEinfo_[i].queries[j].query.c_str(), "addToTableList") == 0 ) {
141  query->addToTableList( MEinfo_[i].queries[j].arg );
142  }
143  else if( strcmp(MEinfo_[i].queries[j].query.c_str(), "addToOutputList") == 0 ) {
144  query->addToOutputList( MEinfo_[i].queries[j].arg, MEinfo_[i].queries[j].alias );
145  vars.push_back( MEinfo_[i].queries[j].alias );
146  }
147  else if( strcmp(MEinfo_[i].queries[j].query.c_str(), "setCondition") == 0 ) {
148  query->setCondition( MEinfo_[i].queries[j].arg, coral::AttributeList() );
149  }
150  else if( strcmp(MEinfo_[i].queries[j].query.c_str(), "addToOrderList") == 0 ) {
151  query->addToOrderList( MEinfo_[i].queries[j].arg );
152  }
153  }
154 
155  coral::ICursor& cursor = query->execute();
156 
157  unsigned int k = 0;
158 
159  while ( cursor.next() && k < MEinfo_[i].loop ) {
160  //while ( cursor.next() ) {
161 
162  const coral::AttributeList& row = cursor.currentRow();
163 
164  std::vector<float> vvars;
165  vvars.clear();
166  for( unsigned int l=0; l<vars.size(); l++ ) {
167  if( !vars[l].empty() ) {
168  vvars.push_back( row[vars[l].c_str()].data<float>() );
169  }
170  }
171  if( vvars.size() == 2 ) {
172  //std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] << std::endl;
173  MEs_[i]->Fill( vvars[0], vvars[1] );
174  }
175  else if( vvars.size() == 3 ) {
176  //std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] << " -- " << vvars[2] << std::endl;
177  MEs_[i]->Fill( vvars[0], vvars[1], vvars[2] );
178  }
179  else if( vvars.size() == 4 ) {
180  //std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] << " -- " << vvars[2] << " -- " << vvars[3] << std::endl;
181  MEs_[i]->Fill( vvars[0], vvars[1], vvars[2], vvars[3] );
182  }
183  else{
184  std::cerr << "Too many variables to plot..." << std::endl;
185  exit(1);
186  }
187 
188  k++;
189 
190  }
191 
192  delete query;
193 
194  } catch ( coral::Exception& e ) {
195  std::cerr << "CORAL Exception : " << e.what() << std::endl;
196  } catch ( std::exception& e ) {
197  std::cerr << "Standard C++ exception : " << e.what() << std::endl;
198  }
199  }
200 
201  }
202 
203  if( atLeastAQuery ) session->transaction().commit();
204 
205  }
206 
207 }
208 
210 
211  gStyle->SetOptStat(0);
212  gStyle->SetOptFit();
213  gStyle->SetPalette(1,0);
214 
215  for( unsigned int i=0; i<MEinfo_.size(); i++ ) {
216 
217  if( MEs_[i] != 0 && ( ievt_ % MEinfo_[i].ncycle ) == 0 ) {
218 
219  TCanvas* c1;
220  int n = MEinfo_[i].xbins > MEinfo_[i].ybins ? int( round( float( MEinfo_[i].xbins ) / float( MEinfo_[i].ybins ) ) ) :
221  int( round( float( MEinfo_[i].ybins ) / float( MEinfo_[i].xbins ) ) );
222  if( MEinfo_[i].xbins > MEinfo_[i].ybins ) {
223  c1 = new TCanvas( "c1", "dummy", 400*n, 400 );
224  }
225  else {
226  c1 = new TCanvas( "c1", "dummy", 400, 400*n );
227  }
228  c1->SetGrid();
229  c1->cd();
230 
231  const double histMax = 1.e15;
232 
233  TObject* ob = const_cast<MonitorElement*>(MEs_[i])->getRootObject();
234  if ( ob ) {
235  if( dynamic_cast<TH1F*>( ob ) ) {
236  TH1F* h = dynamic_cast<TH1F*> ( ob );
237  h->Draw( );
238  }
239  else if( dynamic_cast<TH2F*>( ob ) ) {
240  TH2F* h = dynamic_cast<TH2F*>( ob );
241  if( h->GetMaximum(histMax) > 1.e4 ) {
242  gPad->SetLogz(1);
243  } else {
244  gPad->SetLogz(0);
245  }
246  h->Draw( "colz" );
247  }
248  else if( dynamic_cast<TProfile*>( ob ) ) {
249  TProfile* h = dynamic_cast<TProfile*>( ob );
250  if( h->GetMaximum(histMax) > 1.e4 ) {
251  gPad->SetLogz(1);
252  } else {
253  gPad->SetLogz(0);
254  }
255  h->Draw( "colz" );
256  }
257  }
258 
259  c1->Update();
260  std::string name = htmlDir + "/" + MEinfo_[i].title + ".png";
261  c1->SaveAs( name.c_str() );
262 
263  delete c1;
264 
265  }
266  }
267 }
268 
type
Definition: HCALResponse.h:21
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElementsDb(const edm::ParameterSet &ps, std::string &xmlFile)
Constructors.
const double xbins[]
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:954
A arg
Definition: Factorize.h:36
void analyze(const edm::Event &e, const edm::EventSetup &c, coral::ISessionProxy *s)
Analyze.
void removeElement(const std::string &name)
Definition: DQMStore.cc:3143
const std::vector< DB_ME > & getDB_ME(void) const
int j
Definition: DBlmapReader.cc:9
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
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:1268
std::vector< DB_ME > MEinfo_
int k[5][pyjets_maxn]
std::vector< MonitorElement * > MEs_
bool xmlFile(const std::string fParam)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
tuple query
Definition: o2o.py:269
tuple cout
Definition: gather_cfg.py:121
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:1082
virtual ~MonitorElementsDb()
Destructor.
void htmlOutput(std::string &htmlDir)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:667
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:1412