File indexing completed on 2023-03-17 11:02:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
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;
0042
0043 const DoodadESSource& operator=(const DoodadESSource&) = delete;
0044
0045
0046 unsigned int nCalls_;
0047 };
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
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
0072
0073
0074
0075
0076
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
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
0107
0108
0109
0110
0111
0112 }
0113 using namespace edmtest;
0114
0115 DEFINE_FWK_EVENTSETUP_SOURCE(DoodadESSource);