Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:48

0001 
0002 // -*- C++ -*-
0003 //
0004 // Package:    PrintEventSetupContent
0005 // Class:      PrintEventSetupContent
0006 //
0007 /**\class PrintEventSetupContent PrintEventSetupContent.cc GetRecordName/PrintEventSetupContent/src/PrintEventSetupContent.cc
0008 
0009  Description: <one line class summary>
0010 
0011  Implementation:
0012      <Notes on implementation>
0013 */
0014 //
0015 // Original Author:  Weng Yao
0016 //         Created:  Tue Oct  2 13:49:56 EDT 2007
0017 //
0018 //
0019 
0020 // user include files
0021 #include "FWCore/Framework/interface/ComponentDescription.h"
0022 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0023 #include "FWCore/Framework/interface/EventSetup.h"
0024 #include "FWCore/Framework/interface/EventSetupRecord.h"
0025 #include "FWCore/Framework/interface/IOVSyncValue.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 #include "FWCore/Framework/interface/ValidityInterval.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0030 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0031 
0032 // system include files
0033 #include <iostream>
0034 #include <map>
0035 #include <memory>
0036 
0037 //
0038 // class decleration
0039 //
0040 
0041 namespace edm {
0042   class PrintEventSetupContent : public one::EDAnalyzer<one::WatchRuns, one::WatchLuminosityBlocks> {
0043   public:
0044     explicit PrintEventSetupContent(ParameterSet const&);
0045     ~PrintEventSetupContent() override;
0046 
0047     static void fillDescriptions(ConfigurationDescriptions& descriptions);
0048 
0049   private:
0050     void beginJob() override;
0051 
0052     void analyze(Event const&, EventSetup const&) override;
0053     void endJob() override;
0054     void beginRun(Run const&, EventSetup const&) override;
0055     void endRun(Run const&, EventSetup const&) override;
0056     void beginLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
0057     void endLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
0058 
0059     void print(EventSetup const&);
0060 
0061     // ----------member data ---------------------------
0062     const bool printProviders_;
0063     const bool compact_;
0064     std::map<eventsetup::EventSetupRecordKey, unsigned long long> cacheIdentifiers_;
0065   };
0066 
0067   //
0068   // constants, enums and typedefs
0069   //
0070 
0071   //
0072   // static data member definitions
0073   //
0074 
0075   //
0076   // constructors and destructor
0077   //
0078   PrintEventSetupContent::PrintEventSetupContent(ParameterSet const& config)
0079       : printProviders_(config.getUntrackedParameter<bool>("printProviders")),
0080         compact_(config.getUntrackedParameter<bool>("compact")) {
0081     //now do what ever initialization is neededEventSetupRecordDataGetter::EventSetupRecordDataGetter(ParameterSet const& iConfig):
0082     //  getter = new EventSetupRecordDataGetter::EventSetupRecordDataGetter(iConfig);
0083   }
0084 
0085   PrintEventSetupContent::~PrintEventSetupContent() {
0086     // do anything here that needs to be done at desctruction time
0087     // (e.g. close files, deallocate resources etc.)
0088   }
0089 
0090   //
0091   // member functions
0092   //
0093 
0094   // ------------ method called to for each event  ------------
0095   void PrintEventSetupContent::analyze(Event const&, EventSetup const& iSetup) { print(iSetup); }
0096 
0097   void PrintEventSetupContent::beginRun(Run const&, EventSetup const& iSetup) { print(iSetup); }
0098 
0099   void PrintEventSetupContent::endRun(Run const&, EventSetup const& iSetup) {}
0100 
0101   void PrintEventSetupContent::beginLuminosityBlock(LuminosityBlock const&, EventSetup const& iSetup) { print(iSetup); }
0102 
0103   void PrintEventSetupContent::endLuminosityBlock(LuminosityBlock const&, EventSetup const& iSetup) {}
0104 
0105   void PrintEventSetupContent::print(EventSetup const& iSetup) {
0106     typedef std::vector<eventsetup::EventSetupRecordKey> Records;
0107     typedef std::vector<eventsetup::DataKey> Data;
0108 
0109     Records records;
0110     Data data;
0111     iSetup.fillAvailableRecordKeys(records);
0112     std::unique_ptr<LogSystem> msg;
0113 
0114     for (Records::iterator itrecords = records.begin(), itrecordsend = records.end(); itrecords != itrecordsend;
0115          ++itrecords) {
0116       auto rec = iSetup.find(*itrecords);
0117 
0118       if (rec && cacheIdentifiers_[*itrecords] != rec->cacheIdentifier()) {
0119         cacheIdentifiers_[*itrecords] = rec->cacheIdentifier();
0120         rec->fillRegisteredDataKeys(data);
0121         if (compact_) {
0122           for (Data::iterator itdata = data.begin(), itdataend = data.end(); itdata != itdataend; ++itdata) {
0123             if (not msg)
0124               msg = std::make_unique<LogSystem>("ESContent");
0125             else
0126               *msg << '\n';
0127             *msg << "ESContent> "
0128                  << "record:" << itrecords->name() << " data:" << itdata->type().name() << " '"
0129                  << itdata->name().value() << "'";
0130             if (printProviders_) {
0131               edm::eventsetup::ComponentDescription const* cd = rec->providerDescription(*itdata);
0132               *msg << " provider:" << cd->type_ << " '" << cd->label_ << "'";
0133             }
0134           }
0135         } else {
0136           if (not msg) {
0137             msg = std::make_unique<LogSystem>("ESContent");
0138             *msg << "Changed Record"
0139                  << "\n  "
0140                  << "<datatype>"
0141                  << " "
0142                  << "'label' provider: 'provider label' <provider module type>";
0143           }
0144           *msg << "\n" << itrecords->name();
0145           *msg << "\n start: " << rec->validityInterval().first().eventID()
0146                << " time: " << rec->validityInterval().first().time().value();
0147           *msg << "\n end:   " << rec->validityInterval().last().eventID()
0148                << " time: " << rec->validityInterval().last().time().value();
0149           for (Data::iterator itdata = data.begin(), itdataend = data.end(); itdata != itdataend; ++itdata) {
0150             *msg << "\n  " << itdata->type().name() << " '" << itdata->name().value() << "'";
0151             if (printProviders_) {
0152               edm::eventsetup::ComponentDescription const* cd = rec->providerDescription(*itdata);
0153               *msg << " provider:" << cd->type_ << " '" << cd->label_ << "'";
0154             }
0155           }
0156         }
0157       }
0158     }
0159   }
0160 
0161   //#ifdef THIS_IS_AN_EVENT_EXAMPLE
0162   //   Handle<ExampleData> pIn;
0163   //   iEvent.getByLabel("example", pIn);
0164   //#endif
0165 
0166   //#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
0167   //   ESHandle<SetupData> pSetup;
0168   //   iSetup.get<SetupRecord>().get(pSetup);
0169   //#endif
0170 
0171   // ------------ method called once each job just before starting event loop  ------------
0172   void PrintEventSetupContent::beginJob() {}
0173 
0174   // ------------ method called once each job just after ending the event loop  ------------
0175   void PrintEventSetupContent::endJob() {}
0176 
0177   // ------------ method called once each job for validation  ------------
0178   void PrintEventSetupContent::fillDescriptions(ConfigurationDescriptions& descriptions) {
0179     descriptions.setComment(
0180         "Print what data is available in each available EventSetup Record in the job.\n"
0181         "As part of the data is the C++ class type, label and which module makes that data.");
0182     ParameterSetDescription desc;
0183     desc.addUntracked<bool>("compact", false)
0184         ->setComment("If 'true' produces a more compact view, similar to the one used by PrintEventSetupDataRetrieval");
0185     desc.addUntracked<bool>("printProviders", true)
0186         ->setComment("If 'true' also print which ES module provides the data");
0187     descriptions.add("printEventSetupContent", desc);
0188   }
0189 }  // namespace edm
0190 
0191 //define this as a plug-in
0192 using edm::PrintEventSetupContent;
0193 DEFINE_FWK_MODULE(PrintEventSetupContent);