Go to the documentation of this file.00001
00002
00003
00004 #include "DQMServices/XdaqCollector/interface/XmasToDQMSource.h"
00005
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007
00008 #include "TRandom.h"
00009 #include <math.h>
00010
00011 #include <boost/tokenizer.hpp>
00012
00013 #include <sstream>
00014
00015 #include <time.h>
00016
00017
00018
00019 using namespace std;
00020 using namespace edm;
00021
00022
00023 #define BXBIN 3564
00024 #define WCBIN 257
00025
00026
00027 #define MIN_EVENT_FRAGMENT_SIZE 16
00028
00029
00030 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
00031
00032
00033
00034
00035
00036 XmasToDQMSource::XmasToDQMSource( const edm::ParameterSet& ps ) :
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
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 }
00066
00067
00068 XmasToDQMSource::~XmasToDQMSource()
00069 {
00070
00071
00072
00073
00074 }
00075
00076
00077
00078 void XmasToDQMSource::beginJob(){
00079
00080 }
00081
00082
00083 void XmasToDQMSource::beginRun(const edm::Run& r, const EventSetup& context) {
00084
00085 }
00086
00087
00088 void XmasToDQMSource::beginLuminosityBlock(const LuminosityBlock& lumiSeg,
00089 const EventSetup& context) {
00090
00091 }
00092
00093
00094 void XmasToDQMSource::analyze(const Event& iEvent,
00095 const EventSetup& iSetup )
00096 {
00097
00098
00099
00100
00101
00102
00103
00104
00105 std::map<std::string, std::string, std::less<std::string> >::iterator i;
00106
00107
00108
00109
00110
00111 std::cout << "inside DQMSource::Analyze...ready to lock the data mutex" << std::endl;
00112
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
00119 while(xmas2dqm::wse::ToDqm::instance()->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
00128
00129
00130 xdata::Table *ref_table = NULL;
00131
00132
00133 if(xmas2dqm::wse::ToDqm::instance()->MemoryTable_.size() > 0)
00134 {
00135
00136
00137
00138 ref_table = xmas2dqm::wse::ToDqm::instance()-> MemoryTable_.front();
00139
00140
00141 }
00142
00143
00144 if(ref_table != NULL)
00145 {
00146
00147 for ( size_t r = 0; r < ref_table->numberOfRows_; r++ )
00148 {
00149
00150
00151 if(!ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element])
00152 {
00153 break;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163 if(ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()]->elementAt(r)->toString() == "[]")
00164 {
00165
00166
00167 continue;
00168 }
00169
00170
00171
00172 if(ref_table->columnData_["runNumber"])
00173 {
00174
00175
00176
00177
00178
00179
00180 if (xmas2dqm::wse::ToDqm::instance()->runNumber_.toString() != ref_table->columnData_["runNumber"]->elementAt(r)->toString())
00181 {
00182 continue;
00183 }
00184
00185
00186
00187
00188 }
00189
00190
00191
00192 boost::char_separator<char> sep(":/.");
00193 tokenizer Context_tokens(ref_table->columnData_["Context"]->elementAt(r)->toString(), sep);
00194
00195
00196
00197
00198
00199
00200 std::string host_slot;
00201 host_slot = *(++ Context_tokens.begin());
00202
00203
00204
00205 if(ref_table->columnData_["slotNumber"])
00206 {
00207
00208 host_slot = host_slot + "_" + ref_table->columnData_["slotNumber"]->elementAt(r)->toString();
00209 }
00210
00211
00212
00213
00214
00215 if( HostSlotMap.find(host_slot) == HostSlotMap.end())
00216 {
00217
00218 std::cout << "booking new histogram..." << host_slot << std::endl;
00219
00220 HostSlotMap[host_slot] = new Data();
00221
00222
00223 HostSlotMap[host_slot]->lastTimestamp = ref_table->columnData_["timestamp"]->elementAt(r)->toString();
00224
00225
00226
00227 dbe_->setCurrentFolder(monitorName_ + xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString());
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 std::istringstream str2num;
00247 int nbins;
00248 double xmin,xmax;
00249
00250 str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.bins.toString());
00251 str2num >> nbins;
00252 str2num.clear();
00253
00254 str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xmin.toString());
00255 str2num >> xmin;
00256 str2num.clear();
00257
00258 str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xmax.toString());
00259 str2num >> xmax;
00260 str2num.clear();
00261
00262 HostSlotMap[host_slot]->Histogram1D = dbe_->book1D(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() + "_" + host_slot, "", nbins, xmin, xmax);
00263 HostSlotMap[host_slot]->Histogram1D->setAxisTitle(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xtitle.toString(), 1);
00264 HostSlotMap[host_slot]->Histogram1D->setAxisTitle(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.ytitle.toString(), 2);
00265
00266
00267
00268
00269
00270
00271 boost::char_separator<char> histo_sep("[,]");
00272 tokenizer Histogram_values(ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()]->elementAt(r)->toString(), histo_sep);
00273
00274 int iwc=0;
00275
00276 for(tokenizer::iterator itok=Histogram_values.begin(); itok!=Histogram_values.end();++itok)
00277 {
00278 iwc++;
00279
00280
00281 string s = *itok;
00282
00283
00284
00285 std::istringstream istrfloat(s);
00286 float bin_value;
00287 istrfloat >> bin_value;
00288
00289
00290
00291 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" || xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram")
00292 {
00293 HostSlotMap[host_slot]->Histogram1D->setBinContent(iwc-1, bin_value);
00294 }
00295 else
00296 {
00297 HostSlotMap[host_slot]->Histogram1D->Fill(bin_value);
00298 }
00299
00300 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" && iwc >= nbins )
00301 break;
00302
00303 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram" && iwc >= nbins )
00304 break;
00305 }
00306
00307
00308 }
00309 else
00310 {
00311
00312 std::istringstream str2num;
00313 int nbins;
00314
00315 str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.bins.toString());
00316 str2num >> nbins;
00317 str2num.clear();
00318
00319
00320
00321 if(HostSlotMap[host_slot]->lastTimestamp == ref_table->columnData_["timestamp"]->elementAt(r)->toString())
00322 {
00323
00324 continue;
00325 }
00326 else
00327 {
00328
00329 HostSlotMap[host_slot]->lastTimestamp == ref_table->columnData_["timestamp"]->elementAt(r)->toString();
00330 }
00331
00332
00333
00334
00335 boost::char_separator<char> histo_sep("[,]");
00336 tokenizer Histogram_values(ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()]->elementAt(r)->toString(), histo_sep);
00337
00338 int iwc=0;
00339
00340 for(tokenizer::iterator itok=Histogram_values.begin(); itok!=Histogram_values.end();++itok)
00341 {
00342 iwc++;
00343
00344
00345
00346 string s = *itok;
00347
00348
00349 std::istringstream istrfloat(s);
00350 float bin_value;
00351 istrfloat >> bin_value;
00352
00353 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" || xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram")
00354 {
00355 HostSlotMap[host_slot]->Histogram1D->setBinContent(iwc-1, bin_value);
00356 }
00357 else
00358 {
00359 HostSlotMap[host_slot]->Histogram1D->Fill(bin_value);
00360 }
00361
00362 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "wcHistogram" && iwc >= nbins)
00363 break;
00364
00365 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram" && iwc >= nbins )
00366 break;
00367 }
00368
00369 }
00370 }
00371 }
00372
00373
00374 xmas2dqm::wse::ToDqm::instance()->MemoryTable_.pop();
00375
00376 std::cout << "after poping from the data Queue...."<< std::endl;
00377
00378 if(ref_table !=NULL)
00379 {
00380 ref_table->~Table();
00381 }
00382
00383
00384
00385 delete ref_table ;
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 pthread_cond_signal(&xmas2dqm::wse::ToDqm::instance()->less_);
00398
00399
00400
00401
00402 pthread_mutex_unlock(&xmas2dqm::wse::ToDqm::instance()->LASmutex_);
00403
00404 std::cout << "after unlocking the mutex...." << std::endl;
00405
00406
00407
00408
00409 counterEvt_++;
00410 if (prescaleEvt_ > 0 && counterEvt_%prescaleEvt_!=0) return;
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423 }
00424
00425
00426
00427
00428
00429 void XmasToDQMSource::endLuminosityBlock(const LuminosityBlock& lumiSeg,
00430 const EventSetup& context) {
00431 }
00432
00433 void XmasToDQMSource::endRun(const Run& r, const EventSetup& context){
00434
00435
00436
00437
00438 }
00439
00440 void XmasToDQMSource::endJob(){
00441 }
00442
00443