Belle II Software  release-05-01-25
ProcessedEventsBackupList.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun, Anselm Baur *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <framework/pcore/zmq/processModules/ProcessedEventsBackupList.h>
11 
12 using namespace Belle2;
13 
14 void ProcessedEventsBackupList::storeEvent(std::unique_ptr<EvtMessage> evtMsg, const StoreObjPtr<EventMetaData>& evtMetaData,
15  const unsigned int workerId)
16 {
17  EventMetaData eventMetaData(evtMetaData->getEvent(), evtMetaData->getRun(), evtMetaData->getExperiment());
18  m_evtBackupVector.emplace_back(std::move(evtMsg), eventMetaData, workerId);
19 }
20 
22 {
23  const auto oldSize = m_evtBackupVector.size();
24 
25  m_evtBackupVector.erase(std::remove(m_evtBackupVector.begin(), m_evtBackupVector.end(), evtMetaData),
26  m_evtBackupVector.end());
27 
28  if (oldSize == m_evtBackupVector.size()) {
29  B2WARNING("Event: " << evtMetaData.getEvent() << ", no matching event backup found in backup list");
30  }
31 }
32 
34 {
35  if (m_evtBackupVector.empty()) {
36  return -1;
37  }
38  if (std::chrono::system_clock::now() - m_evtBackupVector[0].getTimestamp() > timeout) {
39  return m_evtBackupVector[0].getWorkerId();
40  } else {
41  return -1;
42  }
43 }
44 
45 unsigned int ProcessedEventsBackupList::size() const
46 {
47  return m_evtBackupVector.size();
48 }
Belle2::ProcessedEventsBackupList::removeEvent
void removeEvent(const EventMetaData &evtMetaData)
Remove all backups with the given event meta data (on confirmation)
Definition: ProcessedEventsBackupList.cc:21
Belle2::EventMetaData::getEvent
unsigned int getEvent() const
Event Getter.
Definition: EventMetaData.h:155
Belle2::ProcessedEventsBackupList::m_evtBackupVector
std::vector< ProcessedEventBackup > m_evtBackupVector
The vector where the event backups are stored.
Definition: ProcessedEventsBackupList.h:57
Belle2::ProcessedEventsBackupList::checkForTimeout
int checkForTimeout(const Duration &timeout) const
Check the items for timeout. Returns -1 if no timeout happened and the worker id, if it did.
Definition: ProcessedEventsBackupList.cc:33
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::EventMetaData
Store event, run, and experiment numbers.
Definition: EventMetaData.h:43
Belle2::ProcessedEventsBackupList::Duration
std::chrono::milliseconds Duration
Short for the class of a duration (always measured in milliseconds)
Definition: ProcessedEventsBackupList.h:36
Belle2::ProcessedEventsBackupList::size
unsigned int size() const
Check the size.
Definition: ProcessedEventsBackupList.cc:45
Belle2::ProcessedEventsBackupList::storeEvent
void storeEvent(std::unique_ptr< EvtMessage > evtMsg, const StoreObjPtr< EventMetaData > &evtMetaData, const unsigned int workerId)
Add a new event backup with the given information. Takes ownership of the evt message.
Definition: ProcessedEventsBackupList.cc:14