2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
5 #include "AthenaBaseComps/AthCheckMacros.h"
7 /////////////////////////////////////////////////////////////////////////////
9 template<typename PAYLOAD>
10 StatusCode TrigCostDataStore<PAYLOAD>::initialize(size_t nSlots) {
11 m_store.resize( nSlots, tbb::concurrent_hash_map< AlgorithmIdentifier, PAYLOAD, AlgorithmIdentifierHashCompare>() );
12 return StatusCode::SUCCESS;
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
17 template<typename PAYLOAD>
18 StatusCode TrigCostDataStore<PAYLOAD>::insert(const AlgorithmIdentifier& ai, const PAYLOAD& payload,
20 ATH_CHECK( checkSlot(ai.m_slotToSaveInto, msg) );
21 tbb::concurrent_hash_map<AlgorithmIdentifier, PAYLOAD, AlgorithmIdentifierHashCompare>& mapReference = m_store.at( ai.m_slotToSaveInto );
22 typename tbb::concurrent_hash_map< AlgorithmIdentifier, PAYLOAD, AlgorithmIdentifierHashCompare>::accessor acc;
23 if (mapReference.insert(acc, ai)) {
24 // Obtains lock on the key value 'name' until 'acc' goes out of scope or calls release()
25 acc->second = payload;
26 } else if (msg.level() <= MSG::DEBUG) {
27 msg << MSG::DEBUG << "Key caller:'" << ai.m_caller << "' store:'" << ai.m_store
28 << "' slot:" << ai.m_realSlot <<" already in the TrigCostDataStore" << endmsg;
30 return StatusCode::SUCCESS;
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
35 template<typename PAYLOAD>
36 template<typename ENTRY>
37 StatusCode TrigCostDataStore<PAYLOAD>::push_back(const AlgorithmIdentifier& ai, ENTRY&& entry,
39 ATH_CHECK( checkSlot(ai.m_slotToSaveInto, msg) );
40 tbb::concurrent_hash_map<AlgorithmIdentifier, std::vector<ENTRY>, AlgorithmIdentifierHashCompare>& mapReference = m_store.at( ai.m_slotToSaveInto );
41 typename tbb::concurrent_hash_map< AlgorithmIdentifier, std::vector<ENTRY>, AlgorithmIdentifierHashCompare>::accessor acc;
43 // Adds new value to store entries. If the AI is already there function will return false
44 // and duplicate will not be added. Otherwise new payload will be created
45 // Also obtains write lock on the key value 'name' until 'acc' goes out of scope
46 mapReference.insert(acc, ai);
47 acc->second.push_back(std::move(entry));
49 return StatusCode::SUCCESS;
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
54 template<typename PAYLOAD>
55 StatusCode TrigCostDataStore<PAYLOAD>::retrieve(const AlgorithmIdentifier& ai,
56 typename tbb::concurrent_hash_map<AlgorithmIdentifier, PAYLOAD, AlgorithmIdentifierHashCompare>::const_accessor& payload,
59 ATH_CHECK( checkSlot(ai.m_slotToSaveInto, msg) );
60 const tbb::concurrent_hash_map< AlgorithmIdentifier, PAYLOAD, AlgorithmIdentifierHashCompare>& mapReference = m_store.at( ai.m_slotToSaveInto );
61 if (!mapReference.find(payload, ai)) {
62 if (msg.level() <= MSG::DEBUG) {
63 msg << MSG::DEBUG << "Cannot access key caller:'" << ai.m_caller << "' store:'" << ai.m_store
64 << "' slot:" << ai.m_realSlot << " from the the TrigCostDataStore" << endmsg;
66 return StatusCode::FAILURE;
68 return StatusCode::SUCCESS;
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
74 template<typename PAYLOAD>
75 StatusCode TrigCostDataStore<PAYLOAD>::clear(const EventContext& context, MsgStream& msg) {
76 ATH_CHECK( checkSlot(context.slot(), msg) );
77 tbb::concurrent_hash_map<AlgorithmIdentifier, PAYLOAD, AlgorithmIdentifierHashCompare>& mapReference = m_store.at( context.slot() );
79 if (msg.level() <= MSG::DEBUG) msg << MSG::DEBUG << "Clearing slot " << context.slot() << endmsg;
80 return StatusCode::SUCCESS;
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
85 template<typename PAYLOAD>
86 StatusCode TrigCostDataStore<PAYLOAD>::getIterators(const EventContext& context, MsgStream& msg,
87 typename tbb::concurrent_hash_map<AlgorithmIdentifier, PAYLOAD, AlgorithmIdentifierHashCompare>::const_iterator& begin,
88 typename tbb::concurrent_hash_map<AlgorithmIdentifier, PAYLOAD, AlgorithmIdentifierHashCompare>::const_iterator& end) {
89 ATH_CHECK( checkSlot(context.slot(), msg) );
90 const tbb::concurrent_hash_map<AlgorithmIdentifier, PAYLOAD, AlgorithmIdentifierHashCompare>& mapReference = m_store.at( context.slot() );
91 begin = mapReference.begin();
92 end = mapReference.end();
93 return StatusCode::SUCCESS;
96 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
98 template<typename PAYLOAD>
99 StatusCode TrigCostDataStore<PAYLOAD>::checkSlot(const size_t slot, MsgStream& msg) const {
100 if (m_store.size() <= slot) {
101 msg << MSG::FATAL << "Requesting slot " << slot << " but we only reserved for " << m_store.size() << " slots. Make sure setSlots() was called." << endmsg;
102 return StatusCode::FAILURE;
104 return StatusCode::SUCCESS;