DoodadESSource

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
// -*- C++ -*-
//
// Package:     Integration
// Class  :     DoodadESSource
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  Chris Jones
//         Created:  Fri Jun 24 14:39:39 EDT 2005
//

// system include files

// user include files
#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/SourceFactory.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "GadgetRcd.h"
#include "Doodad.h"
#include "FWCore/Utilities/interface/EDMException.h"

namespace edmtest {
  class DoodadESSource : public edm::EventSetupRecordIntervalFinder, public edm::ESProducer {
  public:
    DoodadESSource(edm::ParameterSet const& pset);

    std::unique_ptr<Doodad> produce(const GadgetRcd&);

    static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

  protected:
    void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
                        const edm::IOVSyncValue& iTime,
                        edm::ValidityInterval& iInterval) override;

  private:
    DoodadESSource(const DoodadESSource&) = delete;  // stop default

    const DoodadESSource& operator=(const DoodadESSource&) = delete;  // stop default

    // ---------- member data --------------------------------
    unsigned int nCalls_;
  };

  //
  // constants, enums and typedefs
  //

  //
  // static data member definitions
  //

  //
  // constructors and destructor
  //
  DoodadESSource::DoodadESSource(edm::ParameterSet const& pset) : nCalls_(0) {
    if (pset.getUntrackedParameter<bool>("test", true)) {
      throw edm::Exception(edm::errors::Configuration, "Something is wrong with ESSource validation\n")
          << "Or the test configuration parameter was set true (it should never be true unless you want this "
             "exception)\n";
    }

    this->findingRecord<GadgetRcd>();
    setWhatProduced(this);
  }

  //DoodadESSource::~DoodadESSource()
  //{
  //}

  //
  // member functions
  //

  std::unique_ptr<Doodad> DoodadESSource::produce(const GadgetRcd&) {
    auto data = std::make_unique<Doodad>();
    data->a = nCalls_;
    ++nCalls_;
    return data;
  }

  void DoodadESSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
    edm::ParameterSetDescription desc;
    desc.addOptional<std::string>("appendToDataLabel");
    desc.addOptionalUntracked<std::string>("test2");
    desc.addUntracked<bool>("test", false)
        ->setComment("This parameter exists only to test the parameter set validation for ESSources");
    descriptions.add("DoodadESSource", desc);
  }

  void DoodadESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
                                      const edm::IOVSyncValue& iTime,
                                      edm::ValidityInterval& iInterval) {
    //Be valid for 3 runs
    edm::EventID newTime = edm::EventID((iTime.eventID().run() - 1) - ((iTime.eventID().run() - 1) % 3) + 1, 1, 1);
    edm::EventID endTime =
        newTime.nextRun(1).nextRun(1).nextRun(1).previousRunLastEvent(edm::EventID::maxLuminosityBlockNumber());
    iInterval = edm::ValidityInterval(edm::IOVSyncValue(newTime), edm::IOVSyncValue(endTime));
  }

  //
  // const member functions
  //

  //
  // static member functions
  //
}  // namespace edmtest
using namespace edmtest;

DEFINE_FWK_EVENTSETUP_SOURCE(DoodadESSource);