The Gaudi Framework  master (da3d77e1)
EventSlot.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef EVENTSLOT_H_
12 #define EVENTSLOT_H_
13 
14 // Framework includes
15 #include "AlgsExecutionStates.h"
17 
18 #include <string>
19 #include <tuple>
20 #include <unordered_map>
21 #include <vector>
22 
24 struct EventSlot {
26  EventSlot( unsigned int numberOfAlgorithms, unsigned int numberOfControlFlowNodes, SmartIF<IMessageSvc> MS )
27  : algsStates( numberOfAlgorithms, MS ), controlFlowState( numberOfControlFlowNodes, -1 ) {}
28 
30  EventSlot( const EventSlot& ) = delete;
32  EventSlot& operator=( const EventSlot& ) = delete;
34  EventSlot( EventSlot&& ) = default;
36  EventSlot& operator=( EventSlot&& ) = default;
37 
39  EventSlot( EventSlot& original, std::unique_ptr<EventContext> theeventContext, const std::string& nodeName )
40  : eventContext( std::move( theeventContext ) )
41  , algsStates( original.algsStates )
43  , entryPoint( nodeName )
44  , parentSlot( &original ) {
45  algsStates.reset();
46  }
47 
49  void reset( EventContext* theeventContext ) {
50  eventContext.reset( theeventContext );
51  algsStates.reset();
53  complete = false;
54  entryPoint.clear();
55  parentSlot = nullptr;
58  }
59 
61  void addSubSlot( std::unique_ptr<EventContext> viewContext, const std::string& nodeName ) {
62  unsigned int lastIndex = allSubSlots.size();
63 
64  auto search = subSlotsByNode.find( nodeName );
65  if ( search != subSlotsByNode.end() )
66  subSlotsByNode[nodeName].push_back( lastIndex );
67  else
68  subSlotsByNode.emplace( std::piecewise_construct, std::forward_as_tuple( nodeName ),
69  std::forward_as_tuple( 1, lastIndex ) );
70 
71  // Make new slot and nest it into the top slot
72  viewContext->setSubSlot( lastIndex );
73  allSubSlots.emplace_back( *this, std::move( viewContext ), nodeName );
74  }
75 
78  void disableSubSlots( const std::string& nodeName ) {
79  subSlotsByNode.emplace( std::piecewise_construct, std::forward_as_tuple( nodeName ), std::forward_as_tuple() );
80  }
81 
89  bool complete = false;
90 
92 
96  EventSlot* parentSlot = nullptr;
101 };
102 
103 #endif /* EVENTSLOT_H_ */
EventSlot::EventSlot
EventSlot(EventSlot &original, std::unique_ptr< EventContext > theeventContext, const std::string &nodeName)
Construct a (sub)slot, nested to 'original' parent slot, with CF states copied from the parent.
Definition: EventSlot.h:39
EventSlot::eventContext
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
Definition: EventSlot.h:83
std::string
STL class.
std::move
T move(T... args)
EventSlot::subSlotsByNode
std::unordered_map< std::string, std::vector< unsigned int > > subSlotsByNode
Listing of sub-slots by the node (name) they are attached to.
Definition: EventSlot.h:98
EventContext::setSubSlot
void setSubSlot(const ContextID_t subslot)
Definition: EventContext.h:75
std::vector< int >
std::unordered_map::find
T find(T... args)
std::vector::size
T size(T... args)
EventSlot
Class representing an event slot.
Definition: EventSlot.h:24
AlgsExecutionStates
Definition: AlgsExecutionStates.h:38
std::unordered_map::emplace
T emplace(T... args)
AlgsExecutionStates.h
std::unique_ptr::reset
T reset(T... args)
std::string::clear
T clear(T... args)
EventSlot::entryPoint
std::string entryPoint
Event Views bookkeeping (TODO: optimize view bookkeeping)
Definition: EventSlot.h:94
EventSlot::complete
bool complete
Flags completion of the event.
Definition: EventSlot.h:89
EventSlot::EventSlot
EventSlot(const EventSlot &)=delete
Copy constructor.
EventSlot::addSubSlot
void addSubSlot(std::unique_ptr< EventContext > viewContext, const std::string &nodeName)
Add a subslot to the slot (this constructs a new slot and registers it with the parent one)
Definition: EventSlot.h:61
EventSlot::parentSlot
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:96
EventSlot::EventSlot
EventSlot(EventSlot &&)=default
Move constructor.
EventSlot::EventSlot
EventSlot(unsigned int numberOfAlgorithms, unsigned int numberOfControlFlowNodes, SmartIF< IMessageSvc > MS)
Construct a slot.
Definition: EventSlot.h:26
EventSlot::reset
void reset(EventContext *theeventContext)
Reset all resources in order to reuse the slot (thread-unsafe)
Definition: EventSlot.h:49
EventSlot::disableSubSlots
void disableSubSlots(const std::string &nodeName)
Disable event views for a given CF view node by registering an empty container Contact B.
Definition: EventSlot.h:78
EventSlot::allSubSlots
std::vector< EventSlot > allSubSlots
Actual sub-slot instances.
Definition: EventSlot.h:100
SmartIF< IMessageSvc >
AlgsExecutionStates::reset
void reset()
Definition: AlgsExecutionStates.h:63
std::forward_as_tuple
T forward_as_tuple(T... args)
EventSlot::operator=
EventSlot & operator=(const EventSlot &)=delete
Assignment operator.
std::vector::emplace_back
T emplace_back(T... args)
EventContext.h
std
STL namespace.
EventContext
Definition: EventContext.h:34
std::vector::assign
T assign(T... args)
EventSlot::controlFlowState
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:87
std::unordered_map::end
T end(T... args)
std::unique_ptr< EventContext >
std::unordered_map
STL class.
EventSlot::algsStates
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:85
EventSlot::operator=
EventSlot & operator=(EventSlot &&)=default
Move assignment.