18 #include <boost/algorithm/string/case_conv.hpp>
22 #include <TDirectory.h>
59 template <
typename InputIterator,
typename OutputIterator,
typename UnaryOperation,
typename UnaryPredicate>
60 OutputIterator transform_if( InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op,
61 UnaryPredicate pred ) {
62 while ( first != last ) {
63 if ( pred( *first ) ) *result++ = op( *first );
69 constexpr
struct select1st_t {
70 template <
typename T,
typename S>
85 error() <<
"initializing service" <<
endmsg;
94 error() <<
"Caught: " << err <<
endmsg;
101 error() <<
"Caught: " << err <<
endmsg;
107 static TROOT
root(
"root",
"ROOT I/O" );
114 error() <<
"unable to get the IncidentSvc" <<
endmsg;
121 error() <<
"unable to get the FileMgr" <<
endmsg;
131 error() <<
"unable to register ROOT file open action with FileMgr" <<
endmsg;
137 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;
155 error() <<
"could not register with the I/O component manager !" <<
endmsg;
158 bool all_good =
true;
160 for (
const auto& reg :
m_files ) {
161 const std::string& fname = reg.second.first->GetName();
165 warning() <<
"could not register file [" << fname <<
"] with the I/O component manager..." <<
endmsg;
168 info() <<
"registered file [" << fname <<
"]... [ok]" <<
endmsg;
172 error() <<
"problem while registering input/output files with "
173 <<
"the I/O component manager !" <<
endmsg;
179 if ( st.
isFailure() ) { fatal() <<
"Unable to initialize THistSvc" <<
endmsg; }
186 warning() <<
"reinitialize not implemented" <<
endmsg;
195 debug() <<
"THistSvc::finalize" <<
endmsg;
201 for (
const auto& itr : sorted_uids ) {
202 THistID& thid = itr.second->at( 0 );
203 TObject* tobj = thid.
obj;
207 TTree* tree =
dynamic_cast<TTree*
>( tobj );
208 if ( tree->GetDirectory() != 0 ) { dirname = tree->GetDirectory()->GetPath(); }
211 dirname = thid.
file->GetPath();
215 if ( id2.
find(
"/" ) == 0 ) { id2.
erase( 0, 1 ); }
221 TH1* th =
dynamic_cast<TH1*
>( tobj );
222 if ( th ==
nullptr ) {
223 error() <<
"Couldn't dcast: " << itr.first <<
endmsg;
225 if ( th->GetDirectory() != 0 ) { dirname = th->GetDirectory()->GetPath(); }
227 }
else if ( !tobj ) {
228 warning() << itr.first <<
" has NULL TObject ptr" <<
endmsg;
230 debug() <<
"finalize: " << thid <<
endmsg;
237 if (
m_print ) { info() <<
"Listing contents of ROOT files: " <<
endmsg; }
240 if (
std::find( deleted_files.
begin(), deleted_files.
end(), itr.second.first ) == deleted_files.
end() ) {
241 deleted_files.
push_back( itr.second.first );
245 debug() <<
"finalizing stream/file " << itr.first <<
":" << itr.second.first->GetName() <<
endmsg;
256 info() <<
"==> File: " << itr.second.first->GetName() <<
" stream: " << itr.first <<
endmsg;
258 itr.second.first->Print(
"base" );
266 if (
service(
"IncidentSvc", pIncidentSvc ).isFailure() ) {
267 error() <<
"Unable to get the IncidentSvc" <<
endmsg;
271 if ( itr.second.second ==
SHARE ) {
273 void* vfile =
nullptr;
278 error() <<
"unable to open Final Output File: \"" <<
m_sharedFiles[itr.first] <<
"\" for merging" <<
endmsg;
282 TFile* outputfile = (TFile*)vfile;
291 error() <<
"unable to open temporary file: \"" << tmpfn <<
endmsg;
295 TFile* inputfile = (TFile*)vfile;
297 outputfile->SetCompressionLevel( inputfile->GetCompressionLevel() );
309 delete itr.second.first;
322 if ( obj.second.second == 0 ) {
323 delete obj.second.first;
348 hist = getHist_i<TH1>(
id, ind );
349 if ( hist !=
nullptr ) {
357 hist = getHist_i<TH2>(
id, ind );
358 if ( hist !=
nullptr ) {
366 hist = getHist_i<TH3>(
id, ind );
367 if ( hist !=
nullptr ) {
401 tree = getHist_i<TTree>(
id );
402 if ( tree !=
nullptr ) {
415 if ( strcmp(
graph->GetName(),
"Graph" ) == 0 ) {
417 std::string::size_type i = id2.
rfind(
"/" );
418 if ( i != std::string::npos ) { id2.
erase( 0, i + 1 ); }
420 info() <<
"setting name of TGraph id: \"" <<
id <<
"\" to \"" << id2 <<
"\" since it is unset" <<
endmsg;
429 if ( strcmp(
graph->GetName(),
"Graph" ) == 0 ) {
431 std::string::size_type i = id2.
rfind(
"/" );
432 if ( i != std::string::npos ) { id2.
erase( 0, i + 1 ); }
434 info() <<
"setting name of TGraph id: \"" <<
id <<
"\" to \"" << id2 <<
"\" since it is unset" <<
endmsg;
442 graph = getHist_i<TGraph>(
id );
443 if (
graph !=
nullptr ) {
465 eff = getHist_i<TEfficiency>(
id );
466 if ( eff !=
nullptr ) {
474 lh = regShared_i<TH1>(
id,
std::move( hist ) );
483 lh = regShared_i<TH2>(
id,
std::move( hist ) );
492 lh = regShared_i<TH3>(
id,
std::move( hist ) );
511 lh = regShared_i<TEfficiency>(
id,
std::move( eff ) );
520 lh = getShared_i<TH1>(
name );
529 lh = getShared_i<TH2>(
name );
538 lh = getShared_i<TH3>(
name );
547 lh = getShared_i<TGraph>(
name );
556 lh = getShared_i<TEfficiency>(
name );
567 error() <<
"Problem deregistering id \"" <<
id <<
"\": not found in registry" <<
endmsg;
574 debug() <<
"will deregister " << vh->
size() <<
" elements of id \"" <<
id <<
"\"" <<
endmsg;
578 size_t vh_size = vh->
size();
579 while ( vh_size-- ) {
582 error() <<
"Problems deRegistering " << vh->
size() <<
" element of id \"" <<
id <<
"\"" <<
endmsg;
593 vhid_t* vhid = obj_itr->second.first;
594 THistID hid = obj_itr->second.first->at( obj_itr->second.second );
598 error() <<
"Problems deregistering TObject \"" << obj->GetName() <<
"\" with id \"" << hid.
id
599 <<
"\": not in uidMap" <<
endmsg;
603 if ( vhid->
size() == 1 ) {
612 [&]( idMap_t::const_reference i ) { return i.second->at( 0 ).obj == obj; } );
613 if ( id_itr == mitr.second ) {
614 error() <<
"Problems deregistering TObject \"" << obj->GetName() <<
"\" with id \"" << hid.
id
615 <<
"\": not in idMap" <<
endmsg;
621 error() <<
"Problems deregistering TObject \"" << obj->GetName() <<
"\" with id \"" << hid.
id
622 <<
"\": not in hlist" <<
endmsg;
626 vhid->
erase( vhid->
begin() + obj_itr->second.second );
635 }
else if ( vhid->
size() > 1 ) {
636 vhid->
erase( vhid->
begin() + obj_itr->second.second );
641 error() <<
"Deregistration failed unexpectedly. (bug in THistSvc?)" <<
endmsg;
645 error() <<
"Cannot unregister TObject \"" << obj->GetName() <<
"\": not known to THistSvc" <<
endmsg;
653 error() <<
"merge: id \"" <<
name <<
"\" not found" <<
endmsg;
657 return merge( itr->second );
663 return merge( itr->second.first );
665 error() <<
"merge: unknown object " << obj <<
endmsg;
675 return ( getHist_i<TEfficiency>(
name, 0,
true ) !=
nullptr );
679 return ( getHist_i<TGraph>(
name, 0,
true ) !=
nullptr );
719 gErrorIgnoreLevel = kBreak;
722 error() <<
"getTHists: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
727 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
730 TIter nextkey( td->GetListOfKeys() );
731 while ( TKey*
key = (TKey*)nextkey() ) {
734 TObject* obj =
key->ReadObj();
735 if ( obj != 0 && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
737 }
else if ( obj != 0 && obj->IsA()->InheritsFrom(
"TH1" ) ) {
740 }
else if ( obj != 0 ) {
748 nextkey = td->GetListOfKeys();
749 while ( TKey*
key = (TKey*)nextkey() ) {
750 TObject* obj =
key->ReadObj();
751 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
752 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
765 gErrorIgnoreLevel = kBreak;
774 r2 = itr->second.first->GetName();
779 debug() <<
"getTHists: \"" << dir <<
"\" looks like a stream name."
780 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
783 if ( gDirectory->cd( r2.
c_str() ) ) {
796 if ( !gDirectory->cd( dir.
c_str() ) ) {
797 error() <<
"getTHists: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
809 gErrorIgnoreLevel = kBreak;
812 error() <<
"getTHists: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
817 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
820 TIter nextkey( td->GetListOfKeys() );
821 while ( TKey*
key = (TKey*)nextkey() ) {
824 TObject* obj =
key->ReadObj();
825 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
827 }
else if ( obj && obj->IsA()->InheritsFrom(
"TH1" ) ) {
836 id =
id +
"/" +
key->GetName();
838 id =
id + dir +
"/" +
key->GetName();
855 nextkey = td->GetListOfKeys();
856 while ( TKey*
key = (TKey*)nextkey() ) {
857 TObject* obj =
key->ReadObj();
858 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
859 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
871 gErrorIgnoreLevel = kBreak;
880 r2 = itr->second.first->GetName();
885 debug() <<
"getTHists: \"" << dir <<
"\" looks like a stream name."
886 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
889 if ( gDirectory->cd( r2.
c_str() ) ) {
891 sc =
getTHists( gDirectory, tl, rcs, reg );
900 if ( !gDirectory->cd( dir.
c_str() ) ) {
901 error() <<
"getTHists: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
905 warning() <<
"Unable to register histograms automatically "
906 <<
"without a valid stream name" <<
endmsg;
909 sc =
getTHists( gDirectory, tl, rcs, reg );
918 gErrorIgnoreLevel = kBreak;
921 error() <<
"getTTrees: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
926 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
929 TIter nextkey( td->GetListOfKeys() );
930 while ( TKey*
key = (TKey*)nextkey() ) {
933 TObject* obj =
key->ReadObj();
934 if ( obj != 0 && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
936 }
else if ( obj != 0 && obj->IsA()->InheritsFrom(
"TTree" ) ) {
939 }
else if ( obj != 0 ) {
947 nextkey = td->GetListOfKeys();
948 while ( TKey*
key = (TKey*)nextkey() ) {
949 TObject* obj =
key->ReadObj();
950 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
951 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
963 gErrorIgnoreLevel = kBreak;
972 r2 = itr->second.first->GetName();
977 debug() <<
"getTTrees: \"" << dir <<
"\" looks like a stream name."
978 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
981 if ( gDirectory->cd( r2.
c_str() ) ) {
return getTTrees( gDirectory, tl, rcs ); }
987 if ( !gDirectory->cd( dir.
c_str() ) ) {
988 error() <<
"getTTrees: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
999 gErrorIgnoreLevel = kBreak;
1002 error() <<
"getTTrees: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
1007 debug() <<
"getTHists: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
1010 TIter nextkey( td->GetListOfKeys() );
1011 while ( TKey*
key = (TKey*)nextkey() ) {
1012 auto&
log = debug();
1014 TObject* obj =
key->ReadObj();
1015 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
1017 }
else if ( obj && obj->IsA()->InheritsFrom(
"TTree" ) ) {
1026 id =
id +
"/" +
key->GetName();
1028 id =
id + dir +
"/" +
key->GetName();
1037 }
else if ( obj != 0 ) {
1045 nextkey = td->GetListOfKeys();
1046 while ( TKey*
key = (TKey*)nextkey() ) {
1047 TObject* obj =
key->ReadObj();
1048 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
1049 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
1061 gErrorIgnoreLevel = kBreak;
1070 r2 = itr->second.first->GetName();
1075 debug() <<
"getTTrees: \"" << dir <<
"\" looks like a stream name."
1076 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
1079 if ( gDirectory->cd( r2.
c_str() ) ) {
1080 return getTTrees( gDirectory, tl, rcs, reg );
1088 if ( !gDirectory->cd( dir.
c_str() ) ) {
1089 error() <<
"getTTrees: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
1093 return getTTrees( gDirectory, tl, rcs, reg );
1099 gErrorIgnoreLevel = kBreak;
1102 error() <<
"getTEfficiencies: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
1107 debug() <<
"getTEfficiencies: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys"
1111 TIter nextkey( td->GetListOfKeys() );
1112 while ( TKey*
key = (TKey*)nextkey() ) {
1113 auto&
log = debug();
1115 TObject* obj =
key->ReadObj();
1116 if ( obj != 0 && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
1118 }
else if ( obj != 0 && obj->IsA()->InheritsFrom(
"TEfficiency" ) ) {
1121 }
else if ( obj != 0 ) {
1129 nextkey = td->GetListOfKeys();
1130 while ( TKey*
key = (TKey*)nextkey() ) {
1131 TObject* obj =
key->ReadObj();
1132 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
1133 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
1146 gErrorIgnoreLevel = kBreak;
1155 r2 = itr->second.first->GetName();
1160 debug() <<
"getTEfficiencies: \"" << dir <<
"\" looks like a stream name."
1161 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
1164 if ( gDirectory->cd( r2.
c_str() ) ) {
1177 if ( !gDirectory->cd( dir.
c_str() ) ) {
1178 error() <<
"getTEfficiencies: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
1190 gErrorIgnoreLevel = kBreak;
1193 error() <<
"getTEfficiencies: No such TDirectory \"" << td->GetPath() <<
"\"" <<
endmsg;
1198 debug() <<
"getTEfficiencies: \"" << td->GetPath() <<
"\": found " << td->GetListOfKeys()->GetSize() <<
" keys"
1202 TIter nextkey( td->GetListOfKeys() );
1203 while ( TKey*
key = (TKey*)nextkey() ) {
1204 auto&
log = debug();
1206 TObject* obj =
key->ReadObj();
1207 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
1209 }
else if ( obj && obj->IsA()->InheritsFrom(
"TEfficiency" ) ) {
1218 id =
id +
"/" +
key->GetName();
1220 id =
id + dir +
"/" +
key->GetName();
1237 nextkey = td->GetListOfKeys();
1238 while ( TKey*
key = (TKey*)nextkey() ) {
1239 TObject* obj =
key->ReadObj();
1240 if ( obj && obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
1241 TDirectory* tt =
dynamic_cast<TDirectory*
>( obj );
1253 gErrorIgnoreLevel = kBreak;
1262 r2 = itr->second.first->GetName();
1267 debug() <<
"getTEfficiencies: \"" << dir <<
"\" looks like a stream name."
1268 <<
" associated TFile: \"" << itr->second.first->GetName() <<
"\"" <<
endmsg;
1271 if ( gDirectory->cd( r2.
c_str() ) ) {
1282 if ( !gDirectory->cd( dir.
c_str() ) ) {
1283 error() <<
"getTEfficiencies: No such TDirectory/stream \"" << dir <<
"\"" <<
endmsg;
1287 warning() <<
"Unable to register histograms automatically "
1288 <<
"without a valid stream name" <<
endmsg;
1306 Long64_t mfs_warn = mfs * 95 / 100;
1310 for (
const auto& f :
m_files ) {
1311 TFile* tf = f.second.first;
1315 debug() <<
"stream: " << f.first <<
" name: " << tf->GetName() <<
" size: " << tf->GetSize() <<
endmsg;
1320 if ( tf->GetSize() > mfs ) {
1324 fatal() <<
"file \"" << tf->GetName() <<
"\" associated with stream \"" << f.first
1328 if (
service(
"ApplicationMgr",
evt,
true ).isSuccess() ) {
1329 evt->stopRun().ignore( );
1334 }
else if ( tf->GetSize() > mfs_warn ) {
1335 warning() <<
"file \"" << tf->GetName() <<
"\" associated with stream \"" << f.first
1345 bool all_good =
true;
1352 if (
service(
"IoComponentMgr", iomgr,
true ).isFailure() ) {
1353 error() <<
"could not retrieve I/O component manager !" <<
endmsg;
1360 gErrorIgnoreLevel = kFatal;
1362 for (
auto& ifile :
m_files ) {
1363 TFile* f = ifile.second.first;
1366 debug() <<
"file [" << fname <<
"] mode: [" << f->GetOption() <<
"] r:" << f->GetFileBytesRead()
1367 <<
" w:" << f->GetFileBytesWritten() <<
" cnt:" << f->GetFileCounter() <<
endmsg;
1370 if ( ifile.second.second ==
READ ) {
1375 if ( !iomgr->
io_retrieve(
this, fname ).isSuccess() ) {
1376 error() <<
"could not retrieve new name for [" << fname <<
"] !!" <<
endmsg;
1379 }
else if ( fname.
empty() ) {
1387 Option_t*
opts = f->GetOption();
1390 error() <<
"unable to open file \"" << fname <<
"\" for writing" <<
endmsg;
1393 TFile* newfile = (TFile*)vf;
1394 newfile->SetOption(
opts );
1398 ifile.second.first = newfile;
1402 for (
auto& uid :
m_uids ) {
1403 for (
auto& hid : *uid.second ) {
1404 if ( hid.file != f )
continue;
1405 TDirectory* olddir = this->
changeDir( hid );
1408 TDirectory* newdir = this->
changeDir( hid );
1409 TClass* cl = hid.obj->IsA();
1414 TTree& tree =
dynamic_cast<TTree&
>( *hid.obj );
1415 tree.SetDirectory( newdir );
1418 TH1& hist =
dynamic_cast<TH1&
>( *hid.obj );
1419 hist.SetDirectory( newdir );
1422 dynamic_cast<TEfficiency&
>( *hid.obj ).SetDirectory( newdir );
1424 olddir->Remove( hid.obj );
1425 newdir->Append( hid.obj );
1427 error() <<
"id: \"" << hid.id <<
"\" is not a inheriting from a class "
1428 <<
"we know how to handle (received [" << cl->GetName() <<
"], "
1429 <<
"expected [TTree, TH1, TGraph or TEfficiency]) !" <<
endmsg <<
"attaching to current dir ["
1430 << newdir->GetPath() <<
"] "
1431 <<
"nonetheless..." <<
endmsg;
1432 olddir->Remove( hid.obj );
1433 newdir->Append( hid.obj );
1437 f->ReOpen(
"READ" );
1454 gDirectory = m_gDirectory;
1456 gErrorIgnoreLevel = m_gErrorIgnoreLevel;
1461 template <
typename T>
1463 return dynamic_cast<T*
>( readHist_i<T>(
id ) );
1478 for (
auto& hid : *( uitr->second ) ) {
1481 if ( hid.type !=
ObjectType::TTREE || hid.temp || hid.mode ==
READ || hid.obj ==
nullptr )
continue;
1484 verbose() <<
" update: " << uitr->first <<
" " << hid.id <<
" " << hid.mode <<
endmsg;
1486 TTree* tr =
dynamic_cast<TTree*
>( hid.obj );
1487 TFile* oldFile = hid.file;
1488 TFile* newFile = tr->GetCurrentFile();
1490 if ( oldFile != newFile ) {
1493 TFile* dummy =
nullptr;
1494 findStream( hid.id, streamName, rem, dummy );
1497 if ( itr.second.first == oldFile ) { itr.second.first = newFile; }
1500 for (
auto uitr2 = uitr; uitr2 !=
m_uids.
end(); ++uitr2 ) {
1501 for (
auto& hid2 : *( uitr2->second ) ) {
1502 if ( hid2.file == oldFile ) { hid2.file = newFile; }
1507 [&]( streamMap::const_reference
s ) {
return s.second == streamName; } );
1512 debug() <<
"migrating uid: " << hid.id <<
" stream: " << streamName <<
" oldFile: " << oldFileName
1513 <<
" newFile: " << newFileName <<
endmsg;
1517 if ( !oldFileName.
empty() ) {
1522 debug() <<
"changing filename \"" << i->first <<
"\" to \"" << newFileName <<
"\" for stream \""
1523 << i->second <<
"\"" <<
endmsg;
1531 error() <<
"Problems updating fileStreams with new file name" <<
endmsg;
1542 auto mode = i.second.second;
1543 auto file = i.second.first;
1544 if ( mode == WRITE || mode == UPDATE || mode == SHARE ) {
1545 file->Write(
"", TObject::kOverwrite );
1546 }
else if ( mode ==
APPEND ) {
1552 debug() <<
"THistSvc::writeObjectsToFile()::List of Files connected in ROOT " <<
endmsg;
1553 TSeqCollection* filelist = gROOT->GetListOfFiles();
1554 for (
int ii = 0; ii < filelist->GetEntries(); ii++ ) {
1555 debug() <<
"THistSvc::writeObjectsToFile()::List of Files connected in ROOT: \"" << filelist->At( ii )->GetName()
1564 auto loc =
ident.find(
" " );
1572 if ( loc != std::string::npos ) {
1574 for (
auto attrib : Parser(
ident.substr( loc + 1 ) ) ) {
1578 auto TAG = attrib.tag;
1579 auto VAL = attrib.value;
1580 boost::algorithm::to_upper( TAG );
1581 boost::algorithm::to_upper( VAL );
1583 if ( TAG ==
"FILE" || TAG ==
"DATAFILE" ) {
1586 }
else if ( TAG ==
"OPT" ) {
1587 if ( VAL ==
"APPEND" || VAL ==
"UPDATE" ) {
1589 }
else if ( VAL ==
"CREATE" || VAL ==
"NEW" || VAL ==
"WRITE" ) {
1591 }
else if ( VAL ==
"RECREATE" ) {
1593 }
else if ( VAL ==
"SHARE" ) {
1595 }
else if ( VAL ==
"OLD" || VAL ==
"READ" ) {
1598 error() <<
"Unknown OPT: \"" << attrib.value <<
"\"" <<
endmsg;
1601 }
else if ( TAG ==
"TYP" ) {
1603 }
else if ( TAG ==
"CL" ) {
1606 props.emplace_back( attrib.tag, attrib.value );
1611 if (
stream ==
"temp" ) {
1612 error() <<
"in JobOption \"" <<
ident <<
"\": stream name \"temp\" reserved." <<
endmsg;
1616 if ( db_typ !=
"ROOT" ) {
1617 error() <<
"in JobOption \"" <<
ident <<
"\": technology type \"" << db_typ <<
"\" not supported." <<
endmsg;
1622 error() <<
"in JobOption \"" <<
ident <<
"\":\n stream \"" <<
stream <<
"\" already connected to file: \""
1629 error() <<
"No OPT= specified or unknown access mode in: " <<
ident <<
endmsg;
1637 const std::string& oldstream = fitr.first->second;
1639 const auto& f_info =
m_files[oldstream];
1641 if ( newMode != f_info.second ) {
1642 error() <<
"in JobOption \"" <<
ident <<
"\":\n file \"" <<
filename <<
"\" already opened by stream: \""
1643 << oldstream <<
"\" with different access mode." <<
endmsg;
1646 TFile* f2 = f_info.first;
1649 debug() <<
"Connecting stream: \"" <<
stream <<
"\" to previously opened TFile: \"" <<
filename <<
"\""
1656 if (
service(
"IncidentSvc",
pi ).isFailure() ) {
1657 error() <<
"Unable to get the IncidentSvc" <<
endmsg;
1669 error() <<
"Unable to open ROOT file " <<
filename <<
" for reading" <<
endmsg;
1683 error() <<
"Unable to open ROOT file " <<
filename <<
" for writing" <<
endmsg;
1693 error() <<
"unable to open file \"" <<
filename <<
"\" for appending" <<
endmsg;
1704 static int ishared = 0;
1709 debug() <<
"Creating temp file \"" <<
filename <<
"\" and realfilename=" << realfilename <<
endmsg;
1716 error() <<
"Unable to open ROOT file " <<
filename <<
" for writing" <<
endmsg;
1727 error() <<
"Unable to open ROOT file " <<
filename <<
" for appending" <<
endmsg;
1738 debug() <<
"Opening TFile \"" <<
filename <<
"\" stream: \"" <<
stream <<
"\" mode: \"" << typ <<
"\""
1739 <<
" comp level: " << cl <<
endmsg;
1747 TFile* file = hid.
file;
1760 if ( !gDirectory->GetKey( dir.
c_str() ) ) { gDirectory->mkdir( dir.
c_str() ); }
1761 gDirectory->cd( dir.
c_str() );
1768 std::string::size_type i = dir.
find(
"/" );
1770 if ( i == std::string::npos )
return {};
1784 while (
id.find(
"//" ) != std::string::npos ) {
id.replace(
id.find(
"//" ), 2,
"/" ); }
1789 TString
path( (
char*)strstr(
target->GetPath(),
":" ) );
1790 path.Remove( 0, 2 );
1793 TDirectory* current_sourcedir = gDirectory;
1796 TList* lkeys = current_sourcedir->GetListOfKeys();
1797 int nkeys = lkeys->GetEntries();
1798 TKey*
key =
nullptr;
1799 for (
int jj = 0; jj < nkeys; jj++ ) {
1800 key = (TKey*)lkeys->At( jj );
1803 TObject* obj = source->Get( pathnameinsource.
c_str() );
1806 if ( obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
1812 TDirectory* newtargetdir =
target->mkdir( obj->GetName(), obj->GetTitle() );
1816 }
else if ( obj->IsA()->InheritsFrom(
"TTree" ) ) {
1818 TTree* mytree =
dynamic_cast<TTree*
>( obj );
1819 int nentries = (int)mytree->GetEntries();
1820 mytree->SetBranchStatus(
"*", 1 );
1824 mytree->CloneTree();
1828 obj->Write(
key->GetName() );
1835 auto pos =
id.find(
"/" );
1837 if ( pos == std::string::npos ) {
1841 }
else if ( pos != 0 ) {
1848 auto pos2 =
id.find(
"/", pos + 1 );
1850 if ( pos2 == std::string::npos ) {
1852 error() <<
"badly formed Hist/Tree id: \"" <<
id <<
"\"" <<
endmsg;
1858 if (
stream ==
"temp" ) {
1865 if ( !file ) { warning() <<
"no stream \"" <<
stream <<
"\" associated with id: \"" <<
id <<
"\"" <<
endmsg; }
1871 auto pos =
id.find(
"/" );
1873 if ( pos == std::string::npos ) {
1876 }
else if ( pos == 0 ) {
1879 root =
id.substr( 0, pos );
1880 rem =
id.
substr( pos + 1 );
1886 debug() <<
"Delaying connection of Input Files until Initialize"
1891 debug() <<
"Now connecting of Input Files" <<
endmsg;
1897 if (
connect( itr ).isFailure() ) {
1910 debug() <<
"Delaying connection of Output Files until Initialize"
1917 if (
connect( itr ).isFailure() ) {
1930 debug() <<
"copyFileLayout() to destination path: " << destination->GetPath() <<
endmsg;
1934 TString
path( (
char*)strstr( destination->GetPath(),
":" ) );
1935 path.Remove( 0, 2 );
1938 TDirectory* current_source_dir = gDirectory;
1941 TList* key_list = current_source_dir->GetListOfKeys();
1942 int n = key_list->GetEntries();
1943 for (
int j = 0;
j <
n; ++
j ) {
1944 TKey* k = (TKey*)key_list->At(
j );
1946 TObject* o = source->Get( source_pathname.
c_str() );
1948 if ( o && o->IsA()->InheritsFrom(
"TDirectory" ) ) {
1952 TDirectory* destination_dir = destination->mkdir( o->GetName(), o->GetTitle() );
1953 if ( destination_dir ==
nullptr ) destination_dir = destination->GetDirectory( o->GetName() );
1968 if ( idr.
find(
"/" ) == 0 ) {
1976 if (
index >= itr->second->size() ) {
1977 error() <<
"no index " <<
index <<
" found for Hist " << idr <<
endmsg;
1980 hid = &( itr->second->at(
index ) );
1986 if ( mitr.first == mitr.second ) {
1989 }
else if ( distance( mitr.first, mitr.second ) == 1 ) {
1991 if (
index >= mitr.first->second->size() ) {
1992 error() <<
"no index " <<
index <<
" found for Hist " << idr <<
endmsg;
1995 hid = &( mitr.first->second->at( 0 ) );
1999 hid = &( mitr.first->second->at( 0 ) );
2000 return distance( mitr.first, mitr.second );
2009 ost <<
"m_hlist: size: " <<
m_hlist.
size() <<
"\n";
2011 ost <<
" - " << vh->at( 0 ) <<
" :: [" << vh <<
"] " << vh->size() <<
" {";
2012 for (
auto& e : *vh ) {
2014 ost <<
"[" << o <<
"]";
2022 for (
auto& e :
m_uids ) { ost <<
" - " << e.first <<
" [" << e.second <<
"]" <<
std::endl; }
2027 for (
auto& e :
m_ids ) { ost <<
" - " << e.first <<
" [" << e.second <<
"]" <<
std::endl; }
2033 TObject* o = e.first;
2034 THistID& i = e.second.first->at( e.second.second );
2035 ost <<
" - " << o <<
" -> " << i <<
std::endl;
2038 debug() <<
"dumping THistSvc contents\n" << ost.
str() <<
endmsg;
2045 if ( vh->
size() == 1 ) {
2046 debug() <<
"merge: id: \"" <<
name <<
"\" is size 1. nothing to do" <<
endmsg;
2051 error() <<
"merge: id \"" <<
name <<
"\" is not a THn. Cannot merge" <<
endmsg;
2055 TList*
l =
new TList();
2056 for (
size_t i = 1; i < vh->
size(); ++i ) {
2057 debug() <<
"merge: id: \"" <<
name <<
"\" (" << vh->
at( i ).obj <<
") adding index " << i <<
endmsg;
2058 l->Add( vh->
at( i ).obj );
2061 TH1* t0 =
dynamic_cast<TH1*
>( vh->
at( 0 ).obj );
2063 error() <<
"merge: could not dcast " <<
name <<
"(" << t0 <<
") index " << 0 <<
" to TH1" <<
endmsg;
2067 Long64_t
n = t0->Merge(
l );
2069 debug() <<
"merge: id: \"" <<
name <<
"\" merged " <<
n <<
" entries" <<
endmsg;
2071 for (
size_t i = 1; i < vh->
size(); ++i ) {
2072 TH1* th =
dynamic_cast<TH1*
>( vh->
at( i ).obj );
2074 debug() <<
"clearing index " << i <<
"(" << th <<
")" <<
endmsg;
2075 th->SetDirectory(
nullptr );
2078 error() <<
"merge: could not dcast " <<
name <<
" index " << i <<
" to TH1" <<
endmsg;