16 #include <TDirectory.h>
46 class TEventNotifier :
public ::TObject {
51 : m_tree( 0 ), m_event( 0 ) {}
64 virtual ::Bool_t Notify() {
65 if( ( ! m_tree ) || ( ! m_event ) ) {
66 ::Error(
"TEventNotifier::Notify",
71 if( ! m_event->readFrom( m_tree ) ) {
72 ::Error(
"TEventNotifier::Notify",
102 class TTransObjectHolder {
106 class TVirtualTransObject {
109 virtual ~TVirtualTransObject() {}
113 template<
typename T >
114 class TTransObject :
public TVirtualTransObject {
117 TTransObject( std::unique_ptr< T >&&
obj )
118 : m_obj( std::move(
obj ) ) {}
123 if( ! ROOT::Internal::gROOTLocal ) {
124 (void)m_obj.release();
127 if (TTransObjectHolder::s_inCleanup)
128 (void)m_obj.release();
131 std::unique_ptr< T > m_obj;
136 TTransObjectHolder() : m_objects() {}
139 template<
typename T >
140 void add( std::unique_ptr< T >&&
obj ) {
141 m_objects.push_back( std::unique_ptr< TVirtualTransObject >(
142 new TTransObject< T >( std::move(
obj ) ) ) );
156 ~Canary() { TTransObjectHolder::s_inCleanup =
true; }
160 std::vector< std::unique_ptr< TVirtualTransObject > > m_objects;
163 inline static std::atomic<bool> s_inCleanup{
false};
172 static ::TTransObjectHolder s_objectHolder;
174 static ::TTransObjectHolder::Canary s_canary;
190 ::Error(
"xAOD::MakeTransientTrees",
191 XAOD_MESSAGE(
"Couldn't set up the reading of the input "
197 ::TTree* metaTree =
dynamic_cast< ::TTree*
>(
ifile->Get(
"MetaData" ) );
199 ::Error(
"xAOD::MakeTransientTrees",
200 XAOD_MESSAGE(
"Couldn't access metadata tree \"MetaData\" "
201 "in the input file" ) );
207 ::TTree* meta = MakeTransientMetaTree( *
event, metaTree );
211 s_objectHolder.add( std::move(
event ) );
219 s_objectHolder.clear();
228 ::Error(
"xAOD::MakeTransientTree",
239 auto eventTree = std::make_unique< xAODTEventTree >(
event,
treeName );
246 ::Error(
"xAOD::MakeTransientTree",
254 for( ; ef_itr != ef_end; ++ef_itr ) {
275 ::TClass*
cl = ::TClass::GetClass( efe.
className().c_str() );
279 if(
cl->InheritsFrom(
"SG::IConstAuxStore" ) ) {
284 const std::type_info* ti =
cl->GetTypeInfo();
286 ::Warning(
"xAOD::MakeTransientTree",
287 "Couldn't find std::type_info object for type %s "
299 std::make_unique< xAODTEventBranch >( *eventTree,
event, *ti,
302 eventTree->AddBranch( std::move(
br ) );
307 ::TTree*
result = eventTree.get();
309 s_objectHolder.add( std::move( eventTree ) );
312 ::Info(
"xAOD::MakeTransientTree",
313 "Created transient tree \"%s\" in ROOT's common memory",
323 std::unique_ptr< TEvent >
event(
new TEvent(
mode ) );
325 ::Error(
"xAOD::MakeTransientTree",
326 XAOD_MESSAGE(
"Couldn't set up the reading of the input "
335 s_objectHolder.add( std::move(
event ) );
345 std::unique_ptr< ::TEventNotifier > notifier( new ::TEventNotifier() );
350 ::Error(
"xAOD::MakeTransientTree",
351 XAOD_MESSAGE(
"Couldn't set up the reading of the input "
358 ::Error(
"xAOD::MakeTransientTree",
359 XAOD_MESSAGE(
"Couldn't load event 0 from the chain" ) );
365 notifier->Setup( itree,
event.get() );
366 itree->SetNotify( notifier.get() );
369 ::TTree*
result = MakeTransientTree( *
event, itree->GetName() );
372 s_objectHolder.add( std::move(
event ) );
373 s_objectHolder.add( std::move( notifier ) );
386 auto metaTree = std::make_unique< xAODTMetaTree >(
event );
392 TObjArray*
branches = persMetaTree->GetListOfBranches();
393 for( ::Int_t
i = 0;
i <
branches->GetEntries(); ++
i ) {
396 ::TBranch*
br =
dynamic_cast< ::TBranch*
>(
branches->At(
i ) );
398 ::Error(
"xAOD::MakeTransientMetaTree",
399 XAOD_MESSAGE(
"Couldn't access branch %i as a TBranch" ),
406 if( ! strcmp(
br->GetName(),
"EventFormat" ) )
continue;
409 ::TClass*
cl = ::TClass::GetClass(
br->GetClassName(), kTRUE, kTRUE );
413 const std::type_info* ti =
cl->GetTypeInfo();
417 if(
cl->InheritsFrom(
"SG::IConstAuxStore" ) ) {
422 auto mbr = std::make_unique< xAODTMetaBranch >( *metaTree,
event, *ti,
424 br->GetClassName() );
425 metaTree->AddBranch( std::move( mbr ) );
429 ::TTree*
result = metaTree.get();
431 s_objectHolder.add( std::move( metaTree ) );
434 ::Info(
"xAOD::MakeTransientMetaTree",
435 "Created transient metadata tree \"MetaData\" in ROOT's common "
441 const char* eventTreeName,
446 std::unique_ptr< TEvent >
event(
new TEvent(
mode ) );
448 ::Error(
"xAOD::MakeTransientMetaTree",
449 XAOD_MESSAGE(
"Couldn't set up the reading of the input "
455 ::TTree* metaTree =
dynamic_cast< ::TTree*
>(
ifile->Get(
"MetaData" ) );
457 ::Error(
"xAOD::MakeTransientMetaTree",
458 XAOD_MESSAGE(
"Couldn't access metadata tree \"MetaData\" "
459 "in the input file" ) );
464 ::TTree*
result = MakeTransientMetaTree( *
event, metaTree );
467 s_objectHolder.add( std::move(
event ) );
474 const char* eventTreeName,
478 std::unique_ptr< ::TChain > helperChain( new ::TChain( eventTreeName ) );
479 ::TObjArray*
files = ichain->GetListOfFiles();
480 for( ::Int_t
i = 0;
i <
files->GetEntries(); ++
i ) {
481 helperChain->Add(
files->At(
i )->GetTitle() );
488 ::Error(
"xAOD::MakeTransientMetaTree",
489 XAOD_MESSAGE(
"Couldn't set up the reading of the input "
495 ::TTree*
result = MakeTransientMetaTree( *
event, ichain );
498 s_objectHolder.add( std::move( helperChain ) );
499 s_objectHolder.add( std::move(
event ) );