4 #pragma warning( disable : 2259 ) 19 #include "boost/algorithm/string/case_conv.hpp" 21 #include "TDirectory.h" 39 template <
typename InputIterator,
typename OutputIterator,
typename UnaryOperation,
typename UnaryPredicate>
40 OutputIterator transform_if( InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op,
43 while ( first != last ) {
44 if ( pred( *first ) ) *result++ = op( *first );
50 constexpr
struct select1st_t {
51 template <
typename T,
typename S>
99 static TROOT
root(
"root",
"ROOT I/O" );
106 error() <<
"unable to get the IncidentSvc" <<
endmsg;
124 error() <<
"unable to register ROOT file open action with FileMgr" <<
endmsg;
130 error() <<
"unable to register ROOT file open Error action with FileMgr" <<
endmsg;
150 if (
service(
"IoComponentMgr", iomgr,
true ).isFailure() ) {
151 error() <<
"unable to get the IoComponentMgr" <<
endmsg;
156 error() <<
"could not register with the I/O component manager !" <<
endmsg;
159 bool all_good =
true;
161 for (
const auto& reg :
m_files ) {
162 const std::string& fname = reg.second.first->GetName();
166 warning() <<
"could not register file [" << fname <<
"] with the I/O component manager..." <<
endmsg;
169 info() <<
"registered file [" << fname <<
"]... [ok]" <<
endmsg;
173 error() <<
"problem while registering input/output files with " 174 <<
"the I/O component manager !" <<
endmsg;
181 fatal() <<
"Unable to initialize THistSvc" <<
endmsg;
208 for (
const auto& uid :
m_uids ) {
210 TObject* to = uid.second.obj;
213 if ( to && to->IsA()->InheritsFrom(
"TTree" ) ) {
214 TTree* tr =
dynamic_cast<TTree*
>( to );
215 if ( tr->GetDirectory() != 0 ) {
216 dirname = tr->GetDirectory()->GetPath();
218 }
else if ( to && to->IsA()->InheritsFrom(
"TGraph" ) ) {
219 if ( !uid.second.temp ) {
220 dirname = uid.second.file->GetPath();
221 string id2( uid.second.id );
224 if ( id2.
find(
"/" ) == 0 ) {
231 }
else if ( to && to->IsA()->InheritsFrom(
"TH1" ) ) {
232 TH1* th =
dynamic_cast<TH1*
>( to );
234 error() <<
"Couldn't dcast: " << uid.first <<
endmsg;
236 if ( th->GetDirectory() != 0 ) {
237 dirname = th->GetDirectory()->GetPath();
244 debug() <<
"uid: \"" << uid.first <<
"\" temp: " << uid.second.temp <<
" dir: " << dirname <<
endmsg;
251 error() <<
"problems writing histograms" <<
endmsg;
255 info() <<
"Listing contents of ROOT files: " <<
endmsg;
260 if (
find( deleted_files.
begin(), deleted_files.
end(), itr.second.first ) == deleted_files.
end() ) {
261 deleted_files.
push_back( itr.second.first );
265 debug() <<
"finalizing stream/file " << itr.first <<
":" << itr.second.first->GetName() <<
endmsg;
276 info() <<
"==> File: " << itr.second.first->GetName() <<
" stream: " << itr.first <<
endmsg;
278 itr.second.first->Print(
"base" );
281 string tmpfn = itr.second.first->GetName();
286 if (
service(
"IncidentSvc", pi ).isFailure() ) {
287 error() <<
"Unable to get the IncidentSvc" <<
endmsg;
291 if ( itr.second.second ==
SHARE ) {
302 TFile* outputfile = (TFile*)vf;
311 error() <<
"unable to open temporary file: \"" << tmpfn <<
endmsg;
315 TFile* inputfile = (TFile*)vf;
317 outputfile->SetCompressionLevel( inputfile->GetCompressionLevel() );
329 delete itr.second.first;
356 cout <<
"-> " << dir->GetPath() <<
" " << dir->GetListOfKeys()->GetSize() <<
endl;
359 TIter nextkey( dir->GetList() );
360 while ( TKey* key = (TKey*)nextkey() ) {
362 TObject* obj = key->ReadObj();
364 cout << key->GetName() <<
" obj==0" <<
endl;
368 cout <<
" Key: " << key->GetName() <<
" " 369 <<
" tit: " << obj->GetTitle() <<
" " 370 <<
" (" << key->GetClassName() <<
")" <<
endl;
374 nextkey = dir->GetListOfKeys();
375 while ( TKey* key = (TKey*)nextkey() ) {
377 TObject* obj = key->ReadObj();
379 cout << key->GetName() <<
" obj==0" <<
endl;
382 if ( obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
383 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
397 gErrorIgnoreLevel = kBreak;
400 error() <<
"getTHists: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
405 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
407 TIter nextkey( td->GetListOfKeys() );
408 while ( TKey* key = (TKey*)nextkey() ) {
411 TObject* obj = key->ReadObj();
412 if ( obj != 0 && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
414 }
else if ( obj != 0 && obj->IsA()->InheritsFrom(
"TH1" ) ) {
417 }
else if ( obj != 0 ) {
425 nextkey = td->GetListOfKeys();
426 while ( TKey* key = (TKey*)nextkey() ) {
427 TObject* obj = key->ReadObj();
428 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
429 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
445 gErrorIgnoreLevel = kBreak;
454 r2 = itr->second.first->GetName();
459 debug() <<
"getTHists: \"" << dir <<
"\" looks like a stream name." 460 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
462 if ( gDirectory->cd( r2.
c_str() ) ) {
475 if ( !gDirectory->cd( dir.
c_str() ) ) {
476 error() <<
"getTHists: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
490 gErrorIgnoreLevel = kBreak;
493 error() <<
"getTTrees: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
498 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
500 TIter nextkey( td->GetListOfKeys() );
501 while ( TKey* key = (TKey*)nextkey() ) {
504 TObject* obj = key->ReadObj();
505 if ( obj != 0 && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
507 }
else if ( obj != 0 && obj->IsA()->InheritsFrom(
"TTree" ) ) {
510 }
else if ( obj != 0 ) {
518 nextkey = td->GetListOfKeys();
519 while ( TKey* key = (TKey*)nextkey() ) {
520 TObject* obj = key->ReadObj();
521 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
522 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
537 gErrorIgnoreLevel = kBreak;
546 r2 = itr->second.first->GetName();
551 debug() <<
"getTTrees: \"" << dir <<
"\" looks like a stream name." 552 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
554 if ( gDirectory->cd( r2.
c_str() ) ) {
562 if ( !gDirectory->cd( dir.
c_str() ) ) {
563 error() <<
"getTTrees: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
578 gErrorIgnoreLevel = kBreak;
581 error() <<
"getTHists: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
586 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
588 TIter nextkey( td->GetListOfKeys() );
589 while ( TKey* key = (TKey*)nextkey() ) {
592 TObject* obj = key->ReadObj();
593 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
595 }
else if ( obj && obj->IsA()->InheritsFrom(
"TH1" ) ) {
599 string dir = td->GetPath();
600 string fil = td->GetFile()->GetName();
604 id =
id +
"/" + key->GetName();
606 id =
id + dir +
"/" + key->GetName();
623 nextkey = td->GetListOfKeys();
624 while ( TKey* key = (TKey*)nextkey() ) {
625 TObject* obj = key->ReadObj();
626 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
627 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
643 gErrorIgnoreLevel = kBreak;
652 r2 = itr->second.first->GetName();
657 debug() <<
"getTHists: \"" << dir <<
"\" looks like a stream name." 658 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
660 if ( gDirectory->cd( r2.
c_str() ) ) {
662 sc =
getTHists( gDirectory, tl, rcs, reg );
672 if ( !gDirectory->cd( dir.
c_str() ) ) {
673 error() <<
"getTHists: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
677 warning() <<
"Unable to register histograms automatically " 678 <<
"without a valid stream name" <<
endmsg;
681 sc =
getTHists( gDirectory, tl, rcs, reg );
693 gErrorIgnoreLevel = kBreak;
696 error() <<
"getTTrees: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
701 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
703 TIter nextkey( td->GetListOfKeys() );
704 while ( TKey* key = (TKey*)nextkey() ) {
707 TObject* obj = key->ReadObj();
708 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
710 }
else if ( obj && obj->IsA()->InheritsFrom(
"TTree" ) ) {
714 string dir = td->GetPath();
715 string fil = td->GetFile()->GetName();
719 id =
id +
"/" + key->GetName();
721 id =
id + dir +
"/" + key->GetName();
730 }
else if ( obj != 0 ) {
738 nextkey = td->GetListOfKeys();
739 while ( TKey* key = (TKey*)nextkey() ) {
740 TObject* obj = key->ReadObj();
741 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
742 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
758 gErrorIgnoreLevel = kBreak;
767 r2 = itr->second.first->GetName();
772 debug() <<
"getTTrees: \"" << dir <<
"\" looks like a stream name." 773 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
775 if ( gDirectory->cd( r2.
c_str() ) ) {
776 return getTTrees( gDirectory, tl, rcs, reg );
785 if ( !gDirectory->cd( dir.
c_str() ) ) {
786 error() <<
"getTTrees: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
790 return getTTrees( gDirectory, tl, rcs, reg );
804 error() <<
"Problems deregistering TObject \"" << obj->GetName() <<
"\" with id \"" << hid.
id <<
"\"" <<
endmsg;
813 std::find_if( mitr.first, mitr.second, [&]( idMap::const_reference i ) { return i.second.obj == obj; } );
814 if ( itr3 == mitr.second ) {
815 error() <<
"Problems deregistering TObject \"" << obj->GetName() <<
"\" with id \"" << hid.
id <<
"\"" <<
endmsg;
826 error() <<
"Cannot unregister TObject \"" << obj->GetName() <<
"\": not known to THistSvc" <<
endmsg;
838 error() <<
"Problems deregistering id \"" <<
id <<
"\"" <<
endmsg;
842 TObject* obj = itr->second.obj;
871 TTree* hist =
nullptr;
891 TGraph* hist =
nullptr;
899 if (
strcmp( hist->GetName(),
"Graph" ) == 0 ) {
902 string::size_type i = id2.
rfind(
"/" );
903 if ( i != string::npos ) {
904 id2.
erase( 0, i + 1 );
907 info() <<
"setting name of TGraph id: \"" <<
id <<
"\" to \"" << id2 <<
"\" since it is unset" <<
endmsg;
908 hist->SetName( id2.
c_str() );
934 []( uidMap::const_reference i ) {
return i.second.obj->IsA()->InheritsFrom(
"TH1" ); } );
949 []( uidMap::const_reference i ) {
return i.second.obj->IsA()->InheritsFrom(
"TTree" ); } );
964 []( uidMap::const_reference i ) {
return i.second.obj->IsA()->InheritsFrom(
"TTree" ); } );
988 auto pos =
id.find(
"/" );
990 if ( pos == string::npos ) {
993 }
else if ( pos != 0 ) {
998 auto pos2 =
id.
find(
"/", pos + 1 );
1000 if ( pos2 == string::npos ) {
1001 error() <<
"badly formed Hist/Tree id: \"" <<
id <<
"\"" <<
endmsg;
1008 if ( stream ==
"temp" ) {
1014 file = ( itr !=
m_files.
end() ? itr->second.first : nullptr );
1016 warning() <<
"no stream \"" << stream <<
"\" associated with id: \"" <<
id <<
"\"" <<
endmsg;
1026 auto pos =
id.find(
"/" );
1028 if ( pos == string::npos ) {
1031 }
else if ( pos == 0 ) {
1034 root =
id.
substr( 0, pos );
1035 rem =
id.
substr( pos + 1 );
1044 warning() <<
"\"CompressionLevel\" Property has been deprecated. " 1045 <<
"Set it via the \"CL=\" parameter in the \"Output\" Property" <<
endmsg;
1055 debug() <<
"Delaying connection of Input Files until Initialize" 1061 debug() <<
"Now connecting of Input Files" <<
endmsg;
1085 debug() <<
"Delaying connection of Input Files until Initialize" 1121 verbose() <<
" update: " << uitr->first <<
" " << uitr->second.id <<
" " << uitr->second.mode <<
endmsg;
1123 TObject* to = uitr->second.obj;
1124 TFile* oldFile = uitr->second.file;
1127 }
else if ( uitr->second.temp || uitr->second.mode ==
READ ) {
1134 }
else if ( to->IsA()->InheritsFrom(
"TTree" ) ) {
1135 TTree* tr =
dynamic_cast<TTree*
>( to );
1136 TFile* newFile = tr->GetCurrentFile();
1138 if ( oldFile != newFile ) {
1141 TFile* dummy =
nullptr;
1142 findStream( uitr->second.id, streamName, rem, dummy );
1145 if ( itr.second.first == oldFile ) itr.second.first = newFile;
1148 for (
auto uitr2 = uitr; uitr2 !=
m_uids.
end(); ++uitr2 ) {
1149 if ( uitr2->second.file == oldFile ) {
1150 uitr2->second.file = newFile;
1155 [&]( streamMap::const_reference
s ) {
return s.second == streamName; } );
1160 debug() <<
"migrating uid: " << uitr->second.id <<
" stream: " << streamName
1161 <<
" oldFile: " << oldFileName <<
" newFile: " << newFileName <<
endmsg;
1164 if ( !oldFileName.
empty() ) {
1170 debug() <<
"changing filename \"" << i->first <<
"\" to \"" << newFileName <<
"\" for stream \"" 1171 << i->second <<
"\"" <<
endmsg;
1179 error() <<
"Problems updating fileStreams with new file name" <<
endmsg;
1194 auto mode = i.second.second;
1195 auto file = i.second.first;
1197 file->Write(
"", TObject::kOverwrite );
1198 }
else if ( mode ==
APPEND ) {
1204 debug() <<
"THistSvc::write()::List of Files connected in ROOT " <<
endmsg;
1205 TSeqCollection* filelist = gROOT->GetListOfFiles();
1206 for (
int ii = 0; ii < filelist->GetEntries(); ii++ ) {
1207 debug() <<
"THistSvc::write()::List of Files connected in ROOT: \"" << filelist->At( ii )->GetName() <<
"\"" 1220 auto loc = ident.
find(
" " );
1221 string stream = ident.
substr( 0, loc );
1228 if ( loc != string::npos ) {
1230 for (
auto attrib : Parser( ident.
substr( loc + 1 ) ) ) {
1231 auto TAG = boost::algorithm::to_upper_copy( attrib.tag );
1232 auto VAL = boost::algorithm::to_upper_copy( attrib.value );
1234 if ( TAG ==
"FILE" || TAG ==
"DATAFILE" ) {
1235 filename = attrib.value;
1237 }
else if ( TAG ==
"OPT" ) {
1238 if ( VAL ==
"APPEND" || VAL ==
"UPDATE" ) {
1240 }
else if ( VAL ==
"CREATE" || VAL ==
"NEW" || VAL ==
"WRITE" ) {
1242 }
else if ( VAL ==
"RECREATE" ) {
1244 }
else if ( VAL ==
"SHARE" ) {
1246 }
else if ( VAL ==
"OLD" || VAL ==
"READ" ) {
1249 error() <<
"Unknown OPT: \"" << attrib.value <<
"\"" <<
endmsg;
1252 }
else if ( TAG ==
"TYP" ) {
1254 }
else if ( TAG ==
"CL" ) {
1262 if ( stream ==
"temp" ) {
1263 error() <<
"in JobOption \"" << ident <<
"\": stream name \"temp\" reserved." <<
endmsg;
1267 if ( db_typ !=
"ROOT" ) {
1268 error() <<
"in JobOption \"" << ident <<
"\": technology type \"" << db_typ <<
"\" not supported." <<
endmsg;
1273 error() <<
"in JobOption \"" << ident <<
"\":\n stream \"" << stream <<
"\" already connected to file: \"" 1281 }
else if ( typ ==
'N' ) {
1283 }
else if ( typ ==
'A' ) {
1285 }
else if ( typ ==
'R' ) {
1287 }
else if ( typ ==
'S' ) {
1291 error() <<
"No OPT= specified or unknown access mode in: " << ident <<
endmsg;
1299 const std::string& oldstream = fitr.first->second;
1301 const auto& f_info =
m_files[oldstream];
1303 if ( newMode != f_info.second ) {
1304 error() <<
"in JobOption \"" << ident <<
"\":\n file \"" << filename <<
"\" already opened by stream: \"" 1305 << oldstream <<
"\" with different access mode." <<
endmsg;
1308 TFile* f2 = f_info.first;
1311 debug() <<
"Connecting stream: \"" << stream <<
"\" to previously opened TFile: \"" << filename <<
"\"" 1318 if (
service(
"IncidentSvc", pi ).isFailure() ) {
1319 error() <<
"Unable to get the IncidentSvc" <<
endmsg;
1332 error() <<
"Unable to open ROOT file " << filename <<
" for reading" <<
endmsg;
1347 error() <<
"Unable to open ROOT file " << filename <<
" for writing" <<
endmsg;
1358 error() <<
"unable to open file \"" << filename <<
"\" for appending" <<
endmsg;
1369 static int ishared = 0;
1371 filename =
"tmp_THistSvc_" +
std::to_string( ishared++ ) +
".root";
1374 debug() <<
"Creating temp file \"" << filename <<
"\" and realfilename=" << realfilename <<
endmsg;
1380 error() <<
"Unable to open ROOT file " << filename <<
" for writing" <<
endmsg;
1392 error() <<
"Unable to open ROOT file " << filename <<
" for appending" <<
endmsg;
1403 debug() <<
"Opening TFile \"" << filename <<
"\" stream: \"" << stream <<
"\" mode: \"" << typ <<
"\"" 1404 <<
" comp level: " << cl <<
endmsg;
1414 string uid = hid.
id;
1415 TFile* file = hid.
file;
1416 string stream, fdir, bdir, dir, id;
1427 while ( ( dir =
dirname( fdir ) ) !=
"" ) {
1428 if ( !gDirectory->GetKey( dir.
c_str() ) ) {
1429 gDirectory->mkdir( dir.
c_str() );
1431 gDirectory->cd( dir.
c_str() );
1442 string::size_type i = dir.
find(
"/" );
1444 if ( i == string::npos )
return {};
1463 m_ge = gErrorIgnoreLevel;
1470 gErrorIgnoreLevel = m_ge;
1478 while (
id.
find(
"//" ) != std::string::npos ) {
1479 id.replace(
id.
find(
"//" ), 2,
"/" );
1489 TString
path( (
char*)
strstr( target->GetPath(),
":" ) );
1490 path.Remove( 0, 2 );
1493 TDirectory* current_sourcedir = gDirectory;
1496 TList* lkeys = current_sourcedir->GetListOfKeys();
1497 int nkeys = lkeys->GetEntries();
1499 for (
int jj = 0; jj < nkeys; jj++ ) {
1500 key = (TKey*)lkeys->At( jj );
1501 string pathnameinsource = current_sourcedir->GetPath() +
string(
"/" ) + key->GetName();
1505 TObject* obj = source->Get( pathnameinsource.
c_str() );
1508 if ( obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
1515 TDirectory* newtargetdir = target->mkdir( obj->GetName(), obj->GetTitle() );
1519 }
else if ( obj->IsA()->InheritsFrom(
"TTree" ) ) {
1521 TTree* mytree =
dynamic_cast<TTree*
>( obj );
1522 int nentries = (int)mytree->GetEntries();
1523 mytree->SetBranchStatus(
"*", 1 );
1533 mytree->CloneTree();
1541 obj->Write( key->GetName() );
1569 Long64_t mfs = (Long64_t)
m_maxFileSize.value() * (Long64_t)1048576;
1570 Long64_t mfs_warn = mfs * 95 / 100;
1575 for (
const auto& f :
m_files ) {
1576 TFile* tf = f.second.first;
1580 debug() <<
"stream: " << f.first <<
" name: " << tf->GetName() <<
" size: " << tf->GetSize() <<
endmsg;
1584 if ( tf->GetSize() > mfs ) {
1588 fatal() <<
"file \"" << tf->GetName() <<
"\" associated with stream \"" << f.first
1589 <<
"\" has exceeded the max file size of " <<
m_maxFileSize.value() <<
"MB. Terminating Job." <<
endmsg;
1592 if (
service(
"ApplicationMgr", evt,
true ).isSuccess() ) {
1598 }
else if ( tf->GetSize() > mfs_warn ) {
1599 warning() <<
"file \"" << tf->GetName() <<
"\" associated with stream \"" << f.first
1600 <<
"\" is at 95% of its maximum allowable file size of " <<
m_maxFileSize.value() <<
"MB" <<
endmsg;
1615 TString
path( (
char*)
strstr( dst->GetPath(),
":" ) );
1616 path.Remove( 0, 2 );
1619 TDirectory* cur_src_dir = gDirectory;
1622 TList* key_list = cur_src_dir->GetListOfKeys();
1623 int n = key_list->GetEntries();
1624 for (
int j = 0; j <
n; ++j ) {
1625 TKey* k = (TKey*)key_list->At( j );
1627 TObject* o = src->Get( src_pathname.
c_str() );
1629 if ( o && o->IsA()->InheritsFrom(
"TDirectory" ) ) {
1632 TDirectory* dst_dir = dst->mkdir( o->GetName(), o->GetTitle() );
1645 bool all_good =
true;
1652 if (
service(
"IoComponentMgr", iomgr,
true ).isFailure() ) {
1653 error() <<
"could not retrieve I/O component manager !" <<
endmsg;
1660 gErrorIgnoreLevel = kFatal;
1662 for (
auto& ifile :
m_files ) {
1663 TFile* f = ifile.second.first;
1666 debug() <<
"file [" << fname <<
"] mode: [" << f->GetOption() <<
"] r:" << f->GetFileBytesRead()
1667 <<
" w:" << f->GetFileBytesWritten() <<
" cnt:" << f->GetFileCounter() <<
endmsg;
1669 if ( ifile.second.second ==
READ ) {
1675 error() <<
"could not retrieve new name for [" << fname <<
"] !!" <<
endmsg;
1685 Option_t*
opts = f->GetOption();
1688 error() <<
"unable to open file \"" << fname <<
"\" for writing" <<
endmsg;
1691 TFile* newfile = (TFile*)vf;
1692 newfile->SetOption( opts );
1696 ifile.second.first = newfile;
1701 for (
auto& uid :
m_uids ) {
1703 if ( hid.
file != f )
continue;
1704 TDirectory* olddir = this->
changeDir( hid );
1707 TDirectory* newdir = this->
changeDir( hid );
1708 TClass* cl = hid.
obj->IsA();
1712 if ( cl->InheritsFrom(
"TTree" ) ) {
1713 dynamic_cast<TTree*
>( hid.
obj )->SetDirectory( newdir );
1714 dynamic_cast<TTree*
>( hid.
obj )->Reset();
1715 }
else if ( cl->InheritsFrom(
"TH1" ) ) {
1716 dynamic_cast<TH1*
>( hid.
obj )->SetDirectory( newdir );
1717 dynamic_cast<TH1*
>( hid.
obj )->Reset();
1718 }
else if ( cl->InheritsFrom(
"TGraph" ) ) {
1719 olddir->Remove( hid.
obj );
1720 newdir->Append( hid.
obj );
1722 error() <<
"id: \"" << hid.
id <<
"\" is not a inheriting from a class " 1723 <<
"we know how to handle (received [" << cl->GetName() <<
"], " 1724 <<
"expected [TTree, TH1 or TGraph]) !" <<
endmsg <<
"attaching to current dir [" << newdir->GetPath()
1726 <<
"nonetheless..." <<
endmsg;
1727 olddir->Remove( hid.
obj );
1728 newdir->Append( hid.
obj );
1731 f->ReOpen(
"READ" );
1749 if ( fa->
desc() !=
"HIST" ) {
1777 if ( fa->
desc() !=
"HIST" ) {
Parse attribute strings allowing iteration over the various attributes.
virtual StatusCode io_retrieve(IIoComponent *iocomponent, std::string &fname)=0
: retrieve the new filename for a given IIoComponent and
StatusCode initialize() override
virtual StatusCode stopRun()=0
Schedule a stop of the current event processing.
StatusCode getGraph(const std::string &name, TGraph *&) const override
This class is the FileIncident.
StatusCode initialize() override
Define general base for Gaudi exception.
virtual Io::open_t open(const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, Io::Fd &, void *&, const std::string &desc, const bool shared=false)=0
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
const std::string & name() const override
Retrieve name of the service.
StatusCode finalize() override
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::vector< std::string > getGraphs() const override
This file contains the class definition for the FileIncident class.
bool exists(const std::string &name) const override
bool isSuccess() const
Test for a status code of SUCCESS.
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
bool browseTDir(TDirectory *dir) const
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
TDirectory * changeDir(const THistSvc::THistID &hid) const
void setupCompressionLevel(Gaudi::Details::PropertyBase &cmp)
bool isFailure() const
Test for a status code of FAILURE.
Gaudi::Property< std::vector< std::string > > m_outputfile
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
std::vector< std::string > getHists() const override
#define DECLARE_COMPONENT(type)
virtual StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &d="")=0
const std::string & name() const
Gaudi::Property< int > m_autoSave
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
const std::string & desc() const
Gaudi::Property< std::vector< std::string > > m_inputfile
std::string dirname(std::string &dir) const
StatusCode readTree(const std::string &name, TTree *&) const
This class is used for returning status codes from appropriate routines.
Gaudi::Property< bool > m_print
void handle(const Incident &) override
Gaudi::Property< int > m_maxFileSize
StatusCode getTree(const std::string &name, TTree *&) const override
~GlobalDirectoryRestore()
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Gaudi::Property< int > m_compressionLevel
void parseString(const std::string &id, std::string &root, std::string &rem) const
StatusCode getHist_i(const std::string &name, T *&hist, bool quiet=false) const
StatusCode finalize() override
StatusCode regHist(const std::string &name) override
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
virtual unsigned long release()=0
Release Interface instance.
StatusCode reinitialize() override
StatusCode regHist_i(T *hist, const std::string &name)
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode readHist_i(const std::string &name, T *&hist) const
T back_inserter(T...args)
Base class for all Incidents (computing events).
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
std::map< std::string, std::pair< TFile *, Mode > > m_files
Gaudi::StateMachine::State FSMState() const override
StatusCode connect(const std::string &)
The IEventProcessor is the interface to process events.
StatusCode readHist(const std::string &name, TH1 *&) const
virtual StatusCode io_register(IIoComponent *iocomponent)=0
: allow a IIoComponent to register itself with this manager so appropriate actions can be taken when ...
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
StatusCode deReg(TObject *obj) override
StatusCode regTree(const std::string &name) override
StatusCode getHist(const std::string &name, TH1 *&) const override
std::map< std::string, std::string > m_sharedFiles
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
std::vector< std::string > getTrees() const override
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
void setupInputFile(Gaudi::Details::PropertyBase &inputfile)
call-back method to handle input stream property
void setupOutputFile(Gaudi::Details::PropertyBase &outputfile)
call-back method to handle output stream property
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
StatusCode regGraph(const std::string &name) override
Gaudi::Property< int > m_autoFlush
THistSvc(const std::string &name, ISvcLocator *svc)
StatusCode io_reinit() override
callback method to reinitialize the internal state of the component for I/O purposes (e...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
The interface implemented by the IncidentSvc service.
void MergeRootFile(TDirectory *target, TDirectory *source)
void removeDoubleSlash(std::string &) const
virtual Io::close_t close(const Io::Fd, const std::string &caller)=0