CMS 3D CMS Logo

BeamSpotOnlinePopConSourceHandler.cc
Go to the documentation of this file.
5 
6 #include <chrono>
7 #include <memory>
8 
10  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
11  m_name(pset.getUntrackedParameter<std::string>("name", "BeamSpotOnlineSourceHandler")),
12  m_maxAge(pset.getUntrackedParameter<unsigned int>("maxAge", 86400)),
13  m_runNumber(pset.getUntrackedParameter<unsigned int>("runNumber", 1)),
14  m_sourcePayloadTag(pset.getUntrackedParameter<std::string>("sourcePayloadTag", "")) {}
15 
17 
18 bool checkPayloadAge(const BeamSpotOnlineObjects& payload, unsigned int maxAge) {
19  long creationTimeInSeconds = payload.creationTime() >> 32;
20  auto timeNow = std::chrono::system_clock::now();
21  auto nowSinceEpoch = std::chrono::duration_cast<std::chrono::seconds>(timeNow.time_since_epoch()).count();
22  long age = nowSinceEpoch - creationTimeInSeconds;
23  return age < maxAge;
24 }
25 
26 std::unique_ptr<BeamSpotOnlineObjects> makeDummyPayload() {
27  // implement here
28  std::unique_ptr<BeamSpotOnlineObjects> ret;
29  ret = std::make_unique<BeamSpotOnlineObjects>();
30  auto timeNow = std::chrono::system_clock::now();
31  auto nowSinceEpoch = std::chrono::duration_cast<std::chrono::seconds>(timeNow.time_since_epoch()).count();
32  ret->setCreationTime(nowSinceEpoch << 32);
33  return ret;
34 }
35 
37  bool addNewPayload = false;
38  if (!tagInfo().size) {
39  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
40  addNewPayload = true;
41  } else {
42  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ", last object valid since "
43  << tagInfo().lastInterval.since << "; from " << m_name << "::getNewObjects";
45  addNewPayload = true;
46  }
47  }
48 
49  if (addNewPayload) {
50  if (!m_sourcePayloadTag.empty()) {
51  edm::LogInfo(m_name) << "Reading target payload from tag " << m_sourcePayloadTag;
52  auto session = dbSession();
53  session.transaction().start(true);
54  auto lastIov = session.readIov(m_sourcePayloadTag).getLast();
55  m_payload = session.fetchPayload<BeamSpotOnlineObjects>(lastIov.payloadId);
56  session.transaction().commit();
57  } else {
59  }
60 
62  m_to_transfer.push_back(std::make_pair(m_payload.get(), targetTime));
63 
64  edm::LogInfo(m_name) << "Payload added with IOV since " << targetTime;
65  } else {
66  edm::LogInfo(m_name) << "Nothing to do, last payload satisfies maximum age requirement.";
67  }
68 }
69 
BeamSpotOnlinePopConSourceHandler(const edm::ParameterSet &pset)
size
Write out results.
double seconds()
Iov_t lastInterval
Definition: Types.h:73
ret
prodAgent to be discontinued
Time_t since
Definition: Types.h:53
bool checkPayloadAge(const BeamSpotOnlineObjects &payload, unsigned int maxAge)
std::string name
Definition: Types.h:72
unsigned long long Time_t
Definition: Time.h:14
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:66
std::vector< std::pair< BeamSpotOnlineObjects *, Time_t > > m_to_transfer
std::unique_ptr< BeamSpotOnlineObjects > m_payload
Log< level::Info, false > LogInfo
std::unique_ptr< BeamSpotOnlineObjects > makeDummyPayload()
cond::persistency::Session & dbSession() const