Belle II Software  release-05-01-25
ProcessedEventsBackupList.h
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 #pragma once
11 
12 #include <framework/pcore/zmq/processModules/ProcessedEventBackup.h>
13 #include <framework/dataobjects/EventMetaData.h>
14 #include <framework/pcore/EvtMessage.h>
15 #include <framework/datastore/StoreObjPtr.h>
16 #include <memory>
17 #include <chrono>
18 
19 
20 namespace Belle2 {
25  class ProcessedEventsBackupList {
28  using Duration = std::chrono::milliseconds;
29 
30  public:
32  void storeEvent(std::unique_ptr<EvtMessage> evtMsg, const StoreObjPtr<EventMetaData>& evtMetaData, const unsigned int workerId);
33 
35  void removeEvent(const EventMetaData& evtMetaData);
36 
38  int checkForTimeout(const Duration& timeout) const;
39 
41  template <class AZMQClient>
42  void sendWorkerBackupEvents(unsigned int worker, const AZMQClient& socket);
43 
45  unsigned int size() const;
46 
47  private:
49  std::vector<ProcessedEventBackup> m_evtBackupVector;
50  };
51 
52  template <class AZMQClient>
53  void ProcessedEventsBackupList::sendWorkerBackupEvents(unsigned int worker, const AZMQClient& socket)
54  {
55  for (auto it = m_evtBackupVector.begin(); it != m_evtBackupVector.end();) {
56  if (it->getWorkerId() == worker) {
57  B2DEBUG(100, "Delete event: " << it->getEventMetaData().getEvent());
58  it->sendToSocket(socket);
59  // TODO: better: delete backup on confirmation message
60  m_evtBackupVector.erase(it);
61  B2DEBUG(100, "new backup list size: " << m_evtBackupVector.size());
62  } else {
63  it++;
64  }
65  }
66  }
68 }
Belle2::ProcessedEventsBackupList::removeEvent
void removeEvent(const EventMetaData &evtMetaData)
Remove all backups with the given event meta data (on confirmation)
Definition: ProcessedEventsBackupList.cc:21
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::ProcessedEventsBackupList::sendWorkerBackupEvents
void sendWorkerBackupEvents(unsigned int worker, const AZMQClient &socket)
Send all backups of a given worker directly to the multicast and delete them.
Definition: ProcessedEventsBackupList.h:61
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