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
XmasToDQMSource Class Reference

#include <XmasToDQMSource.h>

Inheritance diagram for XmasToDQMSource:
edm::EDAnalyzer

Public Member Functions

 XmasToDQMSource (const edm::ParameterSet &)
 
 ~XmasToDQMSource ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Protected Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c)
 Fake Analyze. More...
 
void beginJob ()
 BeginJob. More...
 
void beginLuminosityBlock (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
 
void beginRun (const edm::Run &r, const edm::EventSetup &c)
 BeginRun. More...
 
void endJob ()
 Endjob. More...
 
void endLuminosityBlock (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
 DQM Client Diagnostic. More...
 
void endRun (const edm::Run &r, const edm::EventSetup &c)
 EndRun. More...
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Private Attributes

int counterEvt_
 
DQMStoredbe_
 
MonitorElementh1
 
std::map< std::string, struct
Data * > 
HostSlotMap
 
std::string monitorName_
 
std::string NBINS
 
edm::ParameterSet parameters_
 
int prescaleEvt_
 counter More...
 
std::string previousTimestamp
 
std::string XMAX
 
std::string XMIN
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 

Detailed Description

Definition at line 35 of file XmasToDQMSource.h.

Constructor & Destructor Documentation

XmasToDQMSource::XmasToDQMSource ( const edm::ParameterSet ps)

book some histograms here

Definition at line 36 of file XmasToDQMSource.cc.

References gather_cfg::cout, dbe_, edm::ParameterSet::getUntrackedParameter(), monitorName_, cmsCodeRules.cppFunctionSkipper::operator, parameters_, and prescaleEvt_.

36  :
37 counterEvt_(0)
38 {
39  cout << "Constructor of XmasToDQMSource called...." << endl;
40 
42  parameters_ = ps;
43  monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","DAQ");
44 
45  cout << "Monitor name = " << monitorName_ << endl;
46  if (monitorName_ != "" )
48 
49  prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
50  cout << "===> DQM event prescale = " << prescaleEvt_ << " events "<< endl;
51 
52 
54  //const int NBINS = 50; XMIN = 0; XMAX = 20000;
55 
56  // create and cd into new folder
57  //dbe_->setCurrentFolder(/*monitorName_+*/"wse");
58  //h1 = dbe_->book1D("histo", "Example 1D histogram.", NBINS, XMIN, XMAX);
59  //h1->setAxisTitle("x-axis title", 1);
60  //h1->setAxisTitle("y-axis title", 2);
61 
62  // assign tag to MEs h1, h2 and h7
63  //const unsigned int detector_id = 17;
64  //dbe_->tag(h1, detector_id);
65 }
edm::ParameterSet parameters_
T getUntrackedParameter(std::string const &, T const &) const
std::string monitorName_
int prescaleEvt_
counter
tuple cout
Definition: gather_cfg.py:41
XmasToDQMSource::~XmasToDQMSource ( )

Definition at line 68 of file XmasToDQMSource.cc.

69 {
70 
71  // do anything here that needs to be done at desctruction time
72  // (e.g. close files, deallocate resources etc.)
73 
74 }

Member Function Documentation

void XmasToDQMSource::analyze ( const edm::Event e,
const edm::EventSetup c 
)
protectedvirtual

Fake Analyze.

Implements edm::EDAnalyzer.

Definition at line 94 of file XmasToDQMSource.cc.

References DQMStore::book1D(), counterEvt_, gather_cfg::cout, dbe_, xmas2dqm::wse::ToDqm::flashlistMonitor_, HostSlotMap, i, xmas2dqm::wse::ToDqm::instance(), xmas2dqm::wse::ToDqm::MemoryTable_, monitorName_, ExpressReco_HICollisions_FallBack::nbins, NULL, prescaleEvt_, csvReporter::r, xmas2dqm::wse::ToDqm::runNumber_, asciidump::s, and DQMStore::setCurrentFolder().

96 {
97  /*time_t start,end;
98  static int times_called=0;
99 
100  times_called++;*/
101 
102 
103  //std::cout << "inside Analyze.... " << std::endl;
104 
105  std::map<std::string, std::string, std::less<std::string> >::iterator i;
106 
107  //cout << "DQMSourceExample::analyze before BSem_.takeO()" << endl;
108 
109  //xmas2dqm::wse::ToDqm::instance()->BSem_.take();
110 
111  std::cout << "inside DQMSource::Analyze...ready to lock the data mutex" << std::endl;
112  //protect access to the queue
113  pthread_mutex_lock(&xmas2dqm::wse::ToDqm::instance()->LASmutex_);
114 
115 
116  std::cout << "inside DQMSource::Analyze...check (...and possible wait) if data queue is empty" << std::endl;
117 
118  //check if the queue is empty and wait (a signal that informs that an element has been pushed)
119  while(xmas2dqm::wse::ToDqm::instance()->/*QTable_*/MemoryTable_.size() <= 0)
120  {
121  pthread_cond_wait(&xmas2dqm::wse::ToDqm::instance()->more_, &xmas2dqm::wse::ToDqm::instance()->LASmutex_);
122  }
123 
124 
125  std::cout << "inside DQMSource::Analyze...data queue has elements...proceeding..." << std::endl;
126 
127  //start = time(NULL);
128 
129  //xdata::Table::Reference ref_table;
130  xdata::Table *ref_table = NULL;
131 
132 
133  if(xmas2dqm::wse::ToDqm::instance()->/*QTable_*/MemoryTable_.size() > 0)
134  {
135  //cout << " DQMSourceExample::analyze : Queue size > 0 " << xmas2dqm::wse::ToDqm::instance()->QTable_.size() << endl;
136 
137  //pop an element from the queue of the LAS data
138  ref_table = xmas2dqm::wse::ToDqm::instance()->/*QTable_*/ MemoryTable_.front();
139  //xmas2dqm::wse::ToDqm::instance()->QTable_.pop();
140 
141  }
142 
143  //Insert data to histograms transfered to DQM GUI servers (print the table)
144  if(ref_table != NULL)
145  {
146 
147  for ( size_t r = 0; r < ref_table->numberOfRows_; r++ )
148  {
149 
150  //check if the flashlist contains the element we want to monitor
151  if(!ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element])
152  {
153  break;
154  }
155 
156  /* remove prints for benchmarking*/
157  /*
158  std::cout << "********* Printing table inside DQMSourceExample ***************" << std::endl;
159  std:: cout << ref_table->columnData_["context"]->elementAt(r)->toString() << std::endl;
160  std:: cout << ref_table->columnData_["slotNumber"]->elementAt(r)->toString() << std::endl;*/
161 
162  //if(ref_table->columnData_["wcHistogram"]->elementAt(r)->toString() == "[]")
163  if(ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()]->elementAt(r)->toString() == "[]")
164  {
165  /* remove prints for benchmarking*/
166  /*std::cout << ref_table->columnData_["context"]->elementAt(r)->toString() << " has empty bxHistogram" << std::endl;*/
167  continue;
168  }
169 
170 
171  //check if there is a column runNumber in the LAS table
172  if(ref_table->columnData_["runNumber"])
173  {
174  /* remove prints for benchmarking*/
175 
176 
177  //xmas2dqm::wse::ToDqm::instance()->BSem_.take();
178 
179  //if runNumber in LAS record different than currnet runNumber go to next LAS record
180  if (xmas2dqm::wse::ToDqm::instance()->runNumber_.toString() != ref_table->columnData_["runNumber"]->elementAt(r)->toString())
181  {
182  continue;
183  }
184 
185 
186  //xmas2dqm::wse::ToDqm::instance()->BSem_.give();
187  //std::cout << "runNumber ... = " << ref_table->columnData_["runNumber"]->elementAt(r)->toString() << std::endl;
188  }
189 
190  //boost::tokenizer<> Context_tokens(ref_table->columnData_["Context"]->elementAt(r)->toString());
191 
192  boost::char_separator<char> sep(":/.");
193  tokenizer Context_tokens(ref_table->columnData_["Context"]->elementAt(r)->toString(), sep);
194 
195 
196  //check if the combination Host + slotNumber exists already in the set of hosts + slotNumbers
197  //if not book a new histogram with correspondent name and push data, else push data to existent histogram
198  //std::string host_slot = *(++Context_tokens.begin()) + "_" + ref_table->columnData_["slotNumber"]->elementAt(r)->toString();
199 
200  std::string host_slot;
201  host_slot = *(++ Context_tokens.begin());
202 
203  //check if there is a column slotNumber in the LAS table in order to use as key for the histogram map the combination of host+slot
204  //useful mostly for bxHistogram, wcHistogram of frlHisto, where the histograms (flashlist elements) refer to host+slot
205  if(ref_table->columnData_["slotNumber"])
206  {
207  //host_slot = *(++ Context_tokens.begin()) + "-" + *(++ ++ Context_tokens.begin()) + "-" + *(++ ++ ++Context_tokens.begin()) + "_" + ref_table->columnData_["slotNumber"]->elementAt(r)->toString();
208  host_slot = host_slot + "_" + ref_table->columnData_["slotNumber"]->elementAt(r)->toString();
209  }
210 
211  //host_slot = host_slot + "_" + ref_table->columnData_["slotNumber"]->elementAt(r)->toString();
212 
213 
214  //check if there is no entry in the map for this host (+slot in case of wcHistogram, bxHistogram)
215  if( HostSlotMap.find(host_slot) == HostSlotMap.end())
216  {
217  /* remove prints for benchmarking*/
218  std::cout << "booking new histogram..." << host_slot << std::endl;
219 
220  HostSlotMap[host_slot] = new /*struct*/ Data();
221 
222 
223  HostSlotMap[host_slot]->lastTimestamp = ref_table->columnData_["timestamp"]->elementAt(r)->toString();
224 
225  // create and cd into new folder
226  //dbe_->setCurrentFolder(monitorName_ + "wcHisto");
227  dbe_->setCurrentFolder(monitorName_ + xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString());
228 
229  //the wcHistogramResolution equals the value of the register Histogram of the FRL, not the value of the bytes resolution for the bin
230  // the value of the register multiplied by 16 gives the byte resolution - range of a wcHistogram bin
231  // if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram")
232 // {
233 // HostSlotMap[host_slot]->Histogram1D = dbe_->book1D("wc_"+ host_slot, "FRL wcHisto", WCBIN,
234 // MIN_EVENT_FRAGMENT_SIZE, MIN_EVENT_FRAGMENT_SIZE + WCBIN*16*atoi(ref_table->columnData_["wcHistogramResolution"]->elementAt(r)->toString().c_str()));
235 // HostSlotMap[host_slot]->Histogram1D->setAxisTitle("Event fragment size (Bytes)"/*"x-axis title"*/, 1);
236 // HostSlotMap[host_slot]->Histogram1D->setAxisTitle("Events"/*"y-axis title"*/, 2);
237 // }
238 // else if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram")
239 // {
240 // HostSlotMap[host_slot]->Histogram1D = dbe_->book1D("bx_"+ host_slot, "FRL bxHisto", BXBIN, 1, BXBIN);
241 //
242 // HostSlotMap[host_slot]->Histogram1D->setAxisTitle("LHC orbit Bunch"/*"x-axis title"*/, 1);
243 // HostSlotMap[host_slot]->Histogram1D->setAxisTitle("Events"/*"y-axis title"*/, 2);
244 // }
245 
246  std::istringstream str2num;
247  int nbins;
248  double xmin,xmax;
249 
250  str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.bins.toString());
251  str2num >> nbins; // now stream is in end of file state
252  str2num.clear(); // clear end of file state
253 
254  str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xmin.toString());
255  str2num >> xmin; // now stream is in end of file state
256  str2num.clear(); // clear end of file state
257 
258  str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xmax.toString());
259  str2num >> xmax; // now stream is in end of file state
260  str2num.clear(); // clear end of file state
261 
262  HostSlotMap[host_slot]->Histogram1D = dbe_->book1D(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() + "_" + host_slot, "", nbins, xmin, xmax);
263  HostSlotMap[host_slot]->Histogram1D->setAxisTitle(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xtitle.toString()/*"x-axis title"*/, 1);
264  HostSlotMap[host_slot]->Histogram1D->setAxisTitle(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.ytitle.toString()/*"y-axis title"*/, 2);
265 
266 
267  /* remove prints for benchmarking*/
268  /*std::cout << "booked histogram = " << host_slot << std::endl;*/
269 
270 
271  boost::char_separator<char> histo_sep("[,]");
272  tokenizer Histogram_values(ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()]->elementAt(r)->toString(), histo_sep);
273 
274  int iwc=0; //bin counter
275 
276  for(tokenizer::iterator itok=Histogram_values.begin(); itok!=Histogram_values.end();++itok)
277  {
278  iwc++;
279  //remove for benchmarking
280  //std::cout << "iwc = "<< iwc << " *itok = " << *itok << std::endl;
281  string s = *itok;
282  //std::cout << "iwc = "<< iwc << " s = " << s << std::endl;
283  //HostSlotMap[host_slot]->Fill(atoi(s.c_str()));
284 
285  std::istringstream istrfloat(s);
286  float bin_value;
287  istrfloat >> bin_value;
288 
289  //std::cout << "iwc = "<< iwc << " bin_value = " << bin_value << std::endl;
290 
291  if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" || xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram")
292  {
293  HostSlotMap[host_slot]->Histogram1D->setBinContent(iwc-1, bin_value/*atoi(s.c_str())*/);
294  }
295  else
296  {
297  HostSlotMap[host_slot]->Histogram1D->Fill(bin_value);
298  }
299 
300  if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" && iwc >= nbins /*WCBIN*/)
301  break;
302 
303  if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram" && iwc >= nbins /*BXBIN*/)
304  break;
305  }
306 
307 
308  }
309  else
310  {
311 
312  std::istringstream str2num;
313  int nbins;
314 
315  str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.bins.toString());
316  str2num >> nbins; // now stream is in end of file state
317  str2num.clear(); // clear end of file state
318 
319 
320  //check if the timestamp has changed and proceed adding data only if timestamp has changed
321  if(HostSlotMap[host_slot]->lastTimestamp == ref_table->columnData_["timestamp"]->elementAt(r)->toString())
322  {
323  //std::cout << host_slot << " same timestamp found..." << std::endl;
324  continue;
325  }
326  else
327  {
328  //std::cout << host_slot << " different timestamp found..." << std::endl;
329  HostSlotMap[host_slot]->lastTimestamp == ref_table->columnData_["timestamp"]->elementAt(r)->toString();
330  }
331 
332 
333 
334  //insert wcHistogram values
335  boost::char_separator<char> histo_sep("[,]");
336  tokenizer Histogram_values(ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()]->elementAt(r)->toString(), histo_sep);
337 
338  int iwc=0; //bin counter
339 
340  for(tokenizer::iterator itok=Histogram_values.begin(); itok!=Histogram_values.end();++itok)
341  {
342  iwc++;
343  //remove for benchmarking
344  //std::cout << "fill booked histogram iwc = "<< iwc << " *itok = " << *itok << std::endl;
345 
346  string s = *itok;
347  //HostSlotMap[host_slot]->Fill(atoi(s.c_str()));
348 
349  std::istringstream istrfloat(s);
350  float bin_value;
351  istrfloat >> bin_value;
352 
353  if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" || xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram")
354  {
355  HostSlotMap[host_slot]->Histogram1D->setBinContent(iwc-1, bin_value/*atoi(s.c_str())*/);
356  }
357  else
358  {
359  HostSlotMap[host_slot]->Histogram1D->Fill(bin_value);
360  }
361 
362  if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" && iwc >= nbins/*WCBIN*/)
363  break;
364 
365  if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram" && iwc >= nbins /*BXBIN*/)
366  break;
367  }
368 
369  }
370  }
371  }
372 
373 
375 
376  std::cout << "after poping from the data Queue...."<< std::endl;
377 
378  if(ref_table !=NULL)
379  {
380  ref_table->~Table();
381  }
382 
383  //std::cout << "after calling xdata::Table::Reference destructor...."<< std::endl;
384 
385  delete ref_table ;
386 
387  //std::cout << "after call of delete...."<< std::endl;
388 
389 
390  /*end = time(NULL);
391 
392  std::cout << "time called = " << times_called << " time in seconds needed = " << (end - start) << std::endl;*/
393 
394  //cout << "DQMSourceExample::analyze before BSem_.give()" << endl;
395 
396  //signal that a new element has been inserted
397  pthread_cond_signal(&xmas2dqm::wse::ToDqm::instance()->less_);
398 
399  //std::cout << "after signaligng less...." << std::endl;
400 
401  //allow access to the queue
402  pthread_mutex_unlock(&xmas2dqm::wse::ToDqm::instance()->LASmutex_);
403 
404  std::cout << "after unlocking the mutex...." << std::endl;
405  //xmas2dqm::wse::ToDqm::instance()->BSem_.give();
406 
407 
408 
409  counterEvt_++;
410  if (prescaleEvt_ > 0 && counterEvt_%prescaleEvt_!=0) return;
411  // cout << " processing conterEvt_: " << counterEvt_ <<endl;
412 
413  /*if(counterEvt_%100 == 0)
414  {
415  cout << " # of events = " << counterEvt_ << endl;
416  dbe_->save("/tmp/thehisto.root","/wse");
417  }*/
418 
419  //std::cout << "returning from XmasToDQMSource::analyze...." << std::endl;
420  //usleep(100);
421  //sleep(1000);
422 
423 }
xdata::Bag< xmas2dqm::wse::FlashlistElements > flashlistMonitor_
Definition: ToDqm.h:67
int i
Definition: DBlmapReader.cc:9
std::map< std::string, struct Data * > HostSlotMap
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:519
boost::tokenizer< boost::char_separator< char > > tokenizer
#define NULL
Definition: scimark2.h:8
xdata::String runNumber_
Definition: ToDqm.h:61
static ToDqm * instance()
Definition: ToDqm.cc:6
std::string monitorName_
int prescaleEvt_
counter
std::queue< xdata::Table * > MemoryTable_
Definition: ToDqm.h:65
tuple cout
Definition: gather_cfg.py:41
string s
Definition: asciidump.py:422
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:237
void XmasToDQMSource::beginJob ( void  )
protectedvirtual

BeginJob.

Reimplemented from edm::EDAnalyzer.

Definition at line 78 of file XmasToDQMSource.cc.

78  {
79 
80 }
void XmasToDQMSource::beginLuminosityBlock ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup context 
)
protectedvirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 88 of file XmasToDQMSource.cc.

89  {
90 
91 }
void XmasToDQMSource::beginRun ( const edm::Run r,
const edm::EventSetup c 
)
protectedvirtual

BeginRun.

Reimplemented from edm::EDAnalyzer.

Definition at line 83 of file XmasToDQMSource.cc.

83  {
84 
85 }
void XmasToDQMSource::endJob ( void  )
protectedvirtual

Endjob.

Reimplemented from edm::EDAnalyzer.

Definition at line 440 of file XmasToDQMSource.cc.

440  {
441 }
void XmasToDQMSource::endLuminosityBlock ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup c 
)
protectedvirtual

DQM Client Diagnostic.

Reimplemented from edm::EDAnalyzer.

Definition at line 429 of file XmasToDQMSource.cc.

430  {
431 }
void XmasToDQMSource::endRun ( const edm::Run r,
const edm::EventSetup c 
)
protectedvirtual

EndRun.

Reimplemented from edm::EDAnalyzer.

Definition at line 433 of file XmasToDQMSource.cc.

433  {
434 
435 
436  //dbe_->setCurrentFolder(/*monitorName_+*/"wse");
437 
438 }

Member Data Documentation

int XmasToDQMSource::counterEvt_
private

Definition at line 70 of file XmasToDQMSource.h.

Referenced by analyze().

DQMStore* XmasToDQMSource::dbe_
private

Definition at line 68 of file XmasToDQMSource.h.

Referenced by analyze(), and XmasToDQMSource().

MonitorElement* XmasToDQMSource::h1
private

every n events FIXME, make prescale module?

Definition at line 76 of file XmasToDQMSource.h.

std::map<std::string, struct Data * > XmasToDQMSource::HostSlotMap
private

Definition at line 82 of file XmasToDQMSource.h.

Referenced by analyze().

std::string XmasToDQMSource::monitorName_
private

Definition at line 69 of file XmasToDQMSource.h.

Referenced by analyze(), and XmasToDQMSource().

std::string XmasToDQMSource::NBINS
private

Definition at line 85 of file XmasToDQMSource.h.

edm::ParameterSet XmasToDQMSource::parameters_
private
int XmasToDQMSource::prescaleEvt_
private

counter

Definition at line 71 of file XmasToDQMSource.h.

Referenced by analyze(), and XmasToDQMSource().

std::string XmasToDQMSource::previousTimestamp
private

Definition at line 84 of file XmasToDQMSource.h.

std::string XmasToDQMSource::XMAX
private

Definition at line 87 of file XmasToDQMSource.h.

std::string XmasToDQMSource::XMIN
private

Definition at line 86 of file XmasToDQMSource.h.