CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/DQMServices/Components/plugins/MEtoEDMConverter.cc

Go to the documentation of this file.
00001 
00011 #include <cassert>
00012 
00013 #include "DQMServices/Components/plugins/MEtoEDMConverter.h"
00014 #include "classlib/utils/StringList.h"
00015 #include "classlib/utils/StringOps.h"
00016 
00017 using namespace lat;
00018 
00019 MEtoEDMConverter::MEtoEDMConverter(const edm::ParameterSet & iPSet) :
00020   fName(""), verbosity(0), frequency(0), deleteAfterCopy(false)
00021 {
00022   std::string MsgLoggerCat = "MEtoEDMConverter_MEtoEDMConverter";
00023 
00024   // get information from parameter set
00025   fName = iPSet.getUntrackedParameter<std::string>("Name","MEtoEDMConverter");
00026   verbosity = iPSet.getUntrackedParameter<int>("Verbosity",0);
00027   frequency = iPSet.getUntrackedParameter<int>("Frequency",50);
00028   path = iPSet.getUntrackedParameter<std::string>("MEPathToSave");  
00029   deleteAfterCopy = iPSet.getUntrackedParameter<bool>("deleteAfterCopy",false);  
00030   
00031   // use value of first digit to determine default output level (inclusive)
00032   // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
00033   verbosity %= 10;
00034   
00035   // print out Parameter Set information being used
00036   if (verbosity >= 0) {
00037     edm::LogInfo(MsgLoggerCat) 
00038       << "\n===============================\n"
00039       << "Initialized as EDProducer with parameter values:\n"
00040       << "    Name          = " << fName << "\n"
00041       << "    Verbosity     = " << verbosity << "\n"
00042       << "    Frequency     = " << frequency << "\n"
00043       << "    Path          = " << path << "\n"
00044       << "===============================\n";
00045   }
00046 
00047   // get dqm info
00048   dbe = 0;
00049   dbe = edm::Service<DQMStore>().operator->();
00050 
00051   std::string sName;
00052 
00053   // create persistent objects
00054 
00055   sName = fName + "Run";
00056   produces<MEtoEDM<TH1F>, edm::InRun>(sName);
00057   produces<MEtoEDM<TH1S>, edm::InRun>(sName);
00058   produces<MEtoEDM<TH1D>, edm::InRun>(sName);
00059   produces<MEtoEDM<TH2F>, edm::InRun>(sName);
00060   produces<MEtoEDM<TH2S>, edm::InRun>(sName);
00061   produces<MEtoEDM<TH2D>, edm::InRun>(sName);
00062   produces<MEtoEDM<TH3F>, edm::InRun>(sName);
00063   produces<MEtoEDM<TProfile>, edm::InRun>(sName);
00064   produces<MEtoEDM<TProfile2D>, edm::InRun>(sName);
00065   produces<MEtoEDM<double>, edm::InRun>(sName);
00066   produces<MEtoEDM<long long>, edm::InRun>(sName);
00067   produces<MEtoEDM<TString>, edm::InRun>(sName);
00068 
00069   sName = fName + "Lumi";
00070   produces<MEtoEDM<TH1F>, edm::InLumi>(sName);
00071   produces<MEtoEDM<TH1S>, edm::InLumi>(sName);
00072   produces<MEtoEDM<TH1D>, edm::InLumi>(sName);
00073   produces<MEtoEDM<TH2F>, edm::InLumi>(sName);
00074   produces<MEtoEDM<TH2S>, edm::InLumi>(sName);
00075   produces<MEtoEDM<TH2D>, edm::InLumi>(sName);
00076   produces<MEtoEDM<TH3F>, edm::InLumi>(sName);
00077   produces<MEtoEDM<TProfile>, edm::InLumi>(sName);
00078   produces<MEtoEDM<TProfile2D>, edm::InLumi>(sName);
00079   produces<MEtoEDM<double>, edm::InLumi>(sName);
00080   produces<MEtoEDM<long long>, edm::InLumi>(sName);
00081   produces<MEtoEDM<TString>, edm::InLumi>(sName);
00082 
00083   iCount.clear();
00084 
00085   assert(sizeof(int64_t) == sizeof(long long));
00086 
00087 }
00088 
00089 MEtoEDMConverter::~MEtoEDMConverter() 
00090 {
00091 }
00092 
00093 void
00094 MEtoEDMConverter::beginJob()
00095 {
00096 }
00097 
00098 void
00099 MEtoEDMConverter::endJob(void)
00100 {
00101   std::string MsgLoggerCat = "MEtoEDMConverter_endJob";
00102 
00103   if (verbosity > 0) {
00104 
00105     // keep track just of package names
00106     std::map<std::string,int> packages;
00107 
00108     // count various objects we have
00109     unsigned nTH1F = 0;
00110     unsigned nTH1S = 0;
00111     unsigned nTH1D = 0;
00112     unsigned nTH2F = 0;
00113     unsigned nTH2S = 0;
00114     unsigned nTH2D = 0;
00115     unsigned nTH3F = 0;
00116     unsigned nTProfile = 0;
00117     unsigned nTProfile2D = 0;
00118     unsigned nDouble = 0;
00119     unsigned nInt64 = 0;
00120     unsigned nString = 0;
00121 
00122     if (verbosity > 1) std::cout << std::endl << "Summary :" << std::endl;
00123 
00124     // get contents out of DQM
00125     std::vector<MonitorElement *>::iterator mmi, mme;
00126     std::vector<MonitorElement *> items(dbe->getAllContents(""));
00127 
00128     for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
00129 
00130       // keep track of leading directory (i.e. package)
00131       StringList dir = StringOps::split((*mmi)->getPathname(),"/");
00132       ++packages[dir[0]];
00133 
00134       // check type
00135       if (verbosity > 1) std::cout << "MEobject:" << std::endl;
00136       MonitorElement *me = *mmi;
00137       TObject *tobj = me->getRootObject();
00138       switch (me->kind())
00139       {
00140       case MonitorElement::DQM_KIND_INT:
00141         ++nInt64;
00142         if (verbosity > 1)
00143           std::cout << "   scalar: " << tobj->GetName() << ": Int64\n";
00144         break;
00145 
00146       case MonitorElement::DQM_KIND_REAL:
00147         ++nDouble;
00148         if (verbosity > 1)
00149           std::cout << "   scalar: " << tobj->GetName() << ": Double\n";
00150         break;
00151 
00152       case MonitorElement::DQM_KIND_STRING:
00153         ++nString;
00154         if (verbosity > 1)
00155           std::cout << "   scalar: " << tobj->GetName() << ": String\n";
00156         break;
00157 
00158       case MonitorElement::DQM_KIND_TH1F:
00159         ++nTH1F;
00160         if (verbosity > 1)
00161           std::cout << "   normal: " << tobj->GetName() << ": TH1F\n";
00162         break;
00163 
00164       case MonitorElement::DQM_KIND_TH1S:
00165        ++nTH1S;
00166         if (verbosity > 1)
00167           std::cout << "   normal: " << tobj->GetName() << ": TH1S\n";
00168         break;
00169 
00170       case MonitorElement::DQM_KIND_TH1D:
00171        ++nTH1D;
00172          if (verbosity > 1)
00173           std::cout << "   normal: " << tobj->GetName() << ": TH1D\n";
00174         break;
00175 
00176       case MonitorElement::DQM_KIND_TH2F:
00177         ++nTH2F;
00178         if (verbosity > 1)
00179           std::cout << "   normal: " << tobj->GetName() << ": TH2F\n";
00180         break;
00181 
00182       case MonitorElement::DQM_KIND_TH2S:
00183         ++nTH2S;
00184         if (verbosity > 1)
00185           std::cout << "   normal: " << tobj->GetName() << ": TH2S\n";
00186         break;
00187 
00188       case MonitorElement::DQM_KIND_TH2D:
00189         ++nTH2D;
00190         if (verbosity > 1)
00191           std::cout << "   normal: " << tobj->GetName() << ": TH2D\n";
00192         break;
00193 
00194       case MonitorElement::DQM_KIND_TH3F:
00195         ++nTH3F;
00196         if (verbosity > 1)
00197           std::cout << "   normal: " << tobj->GetName() << ": TH3F\n";
00198         break;
00199 
00200       case MonitorElement::DQM_KIND_TPROFILE:
00201         ++nTProfile;
00202         if (verbosity > 1)
00203           std::cout << "   normal: " << tobj->GetName() << ": TProfile\n";
00204         break;
00205 
00206       case MonitorElement::DQM_KIND_TPROFILE2D:
00207         ++nTProfile2D;
00208         if (verbosity > 1)
00209           std::cout << "   normal: " << tobj->GetName() << ": TProfile2D\n";
00210         break;
00211 
00212       default:
00213         edm::LogError(MsgLoggerCat)
00214           << "ERROR: The DQM object '" << me->getFullname()
00215           << "' is neither a ROOT object nor a recognised "
00216           << "simple object.\n";
00217         continue;
00218       }
00219     } // end loop through monitor elements
00220 
00221     // list unique packages
00222     std::cout << "Packages accessing DQM:" << std::endl;
00223     std::map<std::string,int>::iterator pkgIter;
00224     for (pkgIter = packages.begin(); pkgIter != packages.end(); ++pkgIter) 
00225       std::cout << "  " << pkgIter->first << ": " << pkgIter->second 
00226                 << std::endl;
00227 
00228     std::cout << "We have " << nTH1F << " TH1F objects" << std::endl;
00229     std::cout << "We have " << nTH1S << " TH1S objects" << std::endl;
00230     std::cout << "We have " << nTH1D << " TH1D objects" << std::endl;
00231     std::cout << "We have " << nTH2F << " TH2F objects" << std::endl;
00232     std::cout << "We have " << nTH2S << " TH2S objects" << std::endl;
00233     std::cout << "We have " << nTH2D << " TH2D objects" << std::endl;
00234     std::cout << "We have " << nTH3F << " TH3F objects" << std::endl;
00235     std::cout << "We have " << nTProfile << " TProfile objects" << std::endl;
00236     std::cout << "We have " << nTProfile2D << " TProfile2D objects" << std::endl;
00237     std::cout << "We have " << nDouble << " Double objects" << std::endl;
00238     std::cout << "We have " << nInt64 << " Int64 objects" << std::endl;
00239     std::cout << "We have " << nString << " String objects" << std::endl;
00240 
00241     if (verbosity > 1) std::cout << std::endl;
00242 
00243   }
00244 
00245   if (verbosity >= 0)
00246     edm::LogInfo(MsgLoggerCat) 
00247       << "Terminating having processed " << iCount.size() << " runs.";
00248 
00249 }
00250 
00251 void
00252 MEtoEDMConverter::beginRun(edm::Run& iRun, const edm::EventSetup& iSetup)
00253 {
00254   std::string MsgLoggerCat = "MEtoEDMConverter_beginRun";
00255     
00256   int nrun = iRun.run();
00257   
00258   // keep track of number of runs processed
00259   ++iCount[nrun];
00260 
00261   if (verbosity > 0) {  // keep track of number of runs processed
00262     edm::LogInfo(MsgLoggerCat)
00263       << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
00264   } else if (verbosity == 0) {
00265     if (nrun%frequency == 0 || iCount.size() == 1) {
00266       edm::LogInfo(MsgLoggerCat)
00267         << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
00268     }
00269   }
00270 
00271   // clear contents of monitor elements
00272   std::vector<MonitorElement *>::iterator mmi, mme;
00273   std::vector<MonitorElement *> items(dbe->getAllContents(path));
00274 
00275   for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
00276 
00277     MonitorElement *me = *mmi;
00278 
00279     switch (me->kind())
00280     {
00281     case MonitorElement::DQM_KIND_INT:
00282       break;
00283 
00284     case MonitorElement::DQM_KIND_REAL:
00285       break;
00286 
00287     case MonitorElement::DQM_KIND_STRING:
00288       break;
00289 
00290     case MonitorElement::DQM_KIND_TH1F:
00291       me->Reset();
00292       break;
00293 
00294     case MonitorElement::DQM_KIND_TH1S:
00295       me->Reset();
00296       break;
00297 
00298     case MonitorElement::DQM_KIND_TH1D:
00299       me->Reset();
00300       break;
00301 
00302     case MonitorElement::DQM_KIND_TH2F:
00303       me->Reset();
00304       break;
00305 
00306     case MonitorElement::DQM_KIND_TH2S:
00307       me->Reset();
00308       break;
00309 
00310     case MonitorElement::DQM_KIND_TH2D:
00311       me->Reset();
00312       break;
00313 
00314     case MonitorElement::DQM_KIND_TH3F:
00315       me->Reset();
00316       break;
00317 
00318     case MonitorElement::DQM_KIND_TPROFILE:
00319       me->Reset();
00320       break;
00321 
00322     case MonitorElement::DQM_KIND_TPROFILE2D:
00323       me->Reset();
00324       break;
00325 
00326     default:
00327       edm::LogError(MsgLoggerCat)
00328         << "ERROR: The DQM object '" << me->getFullname()
00329         << "' is neither a ROOT object nor a recognised "
00330         << "simple object.\n";
00331       continue;
00332     }
00333 
00334   } // end loop through monitor elements
00335 }
00336 
00337 void
00338 MEtoEDMConverter::endRun(edm::Run& iRun, const edm::EventSetup& iSetup)
00339 {
00340   putData(iRun, false);
00341 }
00342 
00343 void
00344 MEtoEDMConverter::beginLuminosityBlock(edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup)
00345 {
00346 }
00347 
00348 void
00349 MEtoEDMConverter::endLuminosityBlock(edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup)
00350 {
00351   putData(iLumi, true);
00352 }
00353 
00354 template <class T>
00355 void
00356 MEtoEDMConverter::putData(T& iPutTo, bool iLumiOnly)
00357 {
00358   std::string MsgLoggerCat = "MEtoEDMConverter_putData";
00359   
00360   if (verbosity > 0)
00361     edm::LogInfo (MsgLoggerCat) << "\nStoring MEtoEDM dataformat histograms.";
00362 
00363   // extract ME information into vectors
00364   std::vector<MonitorElement *>::iterator mmi, mme;
00365   std::vector<MonitorElement *> items(dbe->getAllContents(path));
00366 
00367   unsigned int n1F=0;
00368   unsigned int n1S=0;
00369   unsigned int n1D=0;
00370   unsigned int n2F=0;
00371   unsigned int n2S=0;
00372   unsigned int n2D=0;
00373   unsigned int n3F=0;
00374   unsigned int nProf=0;
00375   unsigned int nProf2=0;
00376   unsigned int nDouble=0;
00377   unsigned int nInt64=0;
00378   unsigned int nString=0;
00379 
00380   for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
00381 
00382     MonitorElement *me = *mmi;
00383 
00384     // store only flagged ME
00385     if (iLumiOnly && !me->getLumiFlag()) continue;
00386 
00387     switch (me->kind())
00388     {
00389     case MonitorElement::DQM_KIND_INT:
00390       ++nInt64;
00391       break;
00392 
00393     case MonitorElement::DQM_KIND_REAL:
00394       ++nDouble;
00395       break;
00396 
00397     case MonitorElement::DQM_KIND_STRING:
00398       ++nString;
00399       break;
00400 
00401     case MonitorElement::DQM_KIND_TH1F:
00402       ++n1F;
00403       break;
00404 
00405     case MonitorElement::DQM_KIND_TH1S:
00406       ++n1S;
00407       break;
00408 
00409     case MonitorElement::DQM_KIND_TH1D:
00410       ++n1D;
00411       break;
00412 
00413     case MonitorElement::DQM_KIND_TH2F:
00414       ++n2F;
00415       break;
00416 
00417     case MonitorElement::DQM_KIND_TH2S:
00418       ++n2S;
00419       break;
00420 
00421     case MonitorElement::DQM_KIND_TH2D:
00422       ++n2D;
00423       break;
00424 
00425     case MonitorElement::DQM_KIND_TH3F:
00426       ++n3F;
00427       break;
00428 
00429     case MonitorElement::DQM_KIND_TPROFILE:
00430       ++nProf;
00431       break;
00432 
00433     case MonitorElement::DQM_KIND_TPROFILE2D:
00434       ++nProf2;
00435       break;
00436 
00437     default:
00438       edm::LogError(MsgLoggerCat)
00439         << "ERROR: The DQM object '" << me->getFullname()
00440         << "' is neither a ROOT object nor a recognised "
00441         << "simple object.\n";
00442       continue;
00443     }
00444   }
00445 
00446   std::auto_ptr<MEtoEDM<long long> > pOutInt(new MEtoEDM<long long>(nInt64));
00447   std::auto_ptr<MEtoEDM<double> > pOutDouble(new MEtoEDM<double>(nDouble));
00448   std::auto_ptr<MEtoEDM<TString> > pOutString(new MEtoEDM<TString>(nString));
00449   std::auto_ptr<MEtoEDM<TH1F> > pOut1(new MEtoEDM<TH1F>(n1F));
00450   std::auto_ptr<MEtoEDM<TH1S> > pOut1s(new MEtoEDM<TH1S>(n1S));
00451   std::auto_ptr<MEtoEDM<TH1D> > pOut1d(new MEtoEDM<TH1D>(n1D));
00452   std::auto_ptr<MEtoEDM<TH2F> > pOut2(new MEtoEDM<TH2F>(n2F));
00453   std::auto_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
00454   std::auto_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
00455   std::auto_ptr<MEtoEDM<TH3F> > pOut3(new MEtoEDM<TH3F>(n3F));
00456   std::auto_ptr<MEtoEDM<TProfile> > pOutProf(new MEtoEDM<TProfile>(nProf));
00457   std::auto_ptr<MEtoEDM<TProfile2D> > pOutProf2(new MEtoEDM<TProfile2D>(nProf2));
00458 
00459   for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
00460 
00461     MonitorElement *me = *mmi;
00462 
00463     // store only flagged ME
00464     if (iLumiOnly && !me->getLumiFlag()) continue;
00465 
00466     // get monitor elements
00467     switch (me->kind())
00468     {
00469     case MonitorElement::DQM_KIND_INT:
00470       pOutInt->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getIntValue());
00471       break;
00472 
00473     case MonitorElement::DQM_KIND_REAL:
00474       pOutDouble->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getFloatValue());
00475       break;
00476 
00477     case MonitorElement::DQM_KIND_STRING:
00478       pOutString->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getStringValue());
00479       break;
00480 
00481     case MonitorElement::DQM_KIND_TH1F:
00482       pOut1->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1F());
00483       break;
00484 
00485     case MonitorElement::DQM_KIND_TH1S:
00486       pOut1s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1S());
00487       break;
00488 
00489     case MonitorElement::DQM_KIND_TH1D:
00490       pOut1d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1D());
00491       break;
00492 
00493     case MonitorElement::DQM_KIND_TH2F:
00494       pOut2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2F());
00495       break;
00496 
00497     case MonitorElement::DQM_KIND_TH2S:
00498       pOut2s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2S());
00499       break;
00500 
00501     case MonitorElement::DQM_KIND_TH2D:
00502       pOut2d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2D());
00503       break;
00504 
00505     case MonitorElement::DQM_KIND_TH3F:
00506       pOut3->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH3F());
00507       break;
00508 
00509     case MonitorElement::DQM_KIND_TPROFILE:
00510       pOutProf->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile());
00511       break;
00512 
00513     case MonitorElement::DQM_KIND_TPROFILE2D:
00514       pOutProf2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile2D());
00515       break;
00516 
00517     default:
00518       edm::LogError(MsgLoggerCat)
00519         << "ERROR: The DQM object '" << me->getFullname()
00520         << "' is neither a ROOT object nor a recognised "
00521         << "simple object.\n";
00522       continue;
00523     }
00524 
00525     if (!iLumiOnly) {
00526       // remove ME after copy to EDM is done.
00527       if (deleteAfterCopy)
00528         dbe->removeElement(me->getPathname(),me->getName());
00529     }
00530 
00531   } // end loop through monitor elements
00532 
00533   std::string sName;
00534 
00535   if (iLumiOnly) {
00536     sName = fName + "Lumi";
00537   } else {
00538     sName = fName + "Run";
00539   }
00540 
00541   // produce objects to put in events
00542   iPutTo.put(pOutInt,sName);
00543   iPutTo.put(pOutDouble,sName);
00544   iPutTo.put(pOutString,sName);
00545   iPutTo.put(pOut1,sName);
00546   iPutTo.put(pOut1s,sName);
00547   iPutTo.put(pOut1d,sName);
00548   iPutTo.put(pOut2,sName);
00549   iPutTo.put(pOut2s,sName);
00550   iPutTo.put(pOut2d,sName);
00551   iPutTo.put(pOut3,sName);
00552   iPutTo.put(pOutProf,sName);
00553   iPutTo.put(pOutProf2,sName);
00554 
00555 }
00556 
00557 void
00558 MEtoEDMConverter::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00559 {
00560 
00561 }