Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:33

0001 // -*- C++ -*-
0002 //
0003 // Package:     Integration
0004 // Class  :     DoodadESSource
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Fri Jun 24 14:39:39 EDT 2005
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0017 #include "FWCore/Framework/interface/ESProducer.h"
0018 #include "FWCore/Framework/interface/SourceFactory.h"
0019 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0021 
0022 #include "GadgetRcd.h"
0023 #include "Doodad.h"
0024 #include "FWCore/Utilities/interface/EDMException.h"
0025 
0026 namespace edmtest {
0027   class DoodadESSource : public edm::EventSetupRecordIntervalFinder, public edm::ESProducer {
0028   public:
0029     DoodadESSource(edm::ParameterSet const& pset);
0030 
0031     std::unique_ptr<Doodad> produce(const GadgetRcd&);
0032 
0033     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0034 
0035   protected:
0036     void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0037                         const edm::IOVSyncValue& iTime,
0038                         edm::ValidityInterval& iInterval) override;
0039 
0040   private:
0041     DoodadESSource(const DoodadESSource&) = delete;  // stop default
0042 
0043     const DoodadESSource& operator=(const DoodadESSource&) = delete;  // stop default
0044 
0045     // ---------- member data --------------------------------
0046     unsigned int nCalls_;
0047   };
0048 
0049   //
0050   // constants, enums and typedefs
0051   //
0052 
0053   //
0054   // static data member definitions
0055   //
0056 
0057   //
0058   // constructors and destructor
0059   //
0060   DoodadESSource::DoodadESSource(edm::ParameterSet const& pset) : nCalls_(0) {
0061     if (pset.getUntrackedParameter<bool>("test", true)) {
0062       throw edm::Exception(edm::errors::Configuration, "Something is wrong with ESSource validation\n")
0063           << "Or the test configuration parameter was set true (it should never be true unless you want this "
0064              "exception)\n";
0065     }
0066 
0067     this->findingRecord<GadgetRcd>();
0068     setWhatProduced(this);
0069   }
0070 
0071   //DoodadESSource::~DoodadESSource()
0072   //{
0073   //}
0074 
0075   //
0076   // member functions
0077   //
0078 
0079   std::unique_ptr<Doodad> DoodadESSource::produce(const GadgetRcd&) {
0080     auto data = std::make_unique<Doodad>();
0081     data->a = nCalls_;
0082     ++nCalls_;
0083     return data;
0084   }
0085 
0086   void DoodadESSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0087     edm::ParameterSetDescription desc;
0088     desc.addOptional<std::string>("appendToDataLabel");
0089     desc.addOptionalUntracked<std::string>("test2");
0090     desc.addUntracked<bool>("test", false)
0091         ->setComment("This parameter exists only to test the parameter set validation for ESSources");
0092     descriptions.add("DoodadESSource", desc);
0093   }
0094 
0095   void DoodadESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0096                                       const edm::IOVSyncValue& iTime,
0097                                       edm::ValidityInterval& iInterval) {
0098     //Be valid for 3 runs
0099     edm::EventID newTime = edm::EventID((iTime.eventID().run() - 1) - ((iTime.eventID().run() - 1) % 3) + 1, 1, 1);
0100     edm::EventID endTime =
0101         newTime.nextRun(1).nextRun(1).nextRun(1).previousRunLastEvent(edm::EventID::maxLuminosityBlockNumber());
0102     iInterval = edm::ValidityInterval(edm::IOVSyncValue(newTime), edm::IOVSyncValue(endTime));
0103   }
0104 
0105   //
0106   // const member functions
0107   //
0108 
0109   //
0110   // static member functions
0111   //
0112 }  // namespace edmtest
0113 using namespace edmtest;
0114 
0115 DEFINE_FWK_EVENTSETUP_SOURCE(DoodadESSource);