CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/FWCore/Services/src/PrintEventSetupDataRetrieval.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Services
00004 // Class  :     PrintEventSetupDataRetrieval
00005 // 
00006 // Implementation:
00007 //     A service which prints which data from the EventSetup have been retrieved since the last time it checked
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Thu Jul  9 14:30:13 CDT 2009
00011 //
00012 
00013 // system include files
00014 #include <iostream>
00015 
00016 // user include files
00017 #include "FWCore/Services/src/PrintEventSetupDataRetrieval.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 #include "FWCore/Framework/interface/EventSetup.h"
00020 #include "FWCore/Framework/interface/EventSetupRecord.h"
00021 #include "FWCore/Framework/interface/ComponentDescription.h"
00022 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00023 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00024 
00025 namespace edm {
00026 //
00027 // constants, enums and typedefs
00028 //
00029 
00030 //
00031 // static data member definitions
00032 //
00033 
00034 //
00035 // constructors and destructor
00036 //
00037    PrintEventSetupDataRetrieval::PrintEventSetupDataRetrieval(const ParameterSet& iPS,
00038                                                               ActivityRegistry&iRegistry):
00039    m_printProviders(iPS.getUntrackedParameter<bool>("printProviders"))
00040    {
00041       if(iPS.getUntrackedParameter<bool>("checkAfterBeginRun")) {
00042          iRegistry.watchPostBeginRun(this, &PrintEventSetupDataRetrieval::postBeginRun);
00043       }
00044       if(iPS.getUntrackedParameter<bool>("checkAfterBeginLumi")) {
00045          iRegistry.watchPostBeginLumi(this, &PrintEventSetupDataRetrieval::postBeginLumi);
00046       }
00047       if(iPS.getUntrackedParameter<bool>("checkAfterEvent")) {
00048          iRegistry.watchPostProcessEvent(this, &PrintEventSetupDataRetrieval::postProcessEvent);
00049       }
00050    }
00051 
00052 // PrintEventSetupDataRetrieval::PrintEventSetupDataRetrieval(const PrintEventSetupDataRetrieval& rhs)
00053 // {
00054 //    // do actual copying here;
00055 // }
00056 
00057    //PrintEventSetupDataRetrieval::~PrintEventSetupDataRetrieval()
00058    //{
00059    //}
00060 
00061    void PrintEventSetupDataRetrieval::fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
00062       edm::ParameterSetDescription desc;
00063       desc.addUntracked<bool>("printProviders",false)->setComment(
00064       "If 'true' also print which ES module provides the data");
00065       desc.addUntracked<bool>("checkAfterBeginRun",false)->setComment(
00066        "If 'true' check for retrieved data after each begin run is processed");
00067       desc.addUntracked<bool>("checkAfterBeginLumi",false)->setComment(
00068        "If 'true' check for retrieved data after each begin lumi is processed");
00069       desc.addUntracked<bool>("checkAfterEvent",true)->setComment(
00070        "If 'true' check for retrieved data after an event is processed");
00071       descriptions.add("PrintEventSetupDataRetrieval", desc);
00072       descriptions.setComment("This service reports when EventSetup data is retrieved by a module in the job.");
00073    }
00074 
00075 //
00076 // assignment operators
00077 //
00078 // const PrintEventSetupDataRetrieval& PrintEventSetupDataRetrieval::operator=(const PrintEventSetupDataRetrieval& rhs)
00079 // {
00080 //   //An exception safe implementation is
00081 //   PrintEventSetupDataRetrieval temp(rhs);
00082 //   swap(rhs);
00083 //
00084 //   return *this;
00085 // }
00086 
00087 //
00088 // member functions
00089 //
00090    void 
00091    PrintEventSetupDataRetrieval::postProcessEvent(Event const&, EventSetup const& iES) {
00092       check(iES);
00093    }
00094 
00095    void 
00096    PrintEventSetupDataRetrieval::postBeginRun(Run const&, EventSetup const& iES) {
00097       check(iES);
00098    }
00099 
00100    void 
00101    PrintEventSetupDataRetrieval::postBeginLumi(LuminosityBlock const&, EventSetup const& iES) {
00102       check(iES);
00103    }
00104    
00105    void PrintEventSetupDataRetrieval::check(EventSetup const& iES) {
00106       //std::cout <<"postProcessEvent"<<std::endl;
00107       m_recordKeys.clear();
00108       iES.fillAvailableRecordKeys(m_recordKeys);
00109       
00110       for(std::vector<eventsetup::EventSetupRecordKey>::const_iterator it = m_recordKeys.begin(), itEnd = m_recordKeys.end();
00111           it != itEnd;
00112           ++it) {
00113          //std::cout <<"  "<<it->name()<<std::endl;
00114          const eventsetup::EventSetupRecord* r = iES.find(*it);
00115          assert(r != 0);
00116          
00117          RetrievedDataMap::iterator itRetrievedData =  m_retrievedDataMap.find(*it);
00118          if(itRetrievedData == m_retrievedDataMap.end()) {
00119             itRetrievedData = m_retrievedDataMap.insert(std::make_pair(*it,std::pair<unsigned long long, std::map<eventsetup::DataKey,bool> >())).first;
00120             itRetrievedData->second.first = r->cacheIdentifier();
00121             std::vector<eventsetup::DataKey> keys;
00122             r->fillRegisteredDataKeys(keys);
00123             for(std::vector<eventsetup::DataKey>::const_iterator itData = keys.begin(), itDataEnd = keys.end();
00124                 itData != itDataEnd;
00125                 ++itData) {
00126                itRetrievedData->second.second.insert(std::make_pair(*itData,false));
00127             }
00128          }
00129          RetrievedDataMap::value_type& retrievedData = *itRetrievedData;
00130          if(itRetrievedData->second.first != r->cacheIdentifier()) {
00131             itRetrievedData->second.first = r->cacheIdentifier();
00132             for(std::map<eventsetup::DataKey,bool>::iterator itDatum = retrievedData.second.second.begin(), itDatumEnd = retrievedData.second.second.end();
00133                 itDatum != itDatumEnd;
00134                 ++itDatum) {
00135                itDatum->second = false;
00136             }
00137          }
00138          
00139          for(std::map<eventsetup::DataKey,bool>::iterator itDatum = retrievedData.second.second.begin(), itDatumEnd = retrievedData.second.second.end();
00140              itDatum != itDatumEnd;
00141              ++itDatum) {
00142             bool wasGotten = r->wasGotten(itDatum->first);
00143             //std::cout <<"     "<<itDatum->first.type().name()<<" "<<wasGotten<<std::endl;
00144             if(wasGotten != itDatum->second) {
00145                itDatum->second = wasGotten;
00146                if(m_printProviders) {
00147                   const edm::eventsetup::ComponentDescription* d = r->providerDescription(itDatum->first);
00148                   assert(0!=d);
00149                   edm::LogSystem("PrintEventSetupDataRetrieval")<<"Retrieved> Record:"<<it->name()<<" data:"<<itDatum->first.type().name()<<" '"<<itDatum->first.name().value()
00150                   <<"' provider:"<<d->type_<<" '"<<d->label_<<"'";
00151                } else {
00152                   edm::LogSystem("PrintEventSetupDataRetrieval")<<"Retrieved> Record:"<<it->name()<<" data:"<<itDatum->first.type().name()<<" '"<<itDatum->first.name().value()<<"'";
00153                }
00154                //std::cout <<"CHANGED"<<std::endl;
00155             }
00156          }
00157       }
00158    }
00159 
00160 //
00161 // const member functions
00162 //
00163 
00164 //
00165 // static member functions
00166 //
00167 }