00001
00010 #include "DQMServices/Components/plugins/EDMtoMEConverter.h"
00011
00012 EDMtoMEConverter::EDMtoMEConverter(const edm::ParameterSet & iPSet) :
00013 verbosity(0), frequency(0)
00014 {
00015 std::string MsgLoggerCat = "EDMtoMEConverter_EDMtoMEConverter";
00016
00017
00018 name = iPSet.getUntrackedParameter<std::string>("Name");
00019 verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
00020 frequency = iPSet.getUntrackedParameter<int>("Frequency");
00021
00022 convertOnEndLumi = iPSet.getUntrackedParameter<bool>("convertOnEndLumi",false);
00023 convertOnEndRun = iPSet.getUntrackedParameter<bool>("convertOnEndRun",false);
00024
00025 prescaleFactor = iPSet.getUntrackedParameter<int>("prescaleFactor", 1);
00026
00027
00028 releaseTag = false;
00029
00030
00031
00032 verbosity %= 10;
00033
00034
00035 dbe = 0;
00036 dbe = edm::Service<DQMStore>().operator->();
00037 if (dbe) {
00038 if (verbosity) {
00039 dbe->setVerbose(1);
00040 } else {
00041 dbe->setVerbose(0);
00042 }
00043 }
00044
00045
00046 if (verbosity >= 0) {
00047 edm::LogInfo(MsgLoggerCat)
00048 << "\n===============================\n"
00049 << "Initialized as EDAnalyzer with parameter values:\n"
00050 << " Name = " << name << "\n"
00051 << " Verbosity = " << verbosity << "\n"
00052 << " Frequency = " << frequency << "\n"
00053 << "===============================\n";
00054 }
00055
00056 classtypes.clear();
00057 classtypes.push_back("TH1F");
00058 classtypes.push_back("TH1S");
00059 classtypes.push_back("TH2F");
00060 classtypes.push_back("TH2S");
00061 classtypes.push_back("TH3F");
00062 classtypes.push_back("TProfile");
00063 classtypes.push_back("TProfile2D");
00064 classtypes.push_back("Float");
00065 classtypes.push_back("Int");
00066 classtypes.push_back("String");
00067
00068 count.clear();
00069 countf = 0;
00070
00071 }
00072
00073 EDMtoMEConverter::~EDMtoMEConverter() {}
00074
00075 void EDMtoMEConverter::beginJob(const edm::EventSetup& iSetup)
00076 {
00077 return;
00078 }
00079
00080 void EDMtoMEConverter::endJob()
00081 {
00082 std::string MsgLoggerCat = "EDMtoMEConverter_endJob";
00083 if (verbosity >= 0)
00084 edm::LogInfo(MsgLoggerCat)
00085 << "Terminating having processed " << count.size() << " runs across "
00086 << countf << " files.";
00087 return;
00088 }
00089
00090 void EDMtoMEConverter::respondToOpenInputFile(const edm::FileBlock& iFb)
00091 {
00092 ++countf;
00093
00094 return;
00095 }
00096
00097 void EDMtoMEConverter::beginRun(const edm::Run& iRun,
00098 const edm::EventSetup& iSetup)
00099 {
00100 std::string MsgLoggerCat = "EDMtoMEConverter_beginRun";
00101
00102 int nrun = iRun.run();
00103
00104
00105 ++count[nrun];
00106
00107 if (verbosity) {
00108 edm::LogInfo(MsgLoggerCat)
00109 << "Processing run " << nrun << " (" << count.size() << " runs total)";
00110 } else if (verbosity == 0) {
00111 if (nrun%frequency == 0 || count.size() == 1) {
00112 edm::LogInfo(MsgLoggerCat)
00113 << "Processing run " << nrun << " (" << count.size() << " runs total)";
00114 }
00115 }
00116
00117 }
00118
00119 void EDMtoMEConverter::endRun(const edm::Run& iRun,
00120 const edm::EventSetup& iSetup)
00121 {
00122 if (convertOnEndRun) {
00123 convert(iRun, true);
00124 }
00125 return;
00126 }
00127
00128 void EDMtoMEConverter::beginLuminosityBlock(const edm::LuminosityBlock& iLumi,
00129 const edm::EventSetup& iSetup)
00130 {
00131 return;
00132 }
00133
00134 void EDMtoMEConverter::endLuminosityBlock(const edm::LuminosityBlock& iLumi,
00135 const edm::EventSetup& iSetup)
00136 {
00137 if (convertOnEndLumi) {
00138 if (prescaleFactor > 0 &&
00139 iLumi.id().luminosityBlock() % prescaleFactor == 0) {
00140 const edm::Run& iRun = iLumi.getRun();
00141 convert(iRun, false);
00142 }
00143 }
00144 return;
00145 }
00146
00147 void EDMtoMEConverter::analyze(const edm::Event& iEvent,
00148 const edm::EventSetup& iSetup)
00149 {
00150 return;
00151 }
00152
00153 void EDMtoMEConverter::convert(const edm::Run& iRun, const bool endrun)
00154 {
00155 std::string MsgLoggerCat = "EDMtoMEConverter_convert";
00156
00157 if (verbosity >= 0)
00158 edm::LogInfo (MsgLoggerCat) << "\nRestoring MonitorElements.";
00159
00160 for (unsigned int ii = 0; ii < classtypes.size(); ++ii) {
00161
00162 if (classtypes[ii] == "TH1F") {
00163 edm::Handle<MEtoEDM<TH1F> > metoedm;
00164 iRun.getByType(metoedm);
00165
00166 if (!metoedm.isValid()) {
00167
00168
00169 continue;
00170 }
00171
00172 std::vector<MEtoEDM<TH1F>::MEtoEDMObject> metoedmobject =
00173 metoedm->getMEtoEdmObject();
00174
00175 me1.resize(metoedmobject.size());
00176
00177 for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
00178
00179 me1[i] = 0;
00180
00181
00182 std::string pathname = metoedmobject[i].name;
00183 if (verbosity) std::cout << pathname << std::endl;
00184
00185
00186 if (!releaseTag)
00187 {
00188 dbe->cd();
00189 dbe->bookString(
00190 "ReleaseTag",
00191 metoedmobject[i].
00192 release.substr(1,metoedmobject[i].release.size()-2)
00193 );
00194 releaseTag = true;
00195 }
00196
00197 std::string dir;
00198
00199
00200 StringList fulldir = StringOps::split(pathname,"/");
00201
00202 for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
00203 dir += fulldir[j];
00204 if (j != fulldir.size() - 2) dir += "/";
00205 }
00206
00207
00208 if (dbe) {
00209 dbe->setCurrentFolder(dir);
00210 me1[i] = dbe->book1D(metoedmobject[i].object.GetName(),
00211 &metoedmobject[i].object);
00212 }
00213
00214
00215 TagList tags = metoedmobject[i].tags;
00216
00217 for (unsigned int j = 0; j < tags.size(); ++j) {
00218 dbe->tag(me1[i]->getFullname(),tags[j]);
00219 }
00220 }
00221 }
00222
00223 if (classtypes[ii] == "TH1S") {
00224 edm::Handle<MEtoEDM<TH1S> > metoedm;
00225 iRun.getByType(metoedm);
00226
00227 if (!metoedm.isValid()) {
00228
00229
00230 continue;
00231 }
00232
00233 std::vector<MEtoEDM<TH1S>::MEtoEDMObject> metoedmobject =
00234 metoedm->getMEtoEdmObject();
00235
00236 me1.resize(metoedmobject.size());
00237
00238 for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
00239
00240 me1[i] = 0;
00241
00242
00243 std::string pathname = metoedmobject[i].name;
00244 if (verbosity) std::cout << pathname << std::endl;
00245
00246
00247 if (!releaseTag)
00248 {
00249 dbe->cd();
00250 dbe->bookString(
00251 "ReleaseTag",
00252 metoedmobject[i].
00253 release.substr(1,metoedmobject[i].release.size()-2)
00254 );
00255 releaseTag = true;
00256 }
00257
00258 std::string dir;
00259
00260
00261 StringList fulldir = StringOps::split(pathname,"/");
00262
00263 for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
00264 dir += fulldir[j];
00265 if (j != fulldir.size() - 2) dir += "/";
00266 }
00267
00268
00269 if (dbe) {
00270 dbe->setCurrentFolder(dir);
00271 me1[i] = dbe->book1S(metoedmobject[i].object.GetName(),
00272 &metoedmobject[i].object);
00273 }
00274
00275
00276 TagList tags = metoedmobject[i].tags;
00277
00278 for (unsigned int j = 0; j < tags.size(); ++j) {
00279 dbe->tag(me1[i]->getFullname(),tags[j]);
00280 }
00281 }
00282 }
00283
00284 if (classtypes[ii] == "TH2F") {
00285 edm::Handle<MEtoEDM<TH2F> > metoedm;
00286 iRun.getByType(metoedm);
00287
00288 if (!metoedm.isValid()) {
00289
00290
00291 continue;
00292 }
00293
00294 std::vector<MEtoEDM<TH2F>::MEtoEDMObject> metoedmobject =
00295 metoedm->getMEtoEdmObject();
00296
00297 me2.resize(metoedmobject.size());
00298
00299 for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
00300
00301 me2[i] = 0;
00302
00303
00304 std::string pathname = metoedmobject[i].name;
00305 if (verbosity) std::cout << pathname << std::endl;
00306
00307
00308 if (!releaseTag)
00309 {
00310 dbe->cd();
00311 dbe->bookString(
00312 "ReleaseTag",
00313 metoedmobject[i].
00314 release.substr(1,metoedmobject[i].release.size()-2)
00315 );
00316 releaseTag = true;
00317 }
00318
00319 std::string dir;
00320
00321
00322 StringList fulldir = StringOps::split(pathname,"/");
00323
00324 for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
00325 dir += fulldir[j];
00326 if (j != fulldir.size() - 2) dir += "/";
00327 }
00328
00329
00330 if (dbe) {
00331 dbe->setCurrentFolder(dir);
00332 me2[i] = dbe->book2D(metoedmobject[i].object.GetName(),
00333 &metoedmobject[i].object);
00334 }
00335
00336
00337 TagList tags = metoedmobject[i].tags;
00338
00339 for (unsigned int j = 0; j < tags.size(); ++j) {
00340 dbe->tag(me2[i]->getFullname(),tags[j]);
00341 }
00342 }
00343 }
00344
00345 if (classtypes[ii] == "TH2S") {
00346 edm::Handle<MEtoEDM<TH2S> > metoedm;
00347 iRun.getByType(metoedm);
00348
00349 if (!metoedm.isValid()) {
00350
00351
00352 continue;
00353 }
00354
00355 std::vector<MEtoEDM<TH2S>::MEtoEDMObject> metoedmobject =
00356 metoedm->getMEtoEdmObject();
00357
00358 me2.resize(metoedmobject.size());
00359
00360 for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
00361
00362 me2[i] = 0;
00363
00364
00365 std::string pathname = metoedmobject[i].name;
00366 if (verbosity) std::cout << pathname << std::endl;
00367
00368
00369 if (!releaseTag)
00370 {
00371 dbe->cd();
00372 dbe->bookString(
00373 "ReleaseTag",
00374 metoedmobject[i].
00375 release.substr(1,metoedmobject[i].release.size()-2)
00376 );
00377 releaseTag = true;
00378 }
00379
00380 std::string dir;
00381
00382
00383 StringList fulldir = StringOps::split(pathname,"/");
00384
00385 for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
00386 dir += fulldir[j];
00387 if (j != fulldir.size() - 2) dir += "/";
00388 }
00389
00390
00391 if (dbe) {
00392 dbe->setCurrentFolder(dir);
00393 me2[i] = dbe->book2S(metoedmobject[i].object.GetName(),
00394 &metoedmobject[i].object);
00395 }
00396
00397
00398 TagList tags = metoedmobject[i].tags;
00399
00400 for (unsigned int j = 0; j < tags.size(); ++j) {
00401 dbe->tag(me2[i]->getFullname(),tags[j]);
00402 }
00403 }
00404 }
00405
00406 if (classtypes[ii] == "TH3F") {
00407 edm::Handle<MEtoEDM<TH3F> > metoedm;
00408 iRun.getByType(metoedm);
00409
00410 if (!metoedm.isValid()) {
00411
00412
00413 continue;
00414 }
00415
00416 std::vector<MEtoEDM<TH3F>::MEtoEDMObject> metoedmobject =
00417 metoedm->getMEtoEdmObject();
00418
00419 me3.resize(metoedmobject.size());
00420
00421 for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
00422
00423 me3[i] = 0;
00424
00425
00426 std::string pathname = metoedmobject[i].name;
00427 if (verbosity) std::cout << pathname << std::endl;
00428
00429
00430 if (!releaseTag)
00431 {
00432 dbe->cd();
00433 dbe->bookString(
00434 "ReleaseTag",
00435 metoedmobject[i].
00436 release.substr(1,metoedmobject[i].release.size()-2)
00437 );
00438 releaseTag = true;
00439 }
00440
00441 std::string dir;
00442
00443
00444 StringList fulldir = StringOps::split(pathname,"/");
00445
00446 for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
00447 dir += fulldir[j];
00448 if (j != fulldir.size() - 2) dir += "/";
00449 }
00450
00451
00452 if (dbe) {
00453 dbe->setCurrentFolder(dir);
00454 me3[i] = dbe->book3D(metoedmobject[i].object.GetName(),
00455 &metoedmobject[i].object);
00456 }
00457
00458
00459 TagList tags = metoedmobject[i].tags;
00460
00461 for (unsigned int j = 0; j < tags.size(); ++j) {
00462 dbe->tag(me3[i]->getFullname(),tags[j]);
00463 }
00464 }
00465 }
00466
00467 if (classtypes[ii] == "TProfile") {
00468 edm::Handle<MEtoEDM<TProfile> > metoedm;
00469 iRun.getByType(metoedm);
00470
00471 if (!metoedm.isValid()) {
00472
00473
00474 continue;
00475 }
00476
00477 std::vector<MEtoEDM<TProfile>::MEtoEDMObject> metoedmobject =
00478 metoedm->getMEtoEdmObject();
00479
00480 me4.resize(metoedmobject.size());
00481
00482 for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
00483
00484 me4[i] = 0;
00485
00486
00487 std::string pathname = metoedmobject[i].name;
00488 if (verbosity) std::cout << pathname << std::endl;
00489
00490
00491 if (!releaseTag)
00492 {
00493 dbe->cd();
00494 dbe->bookString(
00495 "ReleaseTag",
00496 metoedmobject[i].
00497 release.substr(1,metoedmobject[i].release.size()-2)
00498 );
00499 releaseTag = true;
00500 }
00501
00502 std::string dir;
00503
00504
00505 StringList fulldir = StringOps::split(pathname,"/");
00506
00507 for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
00508 dir += fulldir[j];
00509 if (j != fulldir.size() - 2) dir += "/";
00510 }
00511
00512
00513 if (dbe) {
00514 dbe->setCurrentFolder(dir);
00515 me4[i] = dbe->bookProfile(metoedmobject[i].object.GetName(),
00516 &metoedmobject[i].object);
00517 }
00518
00519
00520 TagList tags = metoedmobject[i].tags;
00521
00522 for (unsigned int j = 0; j < tags.size(); ++j) {
00523 dbe->tag(me4[i]->getFullname(),tags[j]);
00524 }
00525 }
00526 }
00527
00528 if (classtypes[ii] == "TProfile2D") {
00529 edm::Handle<MEtoEDM<TProfile2D> > metoedm;
00530 iRun.getByType(metoedm);
00531
00532 if (!metoedm.isValid()) {
00533
00534
00535 continue;
00536 }
00537
00538 std::vector<MEtoEDM<TProfile2D>::MEtoEDMObject> metoedmobject =
00539 metoedm->getMEtoEdmObject();
00540
00541 me5.resize(metoedmobject.size());
00542
00543 for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
00544
00545 me5[i] = 0;
00546
00547
00548 std::string pathname = metoedmobject[i].name;
00549 if (verbosity) std::cout << pathname << std::endl;
00550
00551
00552 if (!releaseTag)
00553 {
00554 dbe->cd();
00555 dbe->bookString(
00556 "ReleaseTag",
00557 metoedmobject[i].
00558 release.substr(1,metoedmobject[i].release.size()-2)
00559 );
00560 releaseTag = true;
00561 }
00562
00563 std::string dir;
00564
00565
00566 StringList fulldir = StringOps::split(pathname,"/");
00567
00568 for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
00569 dir += fulldir[j];
00570 if (j != fulldir.size() - 2) dir += "/";
00571 }
00572
00573
00574 if (dbe) {
00575 dbe->setCurrentFolder(dir);
00576 me5[i] = dbe->bookProfile2D(metoedmobject[i].object.GetName(),
00577 &metoedmobject[i].object);
00578 }
00579
00580
00581 TagList tags = metoedmobject[i].tags;
00582
00583 for (unsigned int j = 0; j < tags.size(); ++j) {
00584 dbe->tag(me5[i]->getFullname(),tags[j]);
00585 }
00586 }
00587 }
00588
00589 if (classtypes[ii] == "Float") {
00590 edm::Handle<MEtoEDM<double> > metoedm;
00591 iRun.getByType(metoedm);
00592
00593 if (!metoedm.isValid()) {
00594
00595
00596 continue;
00597 }
00598
00599 std::vector<MEtoEDM<double>::MEtoEDMObject> metoedmobject =
00600 metoedm->getMEtoEdmObject();
00601
00602 me6.resize(metoedmobject.size());
00603
00604 for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
00605
00606 me6[i] = 0;
00607
00608
00609 std::string pathname = metoedmobject[i].name;
00610 if (verbosity) std::cout << pathname << std::endl;
00611
00612
00613 if (!releaseTag)
00614 {
00615 dbe->cd();
00616 dbe->bookString(
00617 "ReleaseTag",
00618 metoedmobject[i].
00619 release.substr(1,metoedmobject[i].release.size()-2)
00620 );
00621 releaseTag = true;
00622 }
00623
00624 std::string dir;
00625 std::string name;
00626
00627
00628
00629 StringList fulldir = StringOps::split(pathname,"/");
00630 name = *(fulldir.end() - 1);
00631
00632 for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
00633 dir += fulldir[j];
00634 if (j != fulldir.size() - 2) dir += "/";
00635 }
00636
00637
00638 if (dbe) {
00639 dbe->setCurrentFolder(dir);
00640 me6[i] = dbe->bookFloat(name);
00641 me6[i]->Fill(metoedmobject[i].object);
00642 }
00643
00644
00645 TagList tags = metoedmobject[i].tags;
00646
00647 for (unsigned int j = 0; j < tags.size(); ++j) {
00648 dbe->tag(me6[i]->getFullname(),tags[j]);
00649 }
00650 }
00651 }
00652
00653 if (classtypes[ii] == "Int") {
00654 edm::Handle<MEtoEDM<int> > metoedm;
00655 iRun.getByType(metoedm);
00656
00657 if (!metoedm.isValid()) {
00658
00659
00660 continue;
00661 }
00662
00663 std::vector<MEtoEDM<int>::MEtoEDMObject> metoedmobject =
00664 metoedm->getMEtoEdmObject();
00665
00666 me7.resize(metoedmobject.size());
00667
00668 for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
00669
00670 me7[i] = 0;
00671
00672
00673 std::string pathname = metoedmobject[i].name;
00674 if (verbosity) std::cout << pathname << std::endl;
00675
00676
00677 if (!releaseTag)
00678 {
00679 dbe->cd();
00680 dbe->bookString(
00681 "ReleaseTag",
00682 metoedmobject[i].
00683 release.substr(1,metoedmobject[i].release.size()-2)
00684 );
00685 releaseTag = true;
00686 }
00687
00688 std::string dir;
00689 std::string name;
00690
00691
00692 StringList fulldir = StringOps::split(pathname,"/");
00693 name = *(fulldir.end() - 1);
00694
00695 for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
00696 dir += fulldir[j];
00697 if (j != fulldir.size() - 2) dir += "/";
00698 }
00699
00700
00701 if (dbe) {
00702 dbe->setCurrentFolder(dir);
00703 int ival = 0;
00704 if ( endrun ) {
00705 if (name.find("processedEvents") != std::string::npos) {
00706 if (MonitorElement* me = dbe->get(dir+"/"+name)) {
00707 ival = me->getIntValue();
00708 }
00709 }
00710 }
00711 me7[i] = dbe->bookInt(name);
00712 me7[i]->Fill(metoedmobject[i].object+ival);
00713 }
00714
00715
00716 TagList tags = metoedmobject[i].tags;
00717
00718 for (unsigned int j = 0; j < tags.size(); ++j) {
00719 dbe->tag(me7[i]->getFullname(),tags[j]);
00720 }
00721 }
00722 }
00723
00724 if (classtypes[ii] == "String") {
00725 edm::Handle<MEtoEDM<TString> > metoedm;
00726 iRun.getByType(metoedm);
00727
00728 if (!metoedm.isValid()) {
00729
00730
00731 continue;
00732 }
00733
00734 std::vector<MEtoEDM<TString>::MEtoEDMObject> metoedmobject =
00735 metoedm->getMEtoEdmObject();
00736
00737 me8.resize(metoedmobject.size());
00738
00739 for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
00740
00741 me8[i] = 0;
00742
00743
00744 std::string pathname = metoedmobject[i].name;
00745 if (verbosity) std::cout << pathname << std::endl;
00746
00747
00748 if (!releaseTag)
00749 {
00750 dbe->cd();
00751 dbe->bookString(
00752 "ReleaseTag",
00753 metoedmobject[i].
00754 release.substr(1,metoedmobject[i].release.size()-2)
00755 );
00756 releaseTag = true;
00757 }
00758
00759 std::string dir;
00760 std::string name;
00761
00762
00763 StringList fulldir = StringOps::split(pathname,"/");
00764 name = *(fulldir.end() - 1);
00765
00766 for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
00767 dir += fulldir[j];
00768 if (j != fulldir.size() - 2) dir += "/";
00769 }
00770
00771
00772 if (dbe) {
00773 dbe->setCurrentFolder(dir);
00774 std::string scont = metoedmobject[i].object.Data();
00775 me8[i] = dbe->bookString(name,scont);
00776 }
00777
00778
00779 TagList tags = metoedmobject[i].tags;
00780
00781 for (unsigned int j = 0; j < tags.size(); ++j) {
00782 dbe->tag(me8[i]->getFullname(),tags[j]);
00783 }
00784 }
00785 }
00786 }
00787
00788
00789 if (verbosity) {
00790 std::vector<std::string> stags;
00791 dbe->getAllTags(stags);
00792 for (unsigned int i = 0; i < stags.size(); ++i) {
00793 std::cout << "Tags: " << stags[i] << std::endl;
00794 }
00795 }
00796
00797 return;
00798 }
00799