CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/Modules/src/EventSetupRecordDataGetter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EventSetupRecordDataGetter
00004 // Class:      EventSetupRecordDataGetter
00005 // 
00013 //
00014 // Original Author:  Chris Jones
00015 //         Created:  Tue Jun 28 11:10:24 EDT 2005
00016 //
00017 //
00018 
00019 
00020 // system include files
00021 #include <map>
00022 #include <vector>
00023 #include <memory>
00024 #include <set>
00025 #include <iostream>
00026 
00027 // user include files
00028 #include "FWCore/Framework/interface/EDAnalyzer.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00031 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00032 #include "FWCore/Framework/interface/EventSetupRecord.h"
00033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00034 #include "FWCore/Framework/interface/EventSetup.h"
00035 #include "FWCore/Framework/interface/MakerMacros.h"
00036 
00037 //
00038 // class decleration
00039 //
00040 namespace edm {
00041    class EventSetupRecordDataGetter : public EDAnalyzer {
00042 public:
00043      explicit EventSetupRecordDataGetter(ParameterSet const&);
00044      ~EventSetupRecordDataGetter();
00045       
00046       
00047      virtual void analyze(Event const&, EventSetup const&);
00048      virtual void beginRun(Run const&, EventSetup const&);
00049      virtual void beginLuminosityBlock(LuminosityBlock const&, EventSetup const&);
00050 
00051      static void fillDescriptions(ConfigurationDescriptions& descriptions);
00052 
00053 private:
00054      void doGet(EventSetup const&);
00055         // ----------member data ---------------------------
00056      ParameterSet pSet_;
00057       
00058      typedef std::map<eventsetup::EventSetupRecordKey, std::vector<eventsetup::DataKey> > RecordToDataKeys;
00059      RecordToDataKeys recordToDataKeys_;
00060      std::map<eventsetup::EventSetupRecordKey, unsigned long long> recordToCacheIdentifier_;
00061      bool verbose_;
00062 
00063   };
00064 
00065 //
00066 // constructors and destructor
00067 //
00068    EventSetupRecordDataGetter::EventSetupRecordDataGetter(ParameterSet const& iConfig) :
00069     pSet_(iConfig),
00070     recordToDataKeys_(),
00071     recordToCacheIdentifier_(),
00072     verbose_(iConfig.getUntrackedParameter<bool>("verbose")) {}
00073 
00074    EventSetupRecordDataGetter::~EventSetupRecordDataGetter() {
00075 
00076      // do anything here that needs to be done at desctruction time
00077      // (e.g. close files, deallocate resources etc.)
00078 
00079    }
00080 
00081 
00082 //
00083 // member functions
00084 //
00085 
00086 // ------------ method called to produce the data  ------------
00087    void EventSetupRecordDataGetter::fillDescriptions(ConfigurationDescriptions& descriptions) {
00088       descriptions.setComment("Retrieves specified data from the EventSetup sytem whenever that data changes.");
00089       
00090       ParameterSetDescription desc;
00091       desc.addUntracked<bool>("verbose", false)->setComment("Print a message to the logger each time a data item is gotten.");
00092 
00093       ParameterSetDescription toGet;
00094       toGet.add<std::string>("record")->setComment("The name of an EventSetup record holding the data you want obtained.");
00095       toGet.add<std::vector<std::string> >("data")->setComment("The identifier for the data you wish to retrieve. " 
00096                                                                "The identifier is in two parts separated by a backslash '/'. "
00097                                                                "The first part is the C++ class name of the data and the "
00098                                                                "second part is the label used when getting the data (blank is acceptable). "
00099                                                                "If there is no label, the backslash may be omitted."
00100       );
00101       
00102       desc.addVPSet("toGet", toGet)->setComment("The contained PSets must have the following structure.\n"
00103                                                 "A 'string' named 'record' that holds the name of an EventSetup record holding the data you want to obtain.\n"
00104                                                 "a 'vstring' named 'data' that holds identifiers for the data you wish to retrieve. "
00105                                                 "The identifier is in two parts separated by a backslash '/'. "
00106                                                 "The first part is the C++ class name of the data and the "
00107                                                 "second part is the label used when getting the data (blank is acceptable). "
00108                                                 "If there is no label, the backslash may be omitted."
00109       );
00110       descriptions.add("getEventSetupData", desc);
00111    }
00112 
00113    void 
00114    EventSetupRecordDataGetter::beginRun(Run const&, EventSetup const& iSetup) {
00115       doGet(iSetup);
00116    }
00117 
00118    void 
00119    EventSetupRecordDataGetter::beginLuminosityBlock(LuminosityBlock const&, EventSetup const& iSetup) {
00120       doGet(iSetup);
00121    }
00122    
00123    void
00124    EventSetupRecordDataGetter::analyze(edm::Event const& /*iEvent*/, edm::EventSetup const& iSetup) {
00125       doGet(iSetup);
00126    }
00127    
00128    void
00129    EventSetupRecordDataGetter::doGet(EventSetup const& iSetup) {  
00130       if(0 == recordToDataKeys_.size()) {
00131          typedef std::vector<ParameterSet> Parameters;
00132          Parameters const& toGet = pSet_.getParameterSetVector("toGet");
00133          
00134          for(Parameters::const_iterator itToGet = toGet.begin(), itToGetEnd = toGet.end(); itToGet != itToGetEnd; ++itToGet) {
00135             std::string recordName = itToGet->getParameter<std::string>("record");
00136             
00137             eventsetup::EventSetupRecordKey recordKey(eventsetup::EventSetupRecordKey::TypeTag::findType(recordName));
00138             if(recordKey.type() == eventsetup::EventSetupRecordKey::TypeTag()) {
00139               //record not found
00140               edm::LogWarning("DataGetter") <<"Record \""<< recordName <<"\" does not exist "<<std::endl;
00141                
00142                continue;
00143             }
00144             typedef std::vector<std::string> Strings;
00145             Strings dataNames = itToGet->getParameter<Strings>("data");
00146             std::vector<eventsetup::DataKey> dataKeys;
00147             for(Strings::iterator itDatum = dataNames.begin(), itDatumEnd = dataNames.end();
00148                   itDatum != itDatumEnd; ++itDatum) {
00149                std::string datumName(*itDatum, 0, itDatum->find_first_of("/"));
00150                std::string labelName;
00151                if(itDatum->size() != datumName.size()) {
00152                   labelName = std::string(*itDatum, datumName.size()+1);
00153                }
00154                eventsetup::TypeTag datumType = eventsetup::TypeTag::findType(datumName);
00155                if(datumType == eventsetup::TypeTag()) {
00156                  //not found
00157                  edm::LogWarning("DataGetter") <<"data item of type \""<< datumName <<"\" does not exist"<<std::endl;
00158 
00159                 
00160                   continue;
00161                }
00162                eventsetup::DataKey datumKey(datumType, labelName.c_str());
00163                dataKeys.push_back(datumKey); 
00164             }
00165             recordToDataKeys_.insert(std::make_pair(recordKey, dataKeys));
00166             recordToCacheIdentifier_.insert(std::make_pair(recordKey, 0));
00167          }
00168          if(toGet.empty()) {
00169             //This means we should get everything in the EventSetup
00170             std::vector<eventsetup::EventSetupRecordKey> recordKeys;
00171             iSetup.fillAvailableRecordKeys(recordKeys);
00172             std::vector<eventsetup::DataKey> dataKeys;
00173 
00174             for(std::vector<eventsetup::EventSetupRecordKey>::iterator itRKey = recordKeys.begin(), itRKeyEnd = recordKeys.end();
00175                 itRKey != itRKeyEnd;
00176                 ++itRKey) {               
00177                eventsetup::EventSetupRecord const* record = iSetup.find(*itRKey);
00178                dataKeys.clear();
00179                record->fillRegisteredDataKeys(dataKeys);
00180                recordToDataKeys_.insert(std::make_pair(*itRKey, dataKeys));
00181                recordToCacheIdentifier_.insert(std::make_pair(*itRKey, 0));               
00182             }
00183          }
00184       }
00185       
00186       using namespace edm::eventsetup;
00187 
00188       //For each requested Record get the requested data only if the Record is in a new IOV
00189       
00190       for(RecordToDataKeys::iterator itRecord = recordToDataKeys_.begin(), itRecordEnd = recordToDataKeys_.end();
00191            itRecord != itRecordEnd;
00192            ++itRecord) {
00193          EventSetupRecord const* pRecord = iSetup.find(itRecord->first);
00194          if(0 == pRecord) {
00195            edm::LogWarning("RecordNotInIOV") <<"The EventSetup Record '"<<itRecord->first.name()<<"' is not available for this IOV.";
00196          }
00197          if(0 != pRecord && pRecord->cacheIdentifier() != recordToCacheIdentifier_[itRecord->first]) {
00198             recordToCacheIdentifier_[itRecord->first] = pRecord->cacheIdentifier();
00199             typedef std::vector<DataKey> Keys;
00200             Keys const& keys = itRecord->second;
00201             for(Keys::const_iterator itKey = keys.begin(), itKeyEnd = keys.end();
00202                  itKey != itKeyEnd;
00203                  ++itKey) {
00204                if(! pRecord->doGet(*itKey)) {
00205                  edm::LogWarning("DataGetter") << "No data of type \""<<itKey->type().name() <<"\" with name \""<< itKey->name().value()<<"\" in record "<<itRecord->first.type().name() <<" found "<< std::endl;
00206                } else {
00207                   if(verbose_) {
00208                     edm::LogSystem("DataGetter") << "got data of type \""<<itKey->type().name() <<"\" with name \""<< itKey->name().value()<<"\" in record "<<itRecord->first.type().name() << std::endl;
00209                   }
00210                }
00211             }
00212          }
00213       }
00214    }
00215 }
00216 using edm::EventSetupRecordDataGetter;
00217 DEFINE_FWK_MODULE(EventSetupRecordDataGetter);