Skip to content

Commit 21f77e0

Browse files
committed
fix TPCFlagsMemberCustomStreamer.cxx
1 parent f4755b2 commit 21f77e0

1 file changed

Lines changed: 28 additions & 17 deletions

File tree

Detectors/TPC/base/src/TPCFlagsMemberCustomStreamer.cxx

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#include "TPCBase/CalArray.h"
1313
#include <TMemberStreamer.h>
1414
#include <TBuffer.h>
15+
#include <TClass.h>
1516
#include <DataFormatsTPC/Defs.h>
17+
#include <cstdlib>
1618
#include <iostream>
1719

1820
// to enable assert statements
@@ -64,23 +66,32 @@ void MemberVectorPadFlagsStreamer(TBuffer& R__b, void* objp, int n)
6466
}
6567
}
6668

67-
// register the streamer via static global initialization (on library load)
68-
// the streamer is only correct in combination with new ROOT
69+
// Register the streamer via static global initialization on library load.
70+
// The streamer is only correct in combination with new ROOT.
71+
//
72+
// Do not use ROOT::GenerateInitInstance here: it is not available in all ROOT
73+
// builds/versions where this file is compiled. Also do not assert if the class
74+
// lookup fails during static initialization: depending on library load order the
75+
// dictionary may not be available yet, and killing the process at this point
76+
// makes the whole build/load fail.
6977
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 33, 00)
70-
namespace ROOT
78+
namespace
7179
{
72-
static __attribute__((used)) int _R__dummyStreamer_3 =
73-
([]() {
74-
auto cl = TClass::GetClass<o2::tpc::CalArray<o2::tpc::PadFlags>>();
75-
if (cl) {
76-
if (!getenv("TPC_PADFLAGS_STREAMER_OFF")) {
77-
cl->AdoptMemberStreamer("mData", new TMemberStreamer(MemberVectorPadFlagsStreamer));
78-
}
79-
} else {
80-
// we should never come here ... and if we do we should assert/fail
81-
assert(false);
82-
}
80+
[[maybe_unused]] __attribute__((used)) int _R__dummyStreamer_3 = []() {
81+
if (std::getenv("TPC_PADFLAGS_STREAMER_OFF")) {
82+
return 0;
83+
}
84+
85+
auto* cl = TClass::GetClass<o2::tpc::CalArray<o2::tpc::PadFlags>>();
86+
if (!cl) {
87+
std::cerr << "Warning in TPCFlagsMemberCustomStreamer: could not find "
88+
<< "TClass for o2::tpc::CalArray<o2::tpc::PadFlags>; "
89+
<< "PadFlags member streamer was not registered" << std::endl;
8390
return 0;
84-
})();
85-
} // namespace ROOT
86-
#endif
91+
}
92+
93+
cl->AdoptMemberStreamer("mData", new TMemberStreamer(MemberVectorPadFlagsStreamer));
94+
return 0;
95+
}();
96+
} // namespace
97+
#endif

0 commit comments

Comments
 (0)