7 #include "boost/algorithm/string/case_conv.hpp" 10 #include "TDirectory.h" 48 template <
typename InputIterator,
typename OutputIterator,
typename UnaryOperation,
typename UnaryPredicate>
49 OutputIterator transform_if( InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op,
50 UnaryPredicate pred ) {
51 while ( first != last ) {
52 if ( pred( *first ) ) *result++ = op( *first );
58 constexpr
struct select1st_t {
59 template <
typename T,
typename S>
96 static TROOT
root(
"root",
"ROOT I/O" );
103 error() <<
"unable to get the IncidentSvc" <<
endmsg;
120 error() <<
"unable to register ROOT file open action with FileMgr" <<
endmsg;
126 error() <<
"unable to register ROOT file open Error action with FileMgr" <<
endmsg;
139 if (
service(
"IoComponentMgr", iomgr,
true ).isFailure() ) {
140 error() <<
"unable to get the IoComponentMgr" <<
endmsg;
144 error() <<
"could not register with the I/O component manager !" <<
endmsg;
147 bool all_good =
true;
149 for (
const auto& reg :
m_files ) {
150 const std::string& fname = reg.second.first->GetName();
154 warning() <<
"could not register file [" << fname <<
"] with the I/O component manager..." <<
endmsg;
157 info() <<
"registered file [" << fname <<
"]... [ok]" <<
endmsg;
161 error() <<
"problem while registering input/output files with " 162 <<
"the I/O component manager !" <<
endmsg;
190 for (
const auto& itr : sorted_uids ) {
191 THistID& thid = itr.second->at( 0 );
192 TObject* tobj = thid.
obj;
195 if ( tobj && tobj->IsA()->InheritsFrom(
"TTree" ) ) {
196 TTree* tree = dynamic_cast<TTree*>( tobj );
197 if ( tree->GetDirectory() != 0 ) {
dirname = tree->GetDirectory()->GetPath(); }
198 }
else if ( tobj && tobj->IsA()->InheritsFrom(
"TGraph" ) ) {
204 if ( id2.
find(
"/" ) == 0 ) { id2.
erase( 0, 1 ); }
209 }
else if ( tobj && tobj->IsA()->InheritsFrom(
"TH1" ) ) {
210 TH1* th = dynamic_cast<TH1*>( tobj );
211 if ( th ==
nullptr ) {
212 error() <<
"Couldn't dcast: " << itr.first <<
endmsg;
214 if ( th->GetDirectory() != 0 ) {
dirname = th->GetDirectory()->GetPath(); }
216 }
else if ( !tobj ) {
229 if (
std::find( deleted_files.
begin(), deleted_files.
end(), itr.second.first ) == deleted_files.
end() ) {
230 deleted_files.
push_back( itr.second.first );
234 debug() <<
"finalizing stream/file " << itr.first <<
":" << itr.second.first->GetName() <<
endmsg;
245 info() <<
"==> File: " << itr.second.first->GetName() <<
" stream: " << itr.first <<
endmsg;
247 itr.second.first->Print(
"base" );
255 if (
service(
"IncidentSvc", pIncidentSvc ).isFailure() ) {
256 error() <<
"Unable to get the IncidentSvc" <<
endmsg;
260 if ( itr.second.second ==
SHARE ) {
262 void* vfile =
nullptr;
271 TFile* outputfile = (TFile*)vfile;
280 error() <<
"unable to open temporary file: \"" << tmpfn <<
endmsg;
284 TFile* inputfile = (TFile*)vfile;
286 outputfile->SetCompressionLevel( inputfile->GetCompressionLevel() );
298 delete itr.second.first;
310 delete obj.second.first;
330 if ( hist_ptr !=
nullptr ) { hist_ptr = hist.
get(); }
340 hist = getHist_i<TH1>(
id, ind );
341 if ( hist !=
nullptr ) {
349 hist = getHist_i<TH2>(
id, ind );
350 if ( hist !=
nullptr ) {
358 hist = getHist_i<TH3>(
id, ind );
359 if ( hist !=
nullptr ) {
393 tree = getHist_i<TTree>(
id );
394 if ( tree !=
nullptr ) {
407 if ( strcmp(
graph->GetName(),
"Graph" ) == 0 ) {
409 std::string::size_type i = id2.
rfind(
"/" );
410 if ( i != std::string::npos ) { id2.
erase( 0, i + 1 ); }
412 info() <<
"setting name of TGraph id: \"" <<
id <<
"\" to \"" << id2 <<
"\" since it is unset" <<
endmsg;
421 if ( strcmp(
graph->GetName(),
"Graph" ) == 0 ) {
423 std::string::size_type i = id2.
rfind(
"/" );
424 if ( i != std::string::npos ) { id2.
erase( 0, i + 1 ); }
426 info() <<
"setting name of TGraph id: \"" <<
id <<
"\" to \"" << id2 <<
"\" since it is unset" <<
endmsg;
434 graph = getHist_i<TGraph>(
id );
435 if (
graph !=
nullptr ) {
443 lh = regShared_i<TH1>(
id,
std::move( hist ) );
452 lh = regShared_i<TH2>(
id,
std::move( hist ) );
461 lh = regShared_i<TH3>(
id,
std::move( hist ) );
479 lh = getShared_i<TH1>(
name );
488 lh = getShared_i<TH2>(
name );
497 lh = getShared_i<TH3>(
name );
506 lh = getShared_i<TGraph>(
name );
517 error() <<
"Problem deregistering id \"" <<
id <<
"\": not found in registry" <<
endmsg;
522 debug() <<
"will deregister " << vh->
size() <<
" elements of id \"" <<
id <<
"\"" <<
endmsg;
525 size_t vh_size = vh->
size();
526 while ( vh_size-- ) {
527 if (
deReg( vh->
back().obj ).isFailure() ) {
529 error() <<
"Problems deRegistering " << vh->
size() <<
" element of id \"" <<
id <<
"\"" <<
endmsg;
540 vhid_t* vhid = obj_itr->second.first;
541 THistID hid = obj_itr->second.first->at( obj_itr->second.second );
545 error() <<
"Problems deregistering TObject \"" << obj->GetName() <<
"\" with id \"" << hid.
id 546 <<
"\": not in uidMap" <<
endmsg;
550 if ( vhid->
size() == 1 ) {
552 debug() <<
"vhid for " << hid.
id <<
" is empty. deleting" <<
endmsg;
559 [&]( idMap_t::const_reference i ) { return i.second->at( 0 ).obj == obj; } );
560 if ( id_itr == mitr.second ) {
561 error() <<
"Problems deregistering TObject \"" << obj->GetName() <<
"\" with id \"" << hid.
id 562 <<
"\": not in idMap" <<
endmsg;
568 error() <<
"Problems deregistering TObject \"" << obj->GetName() <<
"\" with id \"" << hid.
id 569 <<
"\": not in hlist" <<
endmsg;
573 vhid->
erase( vhid->
begin() + obj_itr->second.second );
582 }
else if ( vhid->
size() > 1 ) {
584 vhid->
erase( vhid->
begin() + obj_itr->second.second );
588 error() <<
"Deregistration failed unexpectedly. (bug in THistSvc?)" <<
endmsg;
592 error() <<
"Cannot unregister TObject \"" << obj->GetName() <<
"\": not known to THistSvc" <<
endmsg;
604 return merge( itr->second );
610 return merge( itr->second.first );
612 error() <<
"merge: unknown object " << obj <<
endmsg;
623 []( uidMap_t::const_reference i ) {
return i.second->at( 0 ).obj->IsA()->InheritsFrom(
"TH1" ); } );
631 []( uidMap_t::const_reference i ) {
return i.second->at( 0 ).obj->IsA()->InheritsFrom(
"TTree" ); } );
639 []( uidMap_t::const_reference i ) {
return i.second->at( 0 ).obj->IsA()->InheritsFrom(
"TGraph" ); } );
646 gErrorIgnoreLevel = kBreak;
649 error() <<
"getTHists: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
654 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
657 TIter nextkey( td->GetListOfKeys() );
658 while ( TKey* key = (TKey*)nextkey() ) {
661 TObject* obj = key->ReadObj();
662 if ( obj != 0 && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
664 }
else if ( obj != 0 && obj->IsA()->InheritsFrom(
"TH1" ) ) {
667 }
else if ( obj != 0 ) {
675 nextkey = td->GetListOfKeys();
676 while ( TKey* key = (TKey*)nextkey() ) {
677 TObject* obj = key->ReadObj();
678 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
679 TDirectory* tt = dynamic_cast<TDirectory*>( obj );
692 gErrorIgnoreLevel = kBreak;
701 r2 = itr->second.first->GetName();
706 debug() <<
"getTHists: \"" << dir <<
"\" looks like a stream name." 707 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
710 if ( gDirectory->cd( r2.
c_str() ) ) {
723 if ( !gDirectory->cd( dir.
c_str() ) ) {
724 error() <<
"getTHists: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
736 gErrorIgnoreLevel = kBreak;
739 error() <<
"getTHists: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
744 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
747 TIter nextkey( td->GetListOfKeys() );
748 while ( TKey* key = (TKey*)nextkey() ) {
751 TObject* obj = key->ReadObj();
752 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
754 }
else if ( obj && obj->IsA()->InheritsFrom(
"TH1" ) ) {
763 id =
id +
"/" + key->GetName();
765 id =
id + dir +
"/" + key->GetName();
782 nextkey = td->GetListOfKeys();
783 while ( TKey* key = (TKey*)nextkey() ) {
784 TObject* obj = key->ReadObj();
785 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
786 TDirectory* tt = dynamic_cast<TDirectory*>( obj );
798 gErrorIgnoreLevel = kBreak;
807 r2 = itr->second.first->GetName();
812 debug() <<
"getTHists: \"" << dir <<
"\" looks like a stream name." 813 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
816 if ( gDirectory->cd( r2.
c_str() ) ) {
818 sc =
getTHists( gDirectory, tl, rcs, reg );
827 if ( !gDirectory->cd( dir.
c_str() ) ) {
828 error() <<
"getTHists: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
832 warning() <<
"Unable to register histograms automatically " 833 <<
"without a valid stream name" <<
endmsg;
836 sc =
getTHists( gDirectory, tl, rcs, reg );
845 gErrorIgnoreLevel = kBreak;
848 error() <<
"getTTrees: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
853 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
856 TIter nextkey( td->GetListOfKeys() );
857 while ( TKey* key = (TKey*)nextkey() ) {
860 TObject* obj = key->ReadObj();
861 if ( obj != 0 && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
863 }
else if ( obj != 0 && obj->IsA()->InheritsFrom(
"TTree" ) ) {
866 }
else if ( obj != 0 ) {
874 nextkey = td->GetListOfKeys();
875 while ( TKey* key = (TKey*)nextkey() ) {
876 TObject* obj = key->ReadObj();
877 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
878 TDirectory* tt = dynamic_cast<TDirectory*>( obj );
890 gErrorIgnoreLevel = kBreak;
899 r2 = itr->second.first->GetName();
904 debug() <<
"getTTrees: \"" << dir <<
"\" looks like a stream name." 905 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
908 if ( gDirectory->cd( r2.
c_str() ) ) {
return getTTrees( gDirectory, tl, rcs ); }
914 if ( !gDirectory->cd( dir.
c_str() ) ) {
915 error() <<
"getTTrees: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
926 gErrorIgnoreLevel = kBreak;
929 error() <<
"getTTrees: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
934 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
937 TIter nextkey( td->GetListOfKeys() );
938 while ( TKey* key = (TKey*)nextkey() ) {
941 TObject* obj = key->ReadObj();
942 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
944 }
else if ( obj && obj->IsA()->InheritsFrom(
"TTree" ) ) {
953 id =
id +
"/" + key->GetName();
955 id =
id + dir +
"/" + key->GetName();
964 }
else if ( obj != 0 ) {
972 nextkey = td->GetListOfKeys();
973 while ( TKey* key = (TKey*)nextkey() ) {
974 TObject* obj = key->ReadObj();
975 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
976 TDirectory* tt = dynamic_cast<TDirectory*>( obj );
988 gErrorIgnoreLevel = kBreak;
997 r2 = itr->second.first->GetName();
1002 debug() <<
"getTTrees: \"" << dir <<
"\" looks like a stream name." 1003 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
1006 if ( gDirectory->cd( r2.
c_str() ) ) {
1007 return getTTrees( gDirectory, tl, rcs, reg );
1015 if ( !gDirectory->cd( dir.
c_str() ) ) {
1016 error() <<
"getTTrees: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
1020 return getTTrees( gDirectory, tl, rcs, reg );
1031 Long64_t mfs = (Long64_t)
m_maxFileSize.value() * (Long64_t)1048576;
1032 Long64_t mfs_warn = mfs * 95 / 100;
1036 for (
const auto& f :
m_files ) {
1037 TFile* tf = f.second.first;
1041 debug() <<
"stream: " << f.first <<
" name: " << tf->GetName() <<
" size: " << tf->GetSize() <<
endmsg;
1046 if ( tf->GetSize() > mfs ) {
1050 fatal() <<
"file \"" << tf->GetName() <<
"\" associated with stream \"" << f.first
1051 <<
"\" has exceeded the max file size of " <<
m_maxFileSize.value() <<
"MB. Terminating Job." <<
endmsg;
1054 if (
service(
"ApplicationMgr",
evt,
true ).isSuccess() ) {
1060 }
else if ( tf->GetSize() > mfs_warn ) {
1061 warning() <<
"file \"" << tf->GetName() <<
"\" associated with stream \"" << f.first
1062 <<
"\" is at 95% of its maximum allowable file size of " <<
m_maxFileSize.value() <<
"MB" <<
endmsg;
1071 bool all_good =
true;
1078 if (
service(
"IoComponentMgr", iomgr,
true ).isFailure() ) {
1079 error() <<
"could not retrieve I/O component manager !" <<
endmsg;
1086 gErrorIgnoreLevel = kFatal;
1088 for (
auto& ifile :
m_files ) {
1089 TFile* f = ifile.second.first;
1092 debug() <<
"file [" << fname <<
"] mode: [" << f->GetOption() <<
"] r:" << f->GetFileBytesRead()
1093 <<
" w:" << f->GetFileBytesWritten() <<
" cnt:" << f->GetFileCounter() <<
endmsg;
1096 if ( ifile.second.second ==
READ ) {
1101 if ( !iomgr->
io_retrieve(
this, fname ).isSuccess() ) {
1102 error() <<
"could not retrieve new name for [" << fname <<
"] !!" <<
endmsg;
1105 }
else if ( fname.
empty() ) {
1113 Option_t*
opts = f->GetOption();
1116 error() <<
"unable to open file \"" << fname <<
"\" for writing" <<
endmsg;
1119 TFile* newfile = (TFile*)vf;
1120 newfile->SetOption(
opts );
1124 ifile.second.first = newfile;
1128 for (
auto& uid :
m_uids ) {
1129 for (
auto& hid : *uid.second ) {
1130 if ( hid.file != f )
continue;
1131 TDirectory* olddir = this->
changeDir( hid );
1134 TDirectory* newdir = this->
changeDir( hid );
1135 TClass* cl = hid.obj->IsA();
1139 if ( cl->InheritsFrom(
"TTree" ) ) {
1140 dynamic_cast<TTree*>( hid.obj )->SetDirectory( newdir );
1141 dynamic_cast<TTree*>( hid.obj )->Reset();
1142 }
else if ( cl->InheritsFrom(
"TH1" ) ) {
1143 dynamic_cast<TH1*>( hid.obj )->SetDirectory( newdir );
1144 dynamic_cast<TH1*>( hid.obj )->Reset();
1145 }
else if ( cl->InheritsFrom(
"TGraph" ) ) {
1146 olddir->Remove( hid.obj );
1147 newdir->Append( hid.obj );
1149 error() <<
"id: \"" << hid.id <<
"\" is not a inheriting from a class " 1150 <<
"we know how to handle (received [" << cl->GetName() <<
"], " 1151 <<
"expected [TTree, TH1 or TGraph]) !" <<
endmsg <<
"attaching to current dir [" << newdir->GetPath()
1153 <<
"nonetheless..." <<
endmsg;
1154 olddir->Remove( hid.obj );
1155 newdir->Append( hid.obj );
1159 f->ReOpen(
"READ" );
1176 gDirectory = m_gDirectory;
1178 gErrorIgnoreLevel = m_gErrorIgnoreLevel;
1183 template <
typename T>
1185 return dynamic_cast<T*>( readHist_i<T>(
id ) );
1199 for (
auto& hid : *( uitr->second ) ) {
1202 verbose() <<
" update: " << uitr->first <<
" " << hid.id <<
" " << hid.mode <<
endmsg;
1204 TObject* to = hid.obj;
1205 TFile* oldFile = hid.file;
1208 }
else if ( hid.temp || hid.mode ==
READ ) {
1214 }
else if ( to->IsA()->InheritsFrom(
"TTree" ) ) {
1215 TTree* tr = dynamic_cast<TTree*>( to );
1216 TFile* newFile = tr->GetCurrentFile();
1218 if ( oldFile != newFile ) {
1221 TFile* dummy =
nullptr;
1222 findStream( hid.id, streamName, rem, dummy );
1225 if ( itr.second.first == oldFile ) { itr.second.first = newFile; }
1228 for (
auto uitr2 = uitr; uitr2 !=
m_uids.
end(); ++uitr2 ) {
1229 for (
auto& hid2 : *( uitr2->second ) ) {
1230 if ( hid2.file == oldFile ) { hid2.file = newFile; }
1235 [&]( streamMap::const_reference
s ) {
return s.second == streamName; } );
1240 debug() <<
"migrating uid: " << hid.id <<
" stream: " << streamName <<
" oldFile: " << oldFileName
1241 <<
" newFile: " << newFileName <<
endmsg;
1245 if ( !oldFileName.
empty() ) {
1250 debug() <<
"changing filename \"" << i->first <<
"\" to \"" << newFileName <<
"\" for stream \"" 1251 << i->second <<
"\"" <<
endmsg;
1259 error() <<
"Problems updating fileStreams with new file name" <<
endmsg;
1271 auto mode = i.second.second;
1272 auto file = i.second.first;
1274 file->Write(
"", TObject::kOverwrite );
1275 }
else if ( mode ==
APPEND ) {
1281 debug() <<
"THistSvc::writeObjectsToFile()::List of Files connected in ROOT " <<
endmsg;
1282 TSeqCollection* filelist = gROOT->GetListOfFiles();
1283 for (
int ii = 0; ii < filelist->GetEntries(); ii++ ) {
1284 debug() <<
"THistSvc::writeObjectsToFile()::List of Files connected in ROOT: \"" << filelist->At( ii )->GetName()
1293 auto loc = ident.
find(
" " );
1301 if ( loc != std::string::npos ) {
1303 for (
auto attrib : Parser( ident.
substr( loc + 1 ) ) ) {
1304 auto TAG = boost::algorithm::to_upper_copy( attrib.tag );
1305 auto VAL = boost::algorithm::to_upper_copy( attrib.value );
1307 if ( TAG ==
"FILE" || TAG ==
"DATAFILE" ) {
1310 }
else if ( TAG ==
"OPT" ) {
1311 if ( VAL ==
"APPEND" || VAL ==
"UPDATE" ) {
1313 }
else if ( VAL ==
"CREATE" || VAL ==
"NEW" || VAL ==
"WRITE" ) {
1315 }
else if ( VAL ==
"RECREATE" ) {
1317 }
else if ( VAL ==
"SHARE" ) {
1319 }
else if ( VAL ==
"OLD" || VAL ==
"READ" ) {
1322 error() <<
"Unknown OPT: \"" << attrib.value <<
"\"" <<
endmsg;
1325 }
else if ( TAG ==
"TYP" ) {
1327 }
else if ( TAG ==
"CL" ) {
1335 if ( stream ==
"temp" ) {
1336 error() <<
"in JobOption \"" << ident <<
"\": stream name \"temp\" reserved." <<
endmsg;
1340 if ( db_typ !=
"ROOT" ) {
1341 error() <<
"in JobOption \"" << ident <<
"\": technology type \"" << db_typ <<
"\" not supported." <<
endmsg;
1346 error() <<
"in JobOption \"" << ident <<
"\":\n stream \"" << stream <<
"\" already connected to file: \"" 1353 error() <<
"No OPT= specified or unknown access mode in: " << ident <<
endmsg;
1361 const std::string& oldstream = fitr.first->second;
1363 const auto& f_info =
m_files[oldstream];
1365 if ( newMode != f_info.second ) {
1366 error() <<
"in JobOption \"" << ident <<
"\":\n file \"" <<
filename <<
"\" already opened by stream: \"" 1367 << oldstream <<
"\" with different access mode." <<
endmsg;
1370 TFile* f2 = f_info.first;
1373 debug() <<
"Connecting stream: \"" << stream <<
"\" to previously opened TFile: \"" <<
filename <<
"\"" 1380 if (
service(
"IncidentSvc",
pi ).isFailure() ) {
1381 error() <<
"Unable to get the IncidentSvc" <<
endmsg;
1428 static int ishared = 0;
1433 debug() <<
"Creating temp file \"" <<
filename <<
"\" and realfilename=" << realfilename <<
endmsg;
1462 debug() <<
"Opening TFile \"" <<
filename <<
"\" stream: \"" << stream <<
"\" mode: \"" << typ <<
"\"" 1463 <<
" comp level: " << cl <<
endmsg;
1471 TFile* file = hid.
file;
1484 if ( !gDirectory->GetKey( dir.
c_str() ) ) { gDirectory->mkdir( dir.
c_str() ); }
1485 gDirectory->cd( dir.
c_str() );
1492 std::string::size_type i = dir.
find(
"/" );
1494 if ( i == std::string::npos )
return {};
1508 while (
id.find(
"//" ) != std::string::npos ) {
id.replace(
id.find(
"//" ), 2,
"/" ); }
1513 TString
path( (
char*)strstr( target->GetPath(),
":" ) );
1514 path.Remove( 0, 2 );
1517 TDirectory* current_sourcedir = gDirectory;
1520 TList* lkeys = current_sourcedir->GetListOfKeys();
1521 int nkeys = lkeys->GetEntries();
1522 TKey* key =
nullptr;
1523 for (
int jj = 0; jj < nkeys; jj++ ) {
1524 key = (TKey*)lkeys->At( jj );
1527 TObject* obj = source->Get( pathnameinsource.
c_str() );
1530 if ( obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
1536 TDirectory* newtargetdir = target->mkdir( obj->GetName(), obj->GetTitle() );
1540 }
else if ( obj->IsA()->InheritsFrom(
"TTree" ) ) {
1542 TTree* mytree = dynamic_cast<TTree*>( obj );
1543 int nentries = (int)mytree->GetEntries();
1544 mytree->SetBranchStatus(
"*", 1 );
1548 mytree->CloneTree();
1552 obj->Write( key->GetName() );
1559 auto pos =
id.find(
"/" );
1561 if ( pos == std::string::npos ) {
1565 }
else if ( pos != 0 ) {
1572 auto pos2 =
id.
find(
"/", pos + 1 );
1574 if ( pos2 == std::string::npos ) {
1576 error() <<
"badly formed Hist/Tree id: \"" <<
id <<
"\"" <<
endmsg;
1582 if ( stream ==
"temp" ) {
1588 file = ( itr !=
m_files.
end() ? itr->second.first : nullptr );
1589 if ( !file ) {
warning() <<
"no stream \"" << stream <<
"\" associated with id: \"" <<
id <<
"\"" <<
endmsg; }
1595 auto pos =
id.find(
"/" );
1597 if ( pos == std::string::npos ) {
1600 }
else if ( pos == 0 ) {
1603 root =
id.substr( 0, pos );
1604 rem =
id.
substr( pos + 1 );
1610 debug() <<
"Delaying connection of Input Files until Initialize" 1615 debug() <<
"Now connecting of Input Files" <<
endmsg;
1634 debug() <<
"Delaying connection of Input Files until Initialize" 1654 debug() <<
"copyFileLayout() to destination path: " << destination->GetPath() <<
endmsg;
1658 TString
path( (
char*)strstr( destination->GetPath(),
":" ) );
1659 path.Remove( 0, 2 );
1662 TDirectory* current_source_dir = gDirectory;
1665 TList* key_list = current_source_dir->GetListOfKeys();
1666 int n = key_list->GetEntries();
1667 for (
int j = 0; j <
n; ++j ) {
1668 TKey* k = (TKey*)key_list->At( j );
1670 TObject* o = source->Get( source_pathname.
c_str() );
1672 if ( o && o->IsA()->InheritsFrom(
"TDirectory" ) ) {
1676 TDirectory* destination_dir = destination->mkdir( o->GetName(), o->GetTitle() );
1677 if ( destination_dir ==
nullptr ) destination_dir = destination->GetDirectory( o->GetName() );
1692 if ( idr.
find(
"/" ) == 0 ) {
1700 if ( index >= itr->second->size() ) {
1701 error() <<
"no index " << index <<
" found for Hist " << idr <<
endmsg;
1704 hid = &( itr->second->at( index ) );
1710 if ( mitr.first == mitr.second ) {
1713 }
else if ( distance( mitr.first, mitr.second ) == 1 ) {
1715 if ( index >= mitr.first->second->size() ) {
1716 error() <<
"no index " << index <<
" found for Hist " << idr <<
endmsg;
1719 hid = &( mitr.first->second->at( 0 ) );
1723 hid = &( mitr.first->second->at( 0 ) );
1724 return distance( mitr.first, mitr.second );
1733 ost <<
"m_hlist: size: " <<
m_hlist.
size() <<
"\n";
1735 ost <<
" - " << vh->at( 0 ) <<
" :: [" << vh <<
"] " << vh->size() <<
" {";
1736 for (
auto& e : *vh ) {
1738 ost <<
"[" << o <<
"]";
1746 for (
auto& e :
m_uids ) { ost <<
" - " << e.first <<
" [" << e.second <<
"]" <<
std::endl; }
1751 for (
auto& e :
m_ids ) { ost <<
" - " << e.first <<
" [" << e.second <<
"]" <<
std::endl; }
1757 TObject* o = e.first;
1758 THistID& i = e.second.first->at( e.second.second );
1759 ost <<
" - " << o <<
" -> " << i <<
std::endl;
1769 if ( vh->
size() == 1 ) {
1770 debug() <<
"merge: id: \"" <<
name <<
"\" is size 1. nothing to do" <<
endmsg;
1774 if ( !vh->
at( 0 ).obj->IsA()->InheritsFrom(
"TH1" ) ) {
1775 error() <<
"merge: id \"" <<
name <<
"\" is not a THn. Cannot merge" <<
endmsg;
1779 TList*
l =
new TList();
1780 for (
size_t i = 1; i < vh->
size(); ++i ) {
1781 debug() <<
"merge: id: \"" <<
name <<
"\" (" << vh->
at( i ).obj <<
") adding index " << i <<
endmsg;
1782 l->Add( vh->
at( i ).obj );
1785 TH1* t0 = dynamic_cast<TH1*>( vh->
at( 0 ).obj );
1787 error() <<
"merge: could not dcast " <<
name <<
"(" << t0 <<
") index " << 0 <<
" to TH1" <<
endmsg;
1791 Long64_t
n = t0->Merge(
l );
1793 debug() <<
"merge: id: \"" <<
name <<
"\" merged " <<
n <<
" entries" <<
endmsg;
1795 for (
size_t i = 1; i < vh->
size(); ++i ) {
1796 TH1* th = dynamic_cast<TH1*>( vh->
at( i ).obj );
1798 debug() <<
"clearing index " << i <<
"(" << th <<
")" <<
endmsg;
1799 th->SetDirectory(
nullptr );
1802 error() <<
"merge: could not dcast " <<
name <<
" index " << i <<
" to TH1" <<
endmsg;
Parse attribute strings allowing iteration over the various attributes.
GlobalDirectoryRestore(THistSvcMutex_t &mut)
Helper struct that bundles the histogram ID with a mutex, TFile and TObject*.
StatusCode initialize() override
void MergeRootFile(TDirectory *, TDirectory *)
std::vector< std::string > getTrees() const override
This class is the FileIncident.
StatusCode initialize() override
StatusCode deReg(const std::string &name) override
Deregister object with given name and give up ownership (without deletion!)
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
StatusCode finalize() override
Gaudi::StateMachine::State FSMState() const override
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
StatusCode regShared(const std::string &name, std::unique_ptr< TH1 >, LockedHandle< TH1 > &) override
Register shared object of type TH1 and return LockedHandle for that object.
This file contains the class definition for the FileIncident class.
StatusCode getShared(const std::string &name, LockedHandle< TH1 > &) const override
Retrieve shared object with given name as TH1 through LockedHandle.
T * readHist(const std::string &name) const
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
const std::string & name() const
StatusCode writeObjectsToFile()
constexpr static const auto SUCCESS
StatusCode merge(const std::string &id) override
Merge all clones for object with a given id.
StatusCode getGraph(const std::string &name, TGraph *&) const override
Return TGraph with given name.
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::string stripDirectoryName(std::string &dir) const
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Gaudi::Property< std::vector< std::string > > m_outputfile
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
virtual StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &d="")=0
#define DECLARE_COMPONENT(type)
void setupOutputFile()
call-back method to handle output stream property
void parseString(const std::string &id, std::string &root, std::string &rem) const
void setupInputFile()
call-back method to handle input stream property
const std::string & name() const override
Retrieve name of the service.
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.
Gaudi::Property< std::vector< std::string > > m_inputfile
StatusCode getTree(const std::string &name, TTree *&) const override
Return TTree with given name.
This class is used for returning status codes from appropriate routines.
Provides automatic lock/unlock access to a class upon deref of ptr.
Gaudi::Property< bool > m_print
void handle(const Incident &) override
Gaudi::Property< int > m_maxFileSize
std::vector< std::string > getHists() const override
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
static Mode charToMode(const char typ)
Convert a char to a Mode enum.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
~GlobalDirectoryRestore()
TDirectory * changeDir(const THistSvc::THistID &hid) const
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
StatusCode finalize() override
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
const std::string & desc() const
StatusCode regHist(const std::string &name) override
Register a new ROOT histogram TH*X with a name.
StatusCode getHist(const std::string &name, TH1 *&, size_t index=0) const override
Return histogram with given name as TH1*, THistSvcMT still owns object.
virtual std::vector< std::string > io_retrieve(IIoComponent *iocomponent)=0
: retrieve all registered filenames for a given IIoComponent
const StatusCode & ignore() const
Ignore/check StatusCode.
StatusCode reinitialize() override
T back_inserter(T... args)
void removeDoubleSlash(std::string &) const
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
StatusCode connect(const std::string &)
constexpr static const auto FAILURE
The IEventProcessor is the interface to process events.
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 regTree(const std::string &name) override
Register a new TTree with a given name.
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.
bool exists(const std::string &name) const override
Check if object with given name is managed by THistSvcMT.
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
AttribStringParser::Iterator begin(const AttribStringParser &parser)
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
StatusCode regGraph(const std::string &name) override
Register a new TGraph with a given name.
Gaudi::Property< int > m_autoFlush
StatusCode io_reinit() override
callback method to reinitialize the internal state of the component for I/O purposes (e....
size_t findHistID(const std::string &id, const THistID *&hid, const size_t &index=0) const
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
TTree * readTree(const std::string &name) const
Helper class that manages ROOts global directory and file.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
TDirectory * m_gDirectory
The interface implemented by the IncidentSvc service.
void updateFiles()
Handle case where TTree grows beyond TTree::fgMaxTreeSize.
std::vector< std::string > getGraphs() const override
T emplace_back(T... args)
virtual Io::close_t close(const Io::Fd, const std::string &caller)=0