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(const EventSetup& context){
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 size_t row = ref_table->getRowCount();
00147
00148
00149 for ( size_t r = 0; r < ref_table->numberOfRows_; r++ )
00150 {
00151
00152
00153 if(!ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element])
00154 {
00155 break;
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165 if(ref_table->columnData_[xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString()]->elementAt(r)->toString() == "[]")
00166 {
00167
00168
00169 continue;
00170 }
00171
00172
00173
00174 if(ref_table->columnData_["runNumber"])
00175 {
00176
00177
00178
00179
00180
00181
00182 if (xmas2dqm::wse::ToDqm::instance()->runNumber_.toString() != ref_table->columnData_["runNumber"]->elementAt(r)->toString())
00183 {
00184 continue;
00185 }
00186
00187
00188
00189
00190 }
00191
00192
00193
00194 boost::char_separator<char> sep(":/.");
00195 tokenizer Context_tokens(ref_table->columnData_["Context"]->elementAt(r)->toString(), sep);
00196
00197
00198
00199
00200
00201
00202 std::string host_slot;
00203 host_slot = *(++ Context_tokens.begin());
00204
00205
00206
00207 if(ref_table->columnData_["slotNumber"])
00208 {
00209
00210 host_slot = host_slot + "_" + ref_table->columnData_["slotNumber"]->elementAt(r)->toString();
00211 }
00212
00213
00214
00215
00216
00217 if( HostSlotMap.find(host_slot) == HostSlotMap.end())
00218 {
00219
00220 std::cout << "booking new histogram..." << host_slot << std::endl;
00221
00222 HostSlotMap[host_slot] = new Data();
00223
00224
00225 HostSlotMap[host_slot]->lastTimestamp = ref_table->columnData_["timestamp"]->elementAt(r)->toString();
00226
00227
00228
00229 dbe_->setCurrentFolder(monitorName_ + xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString());
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
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;
00254 str2num.clear();
00255
00256 str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xmin.toString());
00257 str2num >> xmin;
00258 str2num.clear();
00259
00260 str2num.str(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xmax.toString());
00261 str2num >> xmax;
00262 str2num.clear();
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(), 1);
00266 HostSlotMap[host_slot]->Histogram1D->setAxisTitle(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.ytitle.toString(), 2);
00267
00268
00269
00270
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;
00277
00278 for(tokenizer::iterator itok=Histogram_values.begin(); itok!=Histogram_values.end();++itok)
00279 {
00280 iwc++;
00281
00282
00283 string s = *itok;
00284
00285
00286
00287 std::istringstream istrfloat(s);
00288 float bin_value;
00289 istrfloat >> bin_value;
00290
00291
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);
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 )
00303 break;
00304
00305 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram" && iwc >= nbins )
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;
00319 str2num.clear();
00320
00321
00322
00323 if(HostSlotMap[host_slot]->lastTimestamp == ref_table->columnData_["timestamp"]->elementAt(r)->toString())
00324 {
00325
00326 continue;
00327 }
00328 else
00329 {
00330
00331 HostSlotMap[host_slot]->lastTimestamp == ref_table->columnData_["timestamp"]->elementAt(r)->toString();
00332 }
00333
00334
00335
00336
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;
00341
00342 for(tokenizer::iterator itok=Histogram_values.begin(); itok!=Histogram_values.end();++itok)
00343 {
00344 iwc++;
00345
00346
00347
00348 string s = *itok;
00349
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);
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)
00365 break;
00366
00367 if(xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString() == "bxHistogram" && iwc >= nbins )
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
00386
00387 delete ref_table ;
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 pthread_cond_signal(&xmas2dqm::wse::ToDqm::instance()->less_);
00400
00401
00402
00403
00404 pthread_mutex_unlock(&xmas2dqm::wse::ToDqm::instance()->LASmutex_);
00405
00406 std::cout << "after unlocking the mutex...." << std::endl;
00407
00408
00409
00410
00411 counterEvt_++;
00412 if (prescaleEvt_ > 0 && counterEvt_%prescaleEvt_!=0) return;
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 }
00426
00427
00428
00429
00430
00431 void XmasToDQMSource::endLuminosityBlock(const LuminosityBlock& lumiSeg,
00432 const EventSetup& context) {
00433 }
00434
00435 void XmasToDQMSource::endRun(const Run& r, const EventSetup& context){
00436
00437
00438
00439
00440 }
00441
00442 void XmasToDQMSource::endJob(){
00443 }
00444
00445