ATLAS Offline Software
Loading...
Searching...
No Matches
SG::HiveMgrSvc Class Reference

#include <SGHiveMgrSvc.h>

Inheritance diagram for SG::HiveMgrSvc:
Collaboration diagram for SG::HiveMgrSvc:

Public Member Functions

virtual StatusCode selectStore (size_t slotIndex) override
 Activate an given 'slot' for all subsequent calls within the same thread id.
virtual StatusCode clearStore (size_t slotIndex) override
 Clear a given 'slot'.
virtual StatusCode setNumberOfStores (size_t slots) override
 Set the number of 'slots'.
virtual size_t getNumberOfStores () const override
 Get the number of 'slots'.
virtual bool exists (const DataObjID &) override
 Check if a data object exists in store.
virtual size_t allocateStore (int evtnumber) override
 Allocate a store slot for new event.
virtual StatusCode freeStore (size_t slotIndex) override
 Free a store slot.
virtual size_t getPartitionNumber (int eventnumber) const override
 Get the slot number corresponding to a given event.
virtual size_t freeSlots () override
 Get free slots number.
virtual StatusCode initialize () override
virtual StatusCode finalize () override
virtual StatusCode start () override
 HiveMgrSvc (const std::string &name, ISvcLocator *svc)
 Standard Service Constructor. sets active store to default event store.
virtual ~HiveMgrSvc ()

Static Private Member Functions

static void setNumProcs (size_t numProcs)
 Set number of concurrent processes.

Private Attributes

ServiceHandle< StoreGateSvc > m_hiveStore
size_t m_nSlots
std::vector< SG::HiveEventSlot > m_slots
std::mutex m_mutex
std::atomic< size_t > m_freeSlots {0}

Friends

class TestSGHiveMgrSvc
class ::HltEventLoopMgr

Detailed Description

Definition at line 30 of file SGHiveMgrSvc.h.

Constructor & Destructor Documentation

◆ HiveMgrSvc()

HiveMgrSvc::HiveMgrSvc ( const std::string & name,
ISvcLocator * svc )

Standard Service Constructor. sets active store to default event store.

Definition at line 18 of file SGHiveMgrSvc.cxx.

19 : base_class(name, svc),
21 m_nSlots(1)
22{
23 declareProperty("HiveStoreSvc", m_hiveStore);
24 declareProperty("NSlots", m_nSlots, "number of event slots");
25}
ServiceHandle< StoreGateSvc > m_hiveStore
@ EVENT_STORE
Definition StoreID.h:26
static const std::string & storeName(const StoreID::type &s)
Definition StoreID.cxx:77

◆ ~HiveMgrSvc()

virtual SG::HiveMgrSvc::~HiveMgrSvc ( )
inlinevirtual

Definition at line 106 of file SGHiveMgrSvc.h.

106{}

Member Function Documentation

◆ allocateStore()

size_t HiveMgrSvc::allocateStore ( int evtNumber)
overridevirtual

Allocate a store slot for new event.

Parameters
evtnumber[IN] Event number
slot[OUT] Returned slot or slot number
Returns
Slot number (npos to indicate an error).

Definition at line 103 of file SGHiveMgrSvc.cxx.

103 {
104 if (m_freeSlots == 0) {
105 SG_MSG_ERROR ("No slots available for event number {}", evtNumber);
106 return std::string::npos;
107 }
108 std::scoped_lock lock{m_mutex};
109 for (size_t index=0; index<m_nSlots; ++index) {
110 if( m_slots[index].eventNumber == evtNumber) {
111 SG_MSG_ERROR ("Attempt to allocate an event slot for an event that is still active: event number {}", evtNumber);
112 return std::string::npos;
113 } else if (m_slots[index].eventNumber == -1) {
114 m_slots[index].eventNumber = evtNumber;
115 SG_MSG_DEBUG ("Slot {} allocated to event number {}", index, evtNumber);
116 m_freeSlots--;
117 return index;
118 }
119 }
120 SG_MSG_ERROR ("No slots available for event number {}", evtNumber);
121 return std::string::npos;
122}
#define SG_MSG_DEBUG(x,...)
#define SG_MSG_ERROR(x,...)
std::atomic< size_t > m_freeSlots
std::mutex m_mutex
std::vector< SG::HiveEventSlot > m_slots
size_t index() const
Return the index of this element within its container.
virtual void lock() override
Lock the container.

◆ clearStore()

StatusCode HiveMgrSvc::clearStore ( size_t slotIndex)
overridevirtual

Clear a given 'slot'.

Parameters
slot[IN] Slot number (event slot) *
Returns
Status code indicating failure or success.

Definition at line 58 of file SGHiveMgrSvc.cxx.

58 {
59 StatusCode rc(StatusCode::FAILURE);
60 if (slotIndex < m_nSlots) {
61 rc=m_slots[slotIndex].pEvtStore->clearStore();
62 if (rc.isSuccess()) {
63 SG_MSG_DEBUG ("cleared store {}", slotIndex);
64 }
65 }
66 if (!rc.isSuccess()) {
67 SG_MSG_ERROR ("could not clear store {}", slotIndex);
68 }
69 return rc;
70}
static Double_t rc
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ exists()

bool HiveMgrSvc::exists ( const DataObjID & id)
overridevirtual

Check if a data object exists in store.

TODO: remove the method ASA a cross-experiment event data store interface emerges

Returns
boolean

Definition at line 165 of file SGHiveMgrSvc.cxx.

165 {
166 // this should only get called in error situations, so we
167 // don't care if it's slow
168 std::string key = id.key();
169 key.erase(0,key.find('+')+1);
170
171 if (id.clid() == 0) {
172 // this is an ugly hack in case the DataObjID gets munged
173 // upstream, and we have to re-separate it into (class,key)
174 // from "class/key"
175 std::string cl = id.fullKey();
176 cl.erase(cl.find('/'),cl.length());
177
178 DataObjID d2(std::move(cl),key);
179 return m_hiveStore->transientContains(d2.clid(), key);
180 } else {
181 return m_hiveStore->transientContains(id.clid(), key);
182 }
183
184}
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ finalize()

StatusCode HiveMgrSvc::finalize ( )
overridevirtual

Definition at line 224 of file SGHiveMgrSvc.cxx.

224 {
225 SG_MSG_INFO ("Finalizing {}", name());
226
227 for (SG::HiveEventSlot& s : m_slots) {
228 // The impl services are not set to active, so ServiceManager
229 // won't finalize them.
230 CHECK( s.pEvtStore->finalize() );
231 s.pEvtStore->release();
232 }
233
234 return StatusCode::SUCCESS;
235}
#define CHECK(...)
Evaluate an expression and check for errors.
#define SG_MSG_INFO(x,...)

◆ freeSlots()

size_t HiveMgrSvc::freeSlots ( )
overridevirtual

Get free slots number.

Definition at line 161 of file SGHiveMgrSvc.cxx.

161 {
162 return m_freeSlots;
163}

◆ freeStore()

StatusCode HiveMgrSvc::freeStore ( size_t slotIndex)
overridevirtual

Free a store slot.

Parameters
slot[IN] Slot number
Returns
Status code indicating failure or success.

Definition at line 129 of file SGHiveMgrSvc.cxx.

129 {
130 if (slotIndex < m_nSlots) {
131 std::scoped_lock lock{m_mutex};
132 if (m_slots[slotIndex].eventNumber == -1) {
133 SG_MSG_DEBUG ("Slot {} is already free", slotIndex);
134 }
135 else {
136 m_slots[slotIndex].eventNumber = -1;
137 m_freeSlots++;
138 SG_MSG_DEBUG ("Freed slot {}", slotIndex);
139 }
140 return StatusCode::SUCCESS;
141 } else {
142 SG_MSG_ERROR ("no slot at {}", slotIndex);
143 return StatusCode::FAILURE;
144 }
145}

◆ getNumberOfStores()

size_t HiveMgrSvc::getNumberOfStores ( ) const
overridevirtual

Get the number of 'slots'.

Returns
Number of event stores allocated in the whiteboard

Definition at line 91 of file SGHiveMgrSvc.cxx.

91 {
92 return m_nSlots;
93}

◆ getPartitionNumber()

size_t HiveMgrSvc::getPartitionNumber ( int evtNumber) const
overridevirtual

Get the slot number corresponding to a given event.

Parameters
evtnumber[IN] Event number
Returns
slot number (npos to indicate an error).
Parameters
evtNumber[IN] Event number
Returns
slot number (npos to indicate an error).

Definition at line 153 of file SGHiveMgrSvc.cxx.

153 {
154 std::scoped_lock lock{m_mutex};
155 for (size_t index=0; index<m_nSlots; ++index) {
156 if( m_slots[index].eventNumber == evtNumber) return index;
157 }
158 return std::string::npos;
159}

◆ initialize()

StatusCode HiveMgrSvc::initialize ( )
overridevirtual

Definition at line 186 of file SGHiveMgrSvc.cxx.

186 {
187 SG_MSG_VERBOSE ("Initializing {}", name());
188
189 if ( !(Service::initialize().isSuccess()) ) {
190 SG_MSG_FATAL ("Unable to initialize base class");
191 return StatusCode::FAILURE;
192 }
193 //this sets the hiveStore pointer to StoreGateSvc.defaultStore
194 if (!(m_hiveStore.retrieve()).isSuccess()) {
195 SG_MSG_FATAL ("Unable to get hive event store");
196 return StatusCode::FAILURE;
197 }
198
199 //use hiveStore default impl store as prototype
200 Service* child(0);
201 SGImplSvc* pSG(0);
202
203 for( size_t i = 0; i< m_nSlots; ++i) {
204 std::ostringstream oss;
205 std::print (oss, "{}_{}", i, m_hiveStore->currentStore()->name());
206 if (CloneService::clone(m_hiveStore->currentStore(), oss.str(), child).isSuccess() &&
207 child->initialize().isSuccess() &&
208 0 != (pSG = dynamic_cast<SGImplSvc*>(child)) )
209 {
210 pSG->setSlotNumber (i, m_nSlots);
211 m_slots.push_back(SG::HiveEventSlot(pSG));
212 } else {
213 SG_MSG_FATAL ("Unable to clone event store {}", oss.str());
214 return StatusCode::FAILURE;
215 }
216 }
217
218 m_freeSlots.store( m_nSlots );
219 Gaudi::Concurrency::ConcurrencyFlags::setNumConcEvents( m_nSlots );
220
221 return selectStore(0);
222}
#define SG_MSG_VERBOSE(x,...)
#define SG_MSG_FATAL(x,...)
virtual StatusCode selectStore(size_t slotIndex) override
Activate an given 'slot' for all subsequent calls within the same thread id.
StatusCode clone(const IService *parent, const std::string &childName, Service *&child)
given a reference to a parent svc sets a reference to a cloned child

◆ selectStore()

StatusCode HiveMgrSvc::selectStore ( size_t slotIndex)
overridevirtual

Activate an given 'slot' for all subsequent calls within the same thread id.

Parameters
slot[IN] Slot number (event slot) *
Returns
Status code indicating failure or success.

Definition at line 47 of file SGHiveMgrSvc.cxx.

47 {
48 s_current = &m_slots[slotIndex];
50 return StatusCode::SUCCESS;
51}
__thread HiveEventSlot * s_current(0)
static void setSlot(SG::HiveEventSlot *pSlot)
set the hive event slot pointer: used by the event loop mgrs

◆ setNumberOfStores()

StatusCode HiveMgrSvc::setNumberOfStores ( size_t slots)
overridevirtual

Set the number of 'slots'.

Parameters
slot[IN] Slot number (event slot) *
Returns
Status code indicating failure or success.

Definition at line 77 of file SGHiveMgrSvc.cxx.

77 {
78 //FIXME what if running?
79 if(FSMState() == Gaudi::StateMachine::INITIALIZED) {
80 SG_MSG_FATAL ("Too late to change the number of slots!");
81 return StatusCode::FAILURE;
82 } else {
83 m_slots.resize(slots);
84 m_nSlots = slots;
85 m_freeSlots.store(slots);
86 Gaudi::Concurrency::ConcurrencyFlags::setNumConcEvents( slots );
87 return StatusCode::SUCCESS;
88 }
89}

◆ setNumProcs()

void HiveMgrSvc::setNumProcs ( size_t numProcs)
staticprivate

Set number of concurrent processes.

This can only be called by "friends" of this class. Its sole purpose is to have a common entry point within ATLAS to call the private methods of Gaudi::ConcurrencyFlags.

Parameters
numProcs[IN] Number of concurrent processes

Definition at line 36 of file SGHiveMgrSvc.cxx.

37{
38 Gaudi::Concurrency::ConcurrencyFlags::setNumProcs(numProcs);
39}

◆ start()

StatusCode HiveMgrSvc::start ( )
overridevirtual

Definition at line 238 of file SGHiveMgrSvc.cxx.

239{
240 // On a start transition, merge the string pool from the default store
241 // into that of each store, so that they will know about any explicit
242 // registrations that were done during initialize().
243 // See ATEAM-846.
244 for (SG::HiveEventSlot& slot : m_slots) {
245 slot.pEvtStore->mergeStringPool (*m_hiveStore->currentStore());
246 }
247 return StatusCode::SUCCESS;
248}

◆ ::HltEventLoopMgr

friend class ::HltEventLoopMgr
friend

Definition at line 32 of file SGHiveMgrSvc.h.

◆ TestSGHiveMgrSvc

friend class TestSGHiveMgrSvc
friend

Definition at line 31 of file SGHiveMgrSvc.h.

Member Data Documentation

◆ m_freeSlots

std::atomic<size_t> SG::HiveMgrSvc::m_freeSlots {0}
private

Definition at line 123 of file SGHiveMgrSvc.h.

123{0};

◆ m_hiveStore

ServiceHandle<StoreGateSvc> SG::HiveMgrSvc::m_hiveStore
private

Definition at line 119 of file SGHiveMgrSvc.h.

◆ m_mutex

std::mutex SG::HiveMgrSvc::m_mutex
mutableprivate

Definition at line 122 of file SGHiveMgrSvc.h.

◆ m_nSlots

size_t SG::HiveMgrSvc::m_nSlots
private

Definition at line 120 of file SGHiveMgrSvc.h.

◆ m_slots

std::vector<SG::HiveEventSlot> SG::HiveMgrSvc::m_slots
private

Definition at line 121 of file SGHiveMgrSvc.h.


The documentation for this class was generated from the following files: