CMS 3D CMS Logo

AcquireIntESProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/Integration
4 // Class: AcquireIntESProducer
5 //
10 // Original Author: W. David Dagenhart
11 // Created: 12 January 2023
12 
22 #include "WaitingServer.h"
29 
30 #include <memory>
31 #include <unistd.h>
32 #include <vector>
33 
34 namespace edmtest {
35 
37  public:
39 
40  ~AcquireIntESProducer() override;
45 
46  void initConcurrentIOVs(EventSetupRecordKey const&, unsigned int nConcurrentIOVs) override;
47 
49 
50  std::unique_ptr<ESTestDataI> produce(ESTestRecordI const&);
51 
52  std::unique_ptr<ESTestDataB> produceESTestDataB(ESTestRecordB const&);
53 
55 
56  private:
58  std::vector<test_acquire::Cache> caches_;
59  std::unique_ptr<test_acquire::WaitingServer> server_;
60  const unsigned int numberOfIOVsToAccumulate_;
61  const unsigned int secondsToWaitForWork_;
62  };
63 
65  : numberOfIOVsToAccumulate_(pset.getUntrackedParameter<unsigned int>("numberOfIOVsToAccumulate")),
66  secondsToWaitForWork_(pset.getUntrackedParameter<unsigned int>("secondsToWaitForWork")) {
67  auto collector = setWhatAcquiredProduced(this, "fromAcquireIntESProducer");
68  token_ = collector.consumes<IOVTestInfo>(edm::ESInputTag{"", ""});
69 
71  }
72 
74  if (server_) {
75  server_->stop();
76  }
77  server_.reset();
78  }
79 
80  void AcquireIntESProducer::initConcurrentIOVs(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs) {
81  if (key == EventSetupRecordKey::makeKey<ESTestRecordI>()) {
82  caches_.resize(nConcurrentIOVs);
83  server_ = std::make_unique<test_acquire::WaitingServer>(
85  server_->start();
86  }
87  }
88 
90  usleep(1000000);
91 
92  test_acquire::Cache& iovCache = caches_[record.iovIndex()];
93  iovCache.retrieved().clear();
94  iovCache.processed().clear();
95 
96  // Get some data and push it into the input cache for the ExternalWork.
97  // There is no significance to the particular data we are using.
98  // Using anything from the EventSetup would be good enough for the test.
99  // I already had test modules around that would make IOVTestInfo
100  // data, so that was easy to use. We put in known values and later
101  // check that we get the expected result (they get incremented by one
102  // to simulate some "external work", then summed in the produce method
103  // calculate a result we can check easily).
104  IOVTestInfo const& iovTestInfo = record.get(token_);
105  std::vector<int>& retrieved = iovCache.retrieved();
106  retrieved.push_back(iovTestInfo.iovStartRun_);
107  retrieved.push_back(iovTestInfo.iovStartLumi_);
108  retrieved.push_back(iovTestInfo.iovEndRun_);
109  retrieved.push_back(iovTestInfo.iovEndLumi_);
110  retrieved.push_back(iovTestInfo.cacheIdentifier_);
111 
112  server_->requestValuesAsync(record.iovIndex(), &iovCache.retrieved(), &iovCache.processed(), holder);
113 
114  edm::ValidityInterval iov = record.validityInterval();
115  if (iovTestInfo.iovStartLumi_ != iov.first().luminosityBlockNumber() ||
116  iovTestInfo.iovEndLumi_ != iov.last().luminosityBlockNumber() || iovTestInfo.iovIndex_ != record.iovIndex() ||
117  iovTestInfo.cacheIdentifier_ != record.cacheIdentifier()) {
118  throw cms::Exception("TestFailure") << "AcquireIntESProducer::acquire"
119  << "read values do not agree with record";
120  }
121  }
122 
123  std::unique_ptr<ESTestDataI> AcquireIntESProducer::produce(ESTestRecordI const& record) {
124  usleep(1000000);
125 
126  edm::ESHandle<IOVTestInfo> iovTestInfo = record.getHandle(token_);
127  edm::ValidityInterval iov = record.validityInterval();
128  if (iovTestInfo->iovStartLumi_ != iov.first().luminosityBlockNumber() ||
129  iovTestInfo->iovEndLumi_ != iov.last().luminosityBlockNumber() || iovTestInfo->iovIndex_ != record.iovIndex() ||
130  iovTestInfo->cacheIdentifier_ != record.cacheIdentifier()) {
131  throw cms::Exception("TestFailure") << "AcquireIntESProducer::produce"
132  << "read values do not agree with record";
133  }
134 
135  test_acquire::Cache& iovCache = caches_[record.iovIndex()];
136  int sum = 0;
137  for (auto v : iovCache.processed()) {
138  sum += v;
139  }
140  return std::make_unique<ESTestDataI>(sum);
141  }
142 
143  std::unique_ptr<ESTestDataB> AcquireIntESProducer::produceESTestDataB(ESTestRecordB const&) {
144  return std::make_unique<ESTestDataB>(11);
145  }
146 
149  desc.addUntracked<unsigned int>("numberOfIOVsToAccumulate", 8);
150  desc.addUntracked<unsigned int>("secondsToWaitForWork", 1);
151  descriptions.addDefault(desc);
152  }
153 
154 } // namespace edmtest
155 using namespace edmtest;
std::unique_ptr< ESTestDataI > produce(ESTestRecordI const &)
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:165
const IOVSyncValue & last() const
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:41
const IOVSyncValue & first() const
unsigned int iovEndLumi_
Definition: IOVTestInfo.h:24
unsigned int iovIndex_
Definition: IOVTestInfo.h:25
const unsigned int numberOfIOVsToAccumulate_
auto setWhatAcquiredProduced(T *iThis, const es::Label &iLabel={})
std::unique_ptr< test_acquire::WaitingServer > server_
void addDefault(ParameterSetDescription const &psetDescription)
edm::ESGetToken< IOVTestInfo, ESTestRecordI > token_
unsigned int iovEndRun_
Definition: IOVTestInfo.h:23
unsigned int iovStartLumi_
Definition: IOVTestInfo.h:22
std::vector< test_acquire::Cache > caches_
const unsigned int secondsToWaitForWork_
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
void acquire(ESTestRecordI const &, edm::WaitingTaskWithArenaHolder)
unsigned long long cacheIdentifier_
Definition: IOVTestInfo.h:26
static void fillDescriptions(edm::ConfigurationDescriptions &)
AcquireIntESProducer(edm::ParameterSet const &)
unsigned int iovStartRun_
Definition: IOVTestInfo.h:21
std::vector< int > const & processed() const
Definition: WaitingServer.h:62
std::unique_ptr< ESTestDataB > produceESTestDataB(ESTestRecordB const &)
AcquireIntESProducer & operator=(const AcquireIntESProducer &)=delete
void initConcurrentIOVs(EventSetupRecordKey const &, unsigned int nConcurrentIOVs) override
std::vector< int > const & retrieved() const
Definition: WaitingServer.h:59