9#include "GaudiKernel/IConversionSvc.h"
22#include <unordered_map>
29std::ostream&
operator<<( std::ostream&
s,
const std::vector<T>& v)
31 s<<
"[";
for(
auto i:v){
s << i <<
", ";}
s <<
"]";
60bool NavigationCore::extractBlob(
const std::vector<uint32_t>& input, std::vector<uint32_t>::const_iterator& it, std::vector<uint32_t>& blob)
const {
62 if ( it == input.end() )
65 unsigned sizeOfBlob = *it;
66 std::vector<uint32_t>::const_iterator begin = it;
68 std::vector<uint32_t>::const_iterator end = it;
70 advance(end, sizeOfBlob);
71 if ( end <= input.end()) {
72 blob.reserve(end-begin);
73 blob.insert(blob.end(), begin, end);
82 std::vector<unsigned int> cuts;
87 std::vector<std::pair<CLID, std::string> > clid_name;
89 return serialize(output, cuts, clid_name);
92bool NavigationCore::serialize( std::vector<uint32_t>& output, std::vector<unsigned int>& cuts, std::vector<std::pair<CLID, std::string> >& clid_name )
const {
93 std::vector<uint32_t> holderdata;
94 std::vector<unsigned int> holderblobsizes;
96 std::lock_guard<std::recursive_mutex> lock(
getMutex());
118 ATH_MSG_DEBUG(
"total size of serialized navigation: " << output.size());
124 std::vector<uint32_t> holderdata;
125 std::vector<unsigned int> holderblobsizes;
139 ATH_MSG_DEBUG(
"total size of serialized navigation (DS only): " << output.size());
152 std::lock_guard<std::recursive_mutex> lock(
getMutex());
155 std::vector<uint32_t>::const_iterator inputIt = input.begin();
157 ATH_MSG_DEBUG(
"deserialize: deserializing input of size: " << input.size());
160 if (input.size()==0) {
164 unsigned int version = *inputIt++;
166 ATH_MSG_DEBUG(
"deserialize: the serialized input has versions " << version);
168 if ( version != 3 and version !=4 ) {
169 ATH_MSG_WARNING(
"No backward compatibility beyond version 3 possible; data was serialized with V: " << version
170 <<
" while we are in version 4");
173 ATH_MSG_DEBUG(
"deserialize: deserialization of Navigation version: " << version);
177 ATH_MSG_WARNING(
"deserialize: the navigation is truncated: " << input.size()
180 if ( input.size() == 2 ) {
181 ATH_MSG_WARNING(
"deserialize: the navigation is truncated badly, no recovery possible " );
185 bool tesDeserializationStatus =
deserializeTEs(inputIt,input.size());
186 ATH_MSG_DEBUG(
"deserialize: TEs structure unpacked, status: " << tesDeserializationStatus );
189 ATH_MSG_DEBUG(
"do we have holder payload? " << (inputIt != input.end()));
192 struct DeserializedMemo
195 EventContext::ContextEvt_t m_evt;
196 std::unordered_map<uint64_t, std::shared_ptr<HLT::BaseHolder>> m_holders;
200 const EventContext& ctx = Gaudi::Hive::currentContext();
201 DeserializedMemo& memo = *memos.get (ctx);
202 std::scoped_lock memolock (memo.m_mutex);
203 if (memo.m_evt != ctx.evt()) {
204 memo.m_holders.clear();
205 memo.m_evt = ctx.evt();
210 std::vector<uint32_t>::const_iterator it = inputIt;
211 std::vector<uint32_t> blob;
215 uint64_t hash =
CxxUtils::crc64 (
reinterpret_cast<const char*
>(blob.data()),
216 blob.size()*
sizeof(*blob.data()));
218 auto& holder = memo.m_holders[hash];
220 ATH_MSG_DEBUG(
"deserializing holder blob with size/hash " << blob.size() <<
"/" << hash);
221 holder = std::shared_ptr<HLT::BaseHolder>(
m_holderfactory->fromSerialized(version,blob.begin(),blob.end()));
222 if (! holder )
continue;
224 ATH_MSG_DEBUG(
"blob with size/hash " << blob.size() <<
"/" << hash
225 <<
" already deserialized; re-using holder");
229 ATH_MSG_WARNING(
"deserialize: holder registration for holder with clid: " << holder->typeClid() <<
" and label: " << holder->label() <<
" failed.");
236 std::lock_guard<std::recursive_mutex> l2lock(l2.getMutex());
242 std::string
label(l2holder->label());
244 if ( efholder != 0 ) {
245 if ( (efholder->
label() != l2holder->label())
246 || (efholder->
subTypeIndex() != l2holder->subTypeIndex()) ) {
260 bool status =
createHolder(efholder, l2holder->
typeClid(),l2holder->label(), l2holder->subTypeIndex());
266 if(efholder->
key()!=l2holder->key()){
267 ATH_MSG_WARNING(
"in merge the created EF holder has different SG access key than L2 holder we tried to copy");
288 std::lock_guard<std::recursive_mutex> lock(
getMutex());
293 if ( holders.empty() )
296 std::vector<sub_index_type> sub_indices(holders.size());
297 std::transform(holders.begin(), holders.end(), sub_indices.begin(),
300 return (*std::max_element(sub_indices.begin(),sub_indices.end()))+1;
305 ATH_MSG_VERBOSE(
"NavigationCore::prepare preregistering objects of clid: " << clid <<
" label: " <<
label);
308 ATH_MSG_VERBOSE(
"NavigationCore::prepare preregistering objects not executed as it already exists " << *holder);
313 ATH_MSG_VERBOSE(
"NavigationCore::prepare creating handler for type (CLID): " << clid
314 <<
" label: " <<
label <<
" index: " <<
index);
317 ATH_MSG_INFO(
"NavigationCore::prepare Can't create storage for objects of CLID: " << clid <<
" as it is requested by configuration");
321 ATH_MSG_VERBOSE(
"Holder created, registering " << holder <<
" " << *holder);
324 ATH_MSG_WARNING(
"Holder registration failed " << holder <<
" " << *holder);
336 if (
msgLvl(MSG::VERBOSE) ) {
338 ATH_MSG_VERBOSE(
"NavigationCore::prepare Compile time known types : " << *holder);
346 CLID clid = conf.first;
347 std::string
label = conf.second;
349 ATH_MSG_WARNING(
"NavigationCore::prepare failed preparing the holder for CLID: " << clid <<
" and label " <<
label);
352 ATH_MSG_DEBUG(
"NavigationCore::prepare Navigation structure prepared for next event");
356 std::lock_guard<std::recursive_mutex> lock(
getMutex());
359 auto shared_holder = std::shared_ptr<HLT::BaseHolder>(holder);
366 ATH_MSG_DEBUG(
"createHolder: creating holder for CLID: " << clid <<
" label: " <<
label <<
" and index: " <<
index);
371 ATH_MSG_ERROR(
"createHolder: creation of holder for CLID: " << clid <<
" label: " <<
label <<
" and index: " <<
index <<
" failed");
374 holder =
dynamic_cast<IHolder*
>(baseholder);
384 std::lock_guard<std::recursive_mutex> lock(
getMutex());
391 std::lock_guard<std::recursive_mutex> lock(
getMutex());
402 const bool activeOnly)
const {
404 return getAll(output, activeOnly);
412 bool only_single_feature,
414 bool travel_backward_recursively,
416 std::string& sourcelabel)
const {
423 bool only_single_feature,
426 std::string& sourcelabel )
const {
431 if(index_or_label.index() == 0)
return status;
437 std::vector<unsigned int>& cuts ,std::vector<std::pair<CLID, std::string> >& )
const {
441 unsigned int version=4;
442 ATH_MSG_DEBUG(
"NavigationCore::serialize: serializing with version " << version);
444 output.push_back(version);
446 unsigned int totalSizeIndex = output.size();
450 cuts.push_back(output.size());
454 ATH_MSG_DEBUG(
"serializes: TE serialization status: " << tesSerializationStatus <<
" size: " << output.size());
456 cuts.push_back(output.size());
458 output.insert(output.end(),holderdata.begin(),holderdata.end());
460 for(
auto hc : holderblobsizes){cuts.push_back(cuts.back()+hc);}
462 output[totalSizeIndex] = output.size();
469 std::vector<uint32_t>& holderblobsizes,
470 std::vector<std::pair<CLID, std::string> >& clid_name)
const {
472 ATH_MSG_DEBUG(
"serialization: number of classes to payload: " << payload.size());
473 for (
auto& cl : payload) {
474 ATH_MSG_DEBUG(
"serialization (ordered) of featue attempting : " << cl.first <<
" " << cl.second);
478 ATH_MSG_DEBUG(
"serialization (ordered) of feature skipped, nothing know on this objects" );
482 <<
" size of payload up to now: " << output.size());
484 std::vector<uint32_t> holderblob;
485 size_t payloadsize = 0;
492 output.push_back(holderblob.size());
493 output.insert(output.end(),holderblob.begin(),holderblob.end());
495 holderblobsizes.push_back(1+holderblob.size());
496 clid_name.push_back(std::pair < CLID, std::string> (holder->
typeClid(), holder->
label()));
503 for(
auto& holder : holders){
504 ATH_MSG_DEBUG(
"serialization of feature: " << holder->typeClid() <<
" label: " << holder->label()
505 <<
" size of payload: " << output.size());
507 std::vector<uint32_t> holderblob;
508 bool status = holder->serialize(holderblob);
513 output.push_back(holderblob.size());
514 output.insert(output.end(),holderblob.begin(),holderblob.end());
516 holderblobsizes.push_back(1+holderblob.size());
517 clid_name.push_back(std::pair < CLID, std::string> (holder->typeClid(), holder->label()));
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Maintain a set of objects, one per slot.
uint32_t CLID
The Class ID type.
static unsigned int totalSize(const MultiDimArray< T, N > &ht)
std::ostream & operator<<(std::ostream &s, const std::vector< T > &v)
Define macros for attributes used to control the static checker.
virtual const std::string & key() const =0
returns the containers StoreGate key
bool serializeWithPayload(const xAOD::AuxSelection &sel, std::vector< uint32_t > &output, size_t &payloadsize)
serializes this Holder including payload
virtual bool syncWithSG(SG::OwnershipPolicy policy=SG::OWN_ELEMENTS)=0
const std::string & label() const
returns the label of objects stores by this holder
virtual CLID typeClid() const =0
returns the CLID of objects stores by this holder
uint16_t subTypeIndex() const
returns the index (short number used when linking object to the TE) of objects stores by this holder
The NavigationCore class, adds on top of the TrigNavStructure the EDM read-only handling.
bool registerHolder(HLTNavDetails::IHolder *holder)
NavigationCore(const AthAlgTool &logger)
constructor with parent AlgTool for printing
ITrigHolderFactory * m_holderfactory
uint16_t nextSubTypeIndex(CLID clid, const std::string &label) const
bool extractBlob(const std::vector< uint32_t > &input, std::vector< uint32_t >::const_iterator &it, std::vector< uint32_t > &blob) const
const AthAlgTool & m_logger
std::vector< CSPair > m_classesToPayload_DSonly
classess are put to payload according to that priority list (CLID + key)
static uint32_t string2hash(const std::string &, const std::string &category="TE")
convert strin g to hash.
HLTNavDetails::Holder< T > * getHolder(uint16_t subTypeIndex) const
as above but does not create holder on demand (return 0 if not found)
virtual void reset(bool inFinalize=false)
resets all the navigation, goes to the factory and asks to withdraw all produced objects
IConversionSvc * m_serializerSvc
virtual bool serialize(std::vector< uint32_t > &output) const
method serizlizes the navigation structure The structure is serrizlized in following order ....
unsigned m_objectsIndexOffset
small integer used to generate sub type index
virtual bool getFeatureAccessorsSingleTE(const TriggerElement *te, CLID clid, const index_or_label_type &index_or_label, bool only_single_feature, TriggerElement::FeatureVec &features, const TriggerElement *&source=::HLT::TrigNavStructure::m_unspecifiedTE, std::string &sourcelabel=::HLT::TrigNavStructure::m_unspecifiedLabel) const
void getAllOfType(const std::string &id, std::vector< HLT::TriggerElement * > &output, const bool activeOnly=true) const
return trigger elements given the name of TEs
bool serializeHoldersWithPayload(const std::vector< CSPair > &payload, std::vector< uint32_t > &output, std::vector< uint32_t > &holderblobsizes, std::vector< std::pair< CLID, std::string > > &clid_name) const
StoreGateSvc * m_storeGate
bool merge(const NavigationCore &l2)
attemtps to merge two trees
std::vector< CSPair > m_classesToPayload
classess are put to payload according to that priority list (CLID + key)
virtual void prepare()
prepapres the navigation for next event
std::vector< CSPair > m_classesToPreregister
classes mentioned here will be put to SG irrespectively of thier presence in event
bool msgLvl(const MSG::Level lvl) const
virtual bool getFeatureAccessors(const TriggerElement *te, class_id_type clid, const index_or_label_type &index_or_label, bool only_single_feature, TriggerElement::FeatureVec &features, bool travel_backward_recursively, const TriggerElement *&source=m_unspecifiedTE, std::string &sourcelabel=m_unspecifiedLabel) const
retrieve features accessors according to the requrements This method is actually workhorse for all ab...
bool deserialize(const std::vector< uint32_t > &input)
bool serializeHoldersWithoutPayload(const std::vector< HLTNavDetails::IHolder * > &holders, std::vector< uint32_t > &output, std::vector< uint32_t > &holderblobsizes, std::vector< std::pair< CLID, std::string > > &clid_name) const
std::string m_objectsKeyPrefix
property setting prefix which is to be given to all trigger EDM objects
bool serialize_DSonly(std::vector< uint32_t > &output, std::vector< unsigned int > &cuts, std::vector< std::pair< CLID, std::string > > &clid_name) const
bool serializeWithHolderSection(const std::vector< uint32_t > &holderdata, const std::vector< unsigned int > &holderblobsizes, std::vector< uint32_t > &output, std::vector< unsigned int > &cuts, std::vector< std::pair< CLID, std::string > > &clid_name) const
bool createHolder(HLTNavDetails::IHolder *&holder, CLID clid, const std::string &label, uint16_t idx) const
creates holder for type given by CLID
HLTNavDetails::IHolder * prepareOneHolder(CLID clid, const std::string &label)
std::vector< HolderType * > getAllHolders() const
std::vector< HolderType * > getHoldersOfClid(class_id_type clid) const
HolderType * getHolder(class_id_type clid, const std::variant< sub_index_type, std::string > &stiOrLabel) const
bool registerHolder(const std::shared_ptr< BaseHolder > &holder)
virtual void reset(bool inFinalize=false)
resets all the navigation, goes to the factory and asks to withdraw all produced objects
void printASCIIArt(std::string &str, const TriggerElement *te=0, int offset=0) const
pretty printing of the navigational structure (heavy)
bool serializeTEs(std::vector< uint32_t > &output) const
method serizlizes the navigation structure
void getAllOfType(const te_id_type id, std::vector< TriggerElement * > &output, const bool activeOnly=true) const
The query returning a collection of all TriggerElements if name is given.
virtual bool getFeatureAccessors(const TriggerElement *te, class_id_type clid, const index_or_label_type &index_or_label, bool only_single_feature, TriggerElement::FeatureVec &features, bool travel_backward_recursively, const TriggerElement *&source=m_unspecifiedTE, std::string &sourcelabel=m_unspecifiedLabel) const
bool deserializeTEs(std::vector< uint32_t >::const_iterator &start, unsigned int totalSize)
void getAll(std::vector< TriggerElement * > &output, const bool activeOnly=true) const
The query returning a collection of all TriggerElements.
static const TriggerElement *m_unspecifiedTE ATLAS_THREAD_SAFE
virtual bool getFeatureAccessorsSingleTE(const TriggerElement *te, class_id_type clid, const index_or_label_type &index_or_label, bool only_single_feature, TriggerElement::FeatureVec &features, const TriggerElement *&source, std::string &sourcelabel) const
std::recursive_mutex & getMutex()
TrigHolderStructure & getHolderStorage()
std::string label(class_id_type clid, const index_or_label_type &sti_or_label) const
TriggerElement is the basic ingreedient of the interface between HLT algorithms and the navigation It...
std::vector< FeatureAccessHelper > FeatureVec
static const CLIDtoHolderMap & holders()
Maintain a set of objects, one per slot.
static HLTHash string2hash(const std::string &, const std::string &category="TE")
hash function translating TE names into identifiers
A crc-64 implementation, using pclmul where possible.
static Root::TMsgLogger logger("iLumiCalc")
uint64_t crc64(const CRCTable &table, const char *data, size_t data_len)
Find the CRC-64 of a string,.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
const FeatureContainerInit< FEATURE, CONTAINER > RegisterFeatureContainerTypes< FEATURE, CONTAINER >::s
std::variant< sub_index_type, std::string > index_or_label_type
MsgStream & operator<<(MsgStream &m, const Navigation &nav)