6 #include <boost/regex.hpp>
7 #include <tbb/concurrent_unordered_map.h>
23 #include "GaudiKernel/IConversionSvc.h"
27 #include "TVirtualCollectionProxy.h"
39 : m_serializer(
"TrigTSerializer/TrigTSerializer")
46 m_serializer(
"TrigTSerializer/TrigTSerializer")
71 std::vector<uint32_t> serializedLabel;
74 output.push_back( serializedLabel.size() );
75 output.insert(output.end(), serializedLabel.begin(), serializedLabel.end());
80 std::vector<uint32_t>& output,
81 size_t& payloadsize) {
99 std::ostringstream
ss;
101 std::string st =
ss.str();
102 ATH_MSG_DEBUG(
"IHolder::generateAliasKey generated key: " << st);
124 static tbb::concurrent_unordered_map<std::string,std::string> memo
ATLAS_THREAD_SAFE;
127 const auto itr = memo.find(
key);
128 if (itr!=memo.end())
return itr->second;
131 std::string ret = boost::regex_replace(containername,
rx1,std::string(
""));
134 size_t pos = ret.find(
"::");
135 if (
pos!=std::string::npos) ret.replace(
pos,2,
"__");
141 else if (!
label.empty())
142 ret += (
"_" +
label);
144 memo.insert({
key, ret});
152 const std::string container_typename = collectionName();
154 if ( m_storeGate->transientContains(container_clid,
sgkey) ) {
155 ATH_MSG_VERBOSE(
"deserialize: while working on: " << container_typename <<
" and key: " <<
sgkey
156 <<
" from serialized form found it in SG already, sync with it");
160 ATH_MSG_VERBOSE(
"deserializing a data blob of size " << dataBlob.size() <<
" navi version is " <<
version);
161 ATH_MSG_DEBUG(
"holder type clid " << feature_clid<<
" collection clid: " << container_clid);
163 if (container_clid<1){
164 ATH_MSG_WARNING(
"holder type clid " << feature_clid <<
" collection clid: " << container_clid);
167 typedef std::vector<uint32_t>::const_iterator it_type;
170 if(!dataBlob.size())
return false;
175 auto firstsize = *(
it++);
178 first = std::vector<uint32_t>(
it,
it+firstsize);
180 std::advance(
it,firstsize);
182 if(!(
it!=dataBlob.end())){
183 ATH_MSG_VERBOSE(
"this datablob only has a first part (non xAOD case)");
186 auto secondsize = *(
it++);
188 second = std::vector<uint32_t>(
it,
it+secondsize);
189 std::advance(
it,secondsize);
193 first = std::vector<uint32_t>(dataBlob.begin(),dataBlob.end());
200 if (m_objectserializerSvc->createObj((IOpaqueAddress*)&addr, dobj).isFailure() ){
205 bool setcontainer = setDataObject(dobj);
210 if(!setcontainer)
return false;
212 DataObject* dobjaux(0);
214 std::string sgkeyaux =
sgkey+
"Aux.";
219 if (m_objectserializerSvc->createObj((IOpaqueAddress*)&auxaddr, dobjaux).isFailure() ){
225 if (
it != dataBlob.end()) {
230 dobjBaseAux->template cast<xAOD::AuxContainerBase> (
nullptr,
false))
235 if (!istore || !deserializeDynVars (dataBlob,
236 it - dataBlob.begin(),
244 bool setaux = setAuxDataObject(dobjaux);
249 if(!setaux)
return false;
256 DataObject* dobj = getDataObject();
266 if ( m_objectserializerSvc->createRep(dobj, *pp_cast<IOpaqueAddress>(&addr) ).isSuccess() ) {
267 ATH_MSG_VERBOSE(
"serialization of feature (object) successful, blob size: " << addr->
get().size());
268 dataBlob.push_back(addr->
get().size());
269 dataBlob.insert(dataBlob.end(), addr->
get().begin(), addr->
get().end());
284 DataObject* dobjaux = getAuxDataObject();
291 if(m_objectserializerSvc->createRep(dobjaux,*pp_cast<IOpaqueAddress>(&auxaddr) ).isSuccess() ){
292 ATH_MSG_VERBOSE(
"aux conversion success! aux blob has size: " << auxaddr->
get().size());
293 dataBlob.push_back(auxaddr->
get().size());
294 dataBlob.insert(dataBlob.end(), auxaddr->
get().begin(), auxaddr->
get().end());
304 dobjBaseAux->template cast<xAOD::AuxContainerBase> (
nullptr,
true))
316 if (!serializeDynVars (*iio,
sel, dataBlob)) {
317 ATH_MSG_ERROR(
"Serialization of dynamic aux variables failed.");
322 ATH_MSG_VERBOSE(
"finished serializing payload. size: " << dataBlob.size());
347 std::vector<uint32_t>& dataBlob)
354 const std::type_info* tinfo = iio.
getIOType (
id);
356 ATH_MSG_ERROR(
"serialize aux dyn vars failed: can't get type_info.");
359 TClass*
cls = TClass::GetClass (*tinfo);
361 ATH_MSG_ERROR(
"serialize aux dyn vars failed: can't get TClass.");
366 std::vector<uint32_t> serialized =
372 std::vector<uint32_t> serializedName;
373 ss.serialize (
r.getName(
id), serializedName);
374 dataBlob.push_back (serializedName.size());
375 dataBlob.insert(dataBlob.end(), serializedName.begin(), serializedName.end());
377 std::vector<uint32_t> serializedType;
378 ss.serialize (
cls->GetName(), serializedType);
379 dataBlob.push_back (serializedType.size());
380 dataBlob.insert(dataBlob.end(), serializedType.begin(), serializedType.end());
383 dataBlob.push_back (serialized.size());
384 dataBlob.insert(dataBlob.end(), serialized.begin(), serialized.end());
411 ATH_MSG_ERROR(
"deserialize aux dyn vars failed: can't convert to IAuxStoreHolder.");
416 if (!newstore)
return false;
417 holder->
setStore (newstore.release());
427 std::string stripStdVec (
const std::string& s_in)
429 std::string
s = s_in;
430 std::string::size_type
pos{0};
431 while ((
pos =
s.find (
"std::vector<")) != std::string::npos) {
451 std::unique_ptr<SG::IAuxStore>
459 auto store = std::make_unique<HLTNavDetails::TrigAuxStore>();
462 std::vector<uint32_t>::const_iterator
it = dataBlob.begin() + offs;
463 while (
it < dataBlob.end()) {
465 size_t name_size = *
it++;
470 size_t tname_size = *
it++;
472 ss.deserialize (
it,
it+tname_size, tname);
476 size_t var_size = *
it++;
478 const static char*
const packed_pref =
"SG::PackedContainer<";
479 const static unsigned int packed_preflen = strlen(packed_pref);
480 std::string vecname = tname;
481 if (strncmp (vecname.c_str(), packed_pref, packed_preflen) == 0) {
485 auto makeRules = []() {
487 rules.
add (
"SG::PackedContainer<$T, std::allocator<$T> >",
489 rules.
add (
"SG::PackedContainer<$T, allocator<$T> >",
491 rules.
add (
"SG::PackedContainer<$T, $ALLOC>",
492 "vector<$T, $ALLOC>");
496 vecname = rules.
apply (vecname);
502 if (
id != SG::null_auxid && stripStdVec(
r.getVecTypeName(
id)) != stripStdVec(vecname)) {
503 vecname =
r.getVecTypeName (
id);
509 if (
id == SG::null_auxid)
511 std::string elementTypeName;
512 const std::type_info* elt_tinfo =
getElementType (vecname, elementTypeName);
515 if (
id == SG::null_auxid) {
517 return std::unique_ptr<SG::IAuxStore> (std::move(
store));
522 std::vector<uint32_t> buf (
it,
it+var_size);
526 bool isPacked = (strncmp (tname.c_str(), packed_pref, packed_preflen) == 0);
527 std::unique_ptr<SG::IAuxTypeVector>
vec
528 (
r.makeVectorFromData (
id,
obj,
nullptr, isPacked,
true));
529 store->addVector (std::move(
vec),
false);
532 return std::unique_ptr<SG::IAuxStore> (std::move(
store));
543 const std::type_info*
545 std::string& elementTypeName)
const
547 TClass*
cls = TClass::GetClass (tname.c_str());
548 if (!
cls)
return nullptr;
549 TVirtualCollectionProxy* prox =
cls->GetCollectionProxy();
550 if (!prox)
return nullptr;
551 if (prox->GetValueClass()) {
552 elementTypeName = prox->GetValueClass()->GetName();
553 return prox->GetValueClass()->GetTypeInfo();