#include <DQMServices/XdaqCollector/interface/XmasToDQMSource.h>
Public Member Functions | |
XmasToDQMSource (const edm::ParameterSet &) | |
~XmasToDQMSource () | |
Protected Member Functions | |
void | analyze (const edm::Event &e, const edm::EventSetup &c) |
Fake Analyze. | |
void | beginJob (const edm::EventSetup &c) |
BeginJob. | |
void | beginLuminosityBlock (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) |
void | beginRun (const edm::Run &r, const edm::EventSetup &c) |
BeginRun. | |
void | endJob () |
Endjob. | |
void | endLuminosityBlock (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) |
DQM Client Diagnostic. | |
void | endRun (const edm::Run &r, const edm::EventSetup &c) |
EndRun. | |
Private Attributes | |
int | counterEvt_ |
DQMStore * | dbe_ |
MonitorElement * | h1 |
every n events FIXME, make prescale module? | |
std::map< std::string, struct Data * > | HostSlotMap |
std::string | monitorName_ |
std::string | NBINS |
edm::ParameterSet | parameters_ |
int | prescaleEvt_ |
counter | |
std::string | previousTimestamp |
std::string | XMAX |
std::string | XMIN |
Definition at line 35 of file XmasToDQMSource.h.
XmasToDQMSource::XmasToDQMSource | ( | const edm::ParameterSet & | ps | ) |
book some histograms here
Definition at line 36 of file XmasToDQMSource.cc.
References GenMuonPlsPt100GeV_cfg::cout, dbe_, lat::endl(), edm::ParameterSet::getUntrackedParameter(), monitorName_, parameters_, and prescaleEvt_.
00036 : 00037 counterEvt_(0) 00038 { 00039 cout << "Constructor of XmasToDQMSource called...." << endl; 00040 00041 dbe_ = Service<DQMStore>().operator->(); 00042 parameters_ = ps; 00043 monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","DAQ"); 00044 00045 cout << "Monitor name = " << monitorName_ << endl; 00046 if (monitorName_ != "" ) 00047 monitorName_ = monitorName_+"/" ; 00048 00049 prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1); 00050 cout << "===> DQM event prescale = " << prescaleEvt_ << " events "<< endl; 00051 00052 00054 //const int NBINS = 50; XMIN = 0; XMAX = 20000; 00055 00056 // create and cd into new folder 00057 //dbe_->setCurrentFolder(/*monitorName_+*/"wse"); 00058 //h1 = dbe_->book1D("histo", "Example 1D histogram.", NBINS, XMIN, XMAX); 00059 //h1->setAxisTitle("x-axis title", 1); 00060 //h1->setAxisTitle("y-axis title", 2); 00061 00062 // assign tag to MEs h1, h2 and h7 00063 //const unsigned int detector_id = 17; 00064 //dbe_->tag(h1, detector_id); 00065 }
XmasToDQMSource::~XmasToDQMSource | ( | ) |
Definition at line 68 of file XmasToDQMSource.cc.
00069 { 00070 00071 // do anything here that needs to be done at desctruction time 00072 // (e.g. close files, deallocate resources etc.) 00073 00074 }
void XmasToDQMSource::analyze | ( | const edm::Event & | e, | |
const edm::EventSetup & | c | |||
) | [protected, virtual] |
Fake Analyze.
Implements edm::EDAnalyzer.
Definition at line 94 of file XmasToDQMSource.cc.
References DQMStore::book1D(), counterEvt_, GenMuonPlsPt100GeV_cfg::cout, dbe_, lat::endl(), HostSlotMap, i, xmas2dqm::wse::ToDqm::instance(), less_, monitorName_, NULL, prescaleEvt_, r, row, s, and DQMStore::setCurrentFolder().
00096 { 00097 /*time_t start,end; 00098 static int times_called=0; 00099 00100 times_called++;*/ 00101 00102 00103 //std::cout << "inside Analyze.... " << std::endl; 00104 00105 std::map<std::string, std::string, std::less<std::string> >::iterator i; 00106 00107 //cout << "DQMSourceExample::analyze before BSem_.takeO()" << endl; 00108 00109 //xmas2dqm::wse::ToDqm::instance()->BSem_.take(); 00110 00111 std::cout << "inside DQMSource::Analyze...ready to lock the data mutex" << std::endl; 00112 //protect access to the queue 00113 pthread_mutex_lock(&xmas2dqm::wse::ToDqm::instance()->LASmutex_); 00114 00115 00116 std::cout << "inside DQMSource::Analyze...check (...and possible wait) if data queue is empty" << std::endl; 00117 00118 //check if the queue is empty and wait (a signal that informs that an element has been pushed) 00119 while(xmas2dqm::wse::ToDqm::instance()->/*QTable_*/MemoryTable_.size() <= 0) 00120 { 00121 pthread_cond_wait(&xmas2dqm::wse::ToDqm::instance()->more_, &xmas2dqm::wse::ToDqm::instance()->LASmutex_); 00122 } 00123 00124 00125 std::cout << "inside DQMSource::Analyze...data queue has elements...proceeding..." << std::endl; 00126 00127 //start = time(NULL); 00128 00129 //xdata::Table::Reference ref_table; 00130 xdata::Table *ref_table = NULL; 00131 00132 00133 if(xmas2dqm::wse::ToDqm::instance()->/*QTable_*/MemoryTable_.size() > 0) 00134 { 00135 //cout << " DQMSourceExample::analyze : Queue size > 0 " << xmas2dqm::wse::ToDqm::instance()->QTable_.size() << endl; 00136 00137 //pop an element from the queue of the LAS data 00138 ref_table = xmas2dqm::wse::ToDqm::instance()->/*QTable_*/ MemoryTable_.front(); 00139 //xmas2dqm::wse::ToDqm::instance()->QTable_.pop(); 00140 00141 } 00142 00143 //Insert data to histograms transfered to DQM GUI servers (print the table) 00144 if(ref_table != NULL) 00145 { 00146 size_t row = ref_table->getRowCount(); 00147 00148 00149 for ( size_t r = 0; r < ref_table->numberOfRows_; r++ ) 00150 { 00151 00152 //check if the flashlist contains the element we want to monitor 00153 if(!ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element]) 00154 { 00155 break; 00156 } 00157 00158 /* remove prints for benchmarking*/ 00159 /* 00160 std::cout << "********* Printing table inside DQMSourceExample ***************" << std::endl; 00161 std:: cout << ref_table->columnData_["context"]->elementAt(r)->toString() << std::endl; 00162 std:: cout << ref_table->columnData_["slotNumber"]->elementAt(r)->toString() << std::endl;*/ 00163 00164 //if(ref_table->columnData_["wcHistogram"]->elementAt(r)->toString() == "[]") 00165 if(ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()]->elementAt(r)->toString() == "[]") 00166 { 00167 /* remove prints for benchmarking*/ 00168 /*std::cout << ref_table->columnData_["context"]->elementAt(r)->toString() << " has empty bxHistogram" << std::endl;*/ 00169 continue; 00170 } 00171 00172 00173 //check if there is a column runNumber in the LAS table 00174 if(ref_table->columnData_["runNumber"]) 00175 { 00176 /* remove prints for benchmarking*/ 00177 00178 00179 //xmas2dqm::wse::ToDqm::instance()->BSem_.take(); 00180 00181 //if runNumber in LAS record different than currnet runNumber go to next LAS record 00182 if (xmas2dqm::wse::ToDqm::instance()->runNumber_.toString() != ref_table->columnData_["runNumber"]->elementAt(r)->toString()) 00183 { 00184 continue; 00185 } 00186 00187 00188 //xmas2dqm::wse::ToDqm::instance()->BSem_.give(); 00189 //std::cout << "runNumber ... = " << ref_table->columnData_["runNumber"]->elementAt(r)->toString() << std::endl; 00190 } 00191 00192 //boost::tokenizer<> Context_tokens(ref_table->columnData_["Context"]->elementAt(r)->toString()); 00193 00194 boost::char_separator<char> sep(":/."); 00195 tokenizer Context_tokens(ref_table->columnData_["Context"]->elementAt(r)->toString(), sep); 00196 00197 00198 //check if the combination Host + slotNumber exists already in the set of hosts + slotNumbers 00199 //if not book a new histogram with correspondent name and push data, else push data to existent histogram 00200 //std::string host_slot = *(++Context_tokens.begin()) + "_" + ref_table->columnData_["slotNumber"]->elementAt(r)->toString(); 00201 00202 std::string host_slot; 00203 host_slot = *(++ Context_tokens.begin()); 00204 00205 //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 00206 //useful mostly for bxHistogram, wcHistogram of frlHisto, where the histograms (flashlist elements) refer to host+slot 00207 if(ref_table->columnData_["slotNumber"]) 00208 { 00209 //host_slot = *(++ Context_tokens.begin()) + "-" + *(++ ++ Context_tokens.begin()) + "-" + *(++ ++ ++Context_tokens.begin()) + "_" + ref_table->columnData_["slotNumber"]->elementAt(r)->toString(); 00210 host_slot = host_slot + "_" + ref_table->columnData_["slotNumber"]->elementAt(r)->toString(); 00211 } 00212 00213 //host_slot = host_slot + "_" + ref_table->columnData_["slotNumber"]->elementAt(r)->toString(); 00214 00215 00216 //check if there is no entry in the map for this host (+slot in case of wcHistogram, bxHistogram) 00217 if( HostSlotMap.find(host_slot) == HostSlotMap.end()) 00218 { 00219 /* remove prints for benchmarking*/ 00220 std::cout << "booking new histogram..." << host_slot << std::endl; 00221 00222 HostSlotMap[host_slot] = new /*struct*/ Data(); 00223 00224 00225 HostSlotMap[host_slot]->lastTimestamp = ref_table->columnData_["timestamp"]->elementAt(r)->toString(); 00226 00227 // create and cd into new folder 00228 //dbe_->setCurrentFolder(monitorName_ + "wcHisto"); 00229 dbe_->setCurrentFolder(monitorName_ + xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()); 00230 00231 //the wcHistogramResolution equals the value of the register Histogram of the FRL, not the value of the bytes resolution for the bin 00232 // the value of the register multiplied by 16 gives the byte resolution - range of a wcHistogram bin 00233 // if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram") 00234 // { 00235 // HostSlotMap[host_slot]->Histogram1D = dbe_->book1D("wc_"+ host_slot, "FRL wcHisto", WCBIN, 00236 // MIN_EVENT_FRAGMENT_SIZE, MIN_EVENT_FRAGMENT_SIZE + WCBIN*16*atoi(ref_table->columnData_["wcHistogramResolution"]->elementAt(r)->toString().c_str())); 00237 // HostSlotMap[host_slot]->Histogram1D->setAxisTitle("Event fragment size (Bytes)"/*"x-axis title"*/, 1); 00238 // HostSlotMap[host_slot]->Histogram1D->setAxisTitle("Events"/*"y-axis title"*/, 2); 00239 // } 00240 // else if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram") 00241 // { 00242 // HostSlotMap[host_slot]->Histogram1D = dbe_->book1D("bx_"+ host_slot, "FRL bxHisto", BXBIN, 1, BXBIN); 00243 // 00244 // HostSlotMap[host_slot]->Histogram1D->setAxisTitle("LHC orbit Bunch"/*"x-axis title"*/, 1); 00245 // HostSlotMap[host_slot]->Histogram1D->setAxisTitle("Events"/*"y-axis title"*/, 2); 00246 // } 00247 00248 std::istringstream str2num; 00249 int nbins; 00250 double xmin,xmax; 00251 00252 str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.bins.toString()); 00253 str2num >> nbins; // now stream is in end of file state 00254 str2num.clear(); // clear end of file state 00255 00256 str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xmin.toString()); 00257 str2num >> xmin; // now stream is in end of file state 00258 str2num.clear(); // clear end of file state 00259 00260 str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xmax.toString()); 00261 str2num >> xmax; // now stream is in end of file state 00262 str2num.clear(); // clear end of file state 00263 00264 HostSlotMap[host_slot]->Histogram1D = dbe_->book1D(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() + "_" + host_slot, "", nbins, xmin, xmax); 00265 HostSlotMap[host_slot]->Histogram1D->setAxisTitle(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xtitle.toString()/*"x-axis title"*/, 1); 00266 HostSlotMap[host_slot]->Histogram1D->setAxisTitle(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.ytitle.toString()/*"y-axis title"*/, 2); 00267 00268 00269 /* remove prints for benchmarking*/ 00270 /*std::cout << "booked histogram = " << host_slot << std::endl;*/ 00271 00272 00273 boost::char_separator<char> histo_sep("[,]"); 00274 tokenizer Histogram_values(ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()]->elementAt(r)->toString(), histo_sep); 00275 00276 int iwc=0; //bin counter 00277 00278 for(tokenizer::iterator itok=Histogram_values.begin(); itok!=Histogram_values.end();++itok) 00279 { 00280 iwc++; 00281 //remove for benchmarking 00282 //std::cout << "iwc = "<< iwc << " *itok = " << *itok << std::endl; 00283 string s = *itok; 00284 //std::cout << "iwc = "<< iwc << " s = " << s << std::endl; 00285 //HostSlotMap[host_slot]->Fill(atoi(s.c_str())); 00286 00287 std::istringstream istrfloat(s); 00288 float bin_value; 00289 istrfloat >> bin_value; 00290 00291 //std::cout << "iwc = "<< iwc << " bin_value = " << bin_value << std::endl; 00292 00293 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" || xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram") 00294 { 00295 HostSlotMap[host_slot]->Histogram1D->setBinContent(iwc-1, bin_value/*atoi(s.c_str())*/); 00296 } 00297 else 00298 { 00299 HostSlotMap[host_slot]->Histogram1D->Fill(bin_value); 00300 } 00301 00302 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" && iwc >= nbins /*WCBIN*/) 00303 break; 00304 00305 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram" && iwc >= nbins /*BXBIN*/) 00306 break; 00307 } 00308 00309 00310 } 00311 else 00312 { 00313 00314 std::istringstream str2num; 00315 int nbins; 00316 00317 str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.bins.toString()); 00318 str2num >> nbins; // now stream is in end of file state 00319 str2num.clear(); // clear end of file state 00320 00321 00322 //check if the timestamp has changed and proceed adding data only if timestamp has changed 00323 if(HostSlotMap[host_slot]->lastTimestamp == ref_table->columnData_["timestamp"]->elementAt(r)->toString()) 00324 { 00325 //std::cout << host_slot << " same timestamp found..." << std::endl; 00326 continue; 00327 } 00328 else 00329 { 00330 //std::cout << host_slot << " different timestamp found..." << std::endl; 00331 HostSlotMap[host_slot]->lastTimestamp == ref_table->columnData_["timestamp"]->elementAt(r)->toString(); 00332 } 00333 00334 00335 00336 //insert wcHistogram values 00337 boost::char_separator<char> histo_sep("[,]"); 00338 tokenizer Histogram_values(ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()]->elementAt(r)->toString(), histo_sep); 00339 00340 int iwc=0; //bin counter 00341 00342 for(tokenizer::iterator itok=Histogram_values.begin(); itok!=Histogram_values.end();++itok) 00343 { 00344 iwc++; 00345 //remove for benchmarking 00346 //std::cout << "fill booked histogram iwc = "<< iwc << " *itok = " << *itok << std::endl; 00347 00348 string s = *itok; 00349 //HostSlotMap[host_slot]->Fill(atoi(s.c_str())); 00350 00351 std::istringstream istrfloat(s); 00352 float bin_value; 00353 istrfloat >> bin_value; 00354 00355 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" || xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram") 00356 { 00357 HostSlotMap[host_slot]->Histogram1D->setBinContent(iwc-1, bin_value/*atoi(s.c_str())*/); 00358 } 00359 else 00360 { 00361 HostSlotMap[host_slot]->Histogram1D->Fill(bin_value); 00362 } 00363 00364 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" && iwc >= nbins/*WCBIN*/) 00365 break; 00366 00367 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram" && iwc >= nbins /*BXBIN*/) 00368 break; 00369 } 00370 00371 } 00372 } 00373 } 00374 00375 00376 xmas2dqm::wse::ToDqm::instance()->MemoryTable_.pop(); 00377 00378 std::cout << "after poping from the data Queue...."<< std::endl; 00379 00380 if(ref_table !=NULL) 00381 { 00382 ref_table->~Table(); 00383 } 00384 00385 //std::cout << "after calling xdata::Table::Reference destructor...."<< std::endl; 00386 00387 delete ref_table ; 00388 00389 //std::cout << "after call of delete...."<< std::endl; 00390 00391 00392 /*end = time(NULL); 00393 00394 std::cout << "time called = " << times_called << " time in seconds needed = " << (end - start) << std::endl;*/ 00395 00396 //cout << "DQMSourceExample::analyze before BSem_.give()" << endl; 00397 00398 //signal that a new element has been inserted 00399 pthread_cond_signal(&xmas2dqm::wse::ToDqm::instance()->less_); 00400 00401 //std::cout << "after signaligng less...." << std::endl; 00402 00403 //allow access to the queue 00404 pthread_mutex_unlock(&xmas2dqm::wse::ToDqm::instance()->LASmutex_); 00405 00406 std::cout << "after unlocking the mutex...." << std::endl; 00407 //xmas2dqm::wse::ToDqm::instance()->BSem_.give(); 00408 00409 00410 00411 counterEvt_++; 00412 if (prescaleEvt_ > 0 && counterEvt_%prescaleEvt_!=0) return; 00413 // cout << " processing conterEvt_: " << counterEvt_ <<endl; 00414 00415 /*if(counterEvt_%100 == 0) 00416 { 00417 cout << " # of events = " << counterEvt_ << endl; 00418 dbe_->save("/tmp/thehisto.root","/wse"); 00419 }*/ 00420 00421 //std::cout << "returning from XmasToDQMSource::analyze...." << std::endl; 00422 //usleep(100); 00423 //sleep(1000); 00424 00425 }
void XmasToDQMSource::beginJob | ( | const edm::EventSetup & | c | ) | [protected, virtual] |
void XmasToDQMSource::beginLuminosityBlock | ( | const edm::LuminosityBlock & | lumiSeg, | |
const edm::EventSetup & | context | |||
) | [protected, virtual] |
void XmasToDQMSource::beginRun | ( | const edm::Run & | r, | |
const edm::EventSetup & | c | |||
) | [protected, virtual] |
void XmasToDQMSource::endLuminosityBlock | ( | const edm::LuminosityBlock & | lumiSeg, | |
const edm::EventSetup & | c | |||
) | [protected, virtual] |
DQM Client Diagnostic.
Reimplemented from edm::EDAnalyzer.
Definition at line 431 of file XmasToDQMSource.cc.
void XmasToDQMSource::endRun | ( | const edm::Run & | r, | |
const edm::EventSetup & | c | |||
) | [protected, virtual] |
int XmasToDQMSource::counterEvt_ [private] |
DQMStore* XmasToDQMSource::dbe_ [private] |
MonitorElement* XmasToDQMSource::h1 [private] |
std::map<std::string, struct Data * > XmasToDQMSource::HostSlotMap [private] |
std::string XmasToDQMSource::monitorName_ [private] |
std::string XmasToDQMSource::NBINS [private] |
Definition at line 85 of file XmasToDQMSource.h.
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.