CMS 3D CMS Logo

MEtoEDMConverter.cc

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

Generated on Tue Jun 9 17:34:11 2009 for CMSSW by  doxygen 1.5.4