19#include "TBufferFile.h"
22#include "TMethodCall.h"
25#include "TStreamerInfo.h"
39#define TRIGTSERHEADER 0xf00dbeef
41#define TRIGTSERVERSION 0x0005U
67#include "TSchemaRuleSet.h"
73 static const TClass* invalidPtr =
reinterpret_cast<TClass*
>(std::intptr_t(-1));
96 R__ASSERT(IsReading());
102 UInt_t startpos = UInt_t(fBufCur-fBuffer);
106 TClass *clRef = ReadClass(clCast, &tag);
107 TClass *clOnfile = 0;
108 Int_t baseOffset = 0;
109 if (clRef && (clRef!=invalidPtr) && clCast) {
111 baseOffset = clRef->GetBaseClassOffset(clCast);
112 if (baseOffset == -1) {
115 if (!clCast->GetSchemaRules() ||
116 !clCast->GetSchemaRules()->HasRuleWithSourceClass(clRef->GetName()))
119 Error(
"ReadObject",
"got object of wrong class! requested %s but got %s",
120 clCast->GetName(), clRef->GetName());
122 CheckByteCount(startpos, tag, (TClass*)0);
129 clRef =
const_cast<TClass*
>(clCast);
132 if (clCast->GetState() > TClass::kEmulated && clRef->GetState() <= TClass::kEmulated) {
134 Error(
"ReadObject",
"trying to read an emulated class (%s) to store in a compiled pointer (%s)",
135 clRef->GetName(),clCast->GetName());
136 CheckByteCount(startpos, tag, (TClass*)0);
145 obj = (
char *) (Long_t)fMap->GetValue(startpos+
kMapOffset);
146 if (obj == (
void*) -1) obj = 0;
148 CheckByteCount(startpos, tag, (TClass*)0);
149 return (obj+baseOffset);
154 if (clRef == invalidPtr) {
155 if (fBufCur >= fBufMax)
return 0;
157 MapObject((TObject*) -1, startpos+
kMapOffset);
159 MapObject((
void*)0, 0, fMapCount);
160 CheckByteCount(startpos, tag, (TClass*)0);
168 tag += fDisplacement;
169 tag = CheckObject(tag, clCast);
171 if (tag > (UInt_t)fMap->GetSize()) {
172 Error(
"ReadObject",
"object tag too large, I/O buffer corrupted");
177 obj = (
char *) (Long_t)fMap->GetValue(tag);
178 clRef = (TClass*) (Long_t)fClassMap->GetValue(tag);
180 if (clRef && (clRef!=invalidPtr) && clCast) {
182 baseOffset = clRef->GetBaseClassOffset(clCast);
183 if (baseOffset == -1) {
184 Error(
"ReadObject",
"Got object of wrong class (Got %s while expecting %s)",
185 clRef->GetName(),clCast->GetName());
202 obj = (
char*)clRef->New();
204 Error(
"ReadObject",
"could not create object of class %s",
214 MapObject(obj, clRef, fMapCount);
217 clRef->Streamer( obj, *
this, clOnfile );
219 CheckByteCount(startpos, tag, clRef);
222 return obj+baseOffset;
231 "CosmicMuonCollection_tlp1",
"MdtTrackSegmentCollection_tlp1",
232 "CosmicMuonCollection_p1",
"CosmicMuon_p1",
"MdtTrackSegmentCollection_p1",
233 "MdtTrackSegment_p1",
"MdtTrackSegmentCollection_p2",
"PanTauDetails_p1",
234 "SG::IAuxStoreCompression"
238 declareInterface<ITrigSerializerToolBase>(
this );
241 for (
size_t i=0; i<4; i++)
m_guid[i]=0;
258 if( not
msg.empty() )
msg +=
", ";
268 return StatusCode::SUCCESS;
274 std::map<std::string,uint32_t>::const_iterator mitr(
m_errCount.begin());
275 std::map<std::string,uint32_t>::const_iterator mend(
m_errCount.end());
276 bool reported(
false);
279 ATH_MSG_WARNING(
"Could not interpret persistent object " << (*mitr).first
280 <<
" /" << (*mitr).second <<
" times." );
285 return StatusCode::SUCCESS;
289 const char* location,
const char *
msg)
291 if( level == kWarning and gDebug == 0 ) {
292 if( strstr(
msg,
"no dictionary for class") ) {
294 if( strstr(
msg,
type.c_str()) ) {
300 DefaultErrorHandler(level,abort_bool, location,
msg);
309 std::string extStreamerInfos =
"bs-streamerinfos.root";
312 TFile f(extFile.c_str());
316 TStreamerInfo *
inf =
dynamic_cast<TStreamerInfo*
> (obj);
318 TString t_name=
inf->GetName();
320 if (t_name.BeginsWith(
"listOfRules")){
327 TClass *cl =
inf->GetClass();
329 ATH_MSG_DEBUG(
"external TStreamerInfo for " << cl->GetName()
330 <<
" checksum: " <<
inf->GetCheckSum() );
337 const char* location,
const char *
msg){
338 if( level > kInfo ) {
342 int oldLvl = gErrorIgnoreLevel;
344 gErrorIgnoreLevel = kPrint;
346 ::DefaultErrorHandler(level,abort_bool, location,
msg);
347 gErrorIgnoreLevel = oldLvl;
358 gErrorIgnoreLevel = kError+1;
372 <<
" any further ROOT messages for this class will be suppressed" );
381 std::vector<uint32_t> serialized;
390 size_t rootDebug = gDebug;
403 TClass *pclass = gROOT->GetClass(noc.c_str());
407 TBufferFile *buff =
new TBufferFile(TBuffer::kWrite);
419 buff->WriteObjectAny(
instance, pclass);
423 ATH_MSG_DEBUG(
"wrote buffer of length " << buff->Length() );
426 const char *pbuff = buff->Buffer();
427 const size_t bufsiz = buff->Length();
431 serialized.push_back(bufsiz);
432 serialized.push_back(
m_guid[0]);
433 serialized.push_back(
m_guid[1]);
434 serialized.push_back(
m_guid[2]);
435 serialized.push_back(
m_guid[3]);
443 for (
size_t i=0; i<bufsiz/4; i++){
445 for (
size_t j=0; j<4; j++){
446 pbytes.pp[3-j] = pbuff[4*i+j];
450 serialized.push_back(pbytes.uint);
454 const size_t modb = bufsiz%4;
455 for (
size_t i=0; i<modb; i++){
457 pbytes.pp[0] = pbuff[bufsiz-modb+i];
458 serialized.push_back(pbytes.uint);
461 if (
msgLvl(MSG::VERBOSE)){
462 msg(MSG::VERBOSE) <<
"serialized dump: ";
463 for (
size_t i=0; i<serialized.size(); i++){
464 msg(MSG::VERBOSE) << std::hex << serialized.at(i) <<std::dec <<
" ";
470 ATH_MSG_ERROR(
"gROOT->GetClass failed for" << nameOfClass );
481 size_t rootDebug = gDebug;
492 const size_t vsize = v.size();
493 uint32_t rVersion(0);
495 bool newFormatOK=
true;
496 bool decodeOldFormat=
true;
497 size_t pBuffOffset(3);
511 size_t expectsize = pBuffOffset + bufsiz/4 + bufsiz%4;
513 if (expectsize!=vsize){
516 <<
" does not match the container size " << vsize
517 <<
" for " << nameOfClass <<
" fallback to the old format:" );
519 ATH_MSG_DEBUG( bufsiz <<
"bytes of payload version " << std::hex << rVersion << std::dec
520 <<
" for " << nameOfClass );
524 << nameOfClass <<
" trying initial TrigTSerializer" );
538 pbuf =
new char[bufsiz];
539 std::size_t bufpos = 0;
540 const std::size_t nints = bufsiz / 4;
541 for (std::size_t i = pBuffOffset; i < nints + pBuffOffset; ++i) {
542 const auto bytes = std::bit_cast<std::array<std::byte, 4>>(v.at(i));
543 for (std::size_t c = 0; c < 4; ++c) {
544 pbuf[bufpos++] =
static_cast<char>(bytes[3 - c]);
548 for (
size_t i=nints+pBuffOffset; i<vsize; i++){
549 pbuf[bufpos] = (char)v.at(i);
553 if (
msgLvl(MSG::VERBOSE)){
554 msg(MSG::VERBOSE) <<
"deserialized dump: ";
555 for (
size_t i=0; i<v.size(); i++){
556 msg(MSG::VERBOSE) << std::hex << v.at(i) <<std::dec <<
" ";
561 }
else if (!newFormatOK && decodeOldFormat){
563 pbuf =
new char[bufsiz];
565 for (
size_t i=0; i<bufsiz; i++)
578 TBufferFile *buff =
new TBufferFile(TBuffer::kRead, bufsiz, pbuf, kTRUE);
581 TClass *pclass = gROOT->GetClass(noc.c_str());
583 TObject *pobj = NULL;
589 pobj = (TObject *)(ROOT8367Workaround::TBufferFileWorkaround::doReadObjectAny (buff, pclass));
597 ATH_MSG_ERROR(
"gROOT->GetClass failed for" << nameOfClass );
609 TClass *pclass = gROOT->GetClass(nameOfClass.c_str());
612 StatusCode
sc(StatusCode::FAILURE);
615 sc = StatusCode::SUCCESS;
631 const uint32_t rVersion = v.at(1);
637 return StatusCode::SUCCESS;
641 return StatusCode::FAILURE;
645 for (
size_t i=0; i<4; i++)
654 <<
"ERROR! method TrigTSerializer::" << __PRETTY_FUNCTION__
655 <<
" was removed during migration to ROOT6" << endl;
665 ATH_MSG_VERBOSE(
"Entering do_follow_ptr for " << name <<
" at " << ptr );
669 const std::string classname = name.substr(0, name.find_last_of(
'*'));
670 ATH_MSG_DEBUG(
"going deeper for " << classname <<
" at " << ptr );
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
void TrigTSerializerUnimplError()
Run a MT piece of code with an alternate root error handler.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool msgLvl(const MSG::Level lvl) const
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
void * ReadObjectAnyNV(const TClass *)
static void *doReadObjectAny NO_SANITIZE_UNDEFINED(TBufferFile *buf, const TClass *cl)
Run a MT piece of code with an alternate root error handler.
static std::vector< std::string > s_dictsToIgnore
static copy of the IgnoreMissingDicts property for the static error handler
virtual ~TrigTSerializer()
void reset()
clean internal serializer state.
void * deserialize(const std::string &nameOfClass, const std::vector< uint32_t > &v)
deserializes an object of a class nameOfClass (and recursively other objects) found in std::vector<ui...
TList * m_streamersList
Remember streamer info list for cleaning up later.
StringArrayProperty m_ignoreMissingDicts
IgnoreMissingDicts.
StatusCode peekCLID(const std::vector< uint32_t > &v, uint32_t *guid) const
access clid of the payload (stored in BS)
static bool s_decodingError
void add_previous_streamerinfos()
void setCLID(const uint32_t *guid)
access clid of the payload virtual CLID getCLID() const = 0;
static bool bsDictWarningFilter(Int_t level, Bool_t abort_bool, const char *location, const char *msg)
std::vector< uint32_t > serialize(const std::string &nameOfClass, const void *instance)
serializes an object of a class nameOfClass pointed to by instance and recursively also other objects...
StatusCode initClass(const std::string &nameOfClass) const
initialize framework to be ready to serialize a given class method to be called to prevent delayed in...
std::map< std::string, uint32_t > m_errCount
void restoreAfterTBuffer(const std::string &nameOfClass)
void prepareForTBuffer(const std::string &nameOfClass)
void do_persistify(const std::string &nameOfClass, void *instance)
void do_persistify_obj(const std::string &nameOfClass, void *instance)
static bool streamerErrorHandler(Int_t level, Bool_t abort_bool, const char *location, const char *msg)
TrigTSerializer(const std::string &name, const std::string &type, const IInterface *parent)
void do_follow_ptr(const std::string &nameOfClass, void *instance)
singleton-like access to IMessageSvc via open function and helper
std::string remapToDictName(const std::string &s)
Helper to disable undefined behavior sanitizer for a function.