4 #pragma warning(disable:2259)
9 #include "GaudiKernel/ISvcLocator.h"
10 #include "GaudiKernel/AttribStringParser.h"
11 #include "GaudiKernel/GaudiException.h"
12 #include "GaudiKernel/Property.h"
13 #include "GaudiKernel/IIncidentSvc.h"
14 #include "GaudiKernel/FileIncident.h"
15 #include "GaudiKernel/IEventProcessor.h"
16 #include "GaudiKernel/IJobOptionsSvc.h"
17 #include "GaudiKernel/IIoComponentMgr.h"
18 #include "GaudiKernel/IFileMgr.h"
19 #include "boost/algorithm/string/case_conv.hpp"
23 #include "TDirectory.h"
39 template <
typename InputIterator,
typename OutputIterator,
typename UnaryOperation,
typename UnaryPredicate>
40 OutputIterator transform_if( InputIterator first, InputIterator last,
41 OutputIterator result,
43 UnaryPredicate pred) {
44 while (first != last) {
45 if (pred(*first)) *result++ = op(*first);
51 constexpr
struct select1st_t {
52 template <
typename T,
typename S>
53 const T& operator()(
const std::pair<T,S>& p)
const {
return p.first; }
67 declareProperty (
"PrintAll",
m_print=
false);
69 "maximum file size in MB. if exceeded, will cause an abort. -1 to never check.");
83 auto jos = serviceLocator()->service<
IJobOptionsSvc>(
"JobOptionsSvc", true );
89 [](
const Property* p) {
return p->
name() ==
"OutputLevel"; } );
112 <<
"Caught: " << err <<
endmsg;
120 <<
"Caught: " << err <<
endmsg;
126 static TROOT
root(
"root",
"ROOT I/O");
134 if (service(
"IncidentSvc",
p_incSvc,
true).isFailure()) {
141 if (service(
"FileMgr",
p_fileMgr,
true).isFailure()) {
151 using namespace std::placeholders;
155 <<
"unable to register ROOT file open action with FileMgr"
161 <<
"unable to register ROOT file open Error action with FileMgr"
181 if (service(
"IoComponentMgr", iomgr,
true).isFailure()) {
188 <<
"could not register with the I/O component manager !"
192 bool all_good =
true;
194 for (
const auto& reg :
m_files ) {
195 const std::string& fname = reg.second.first->GetName();
202 << fname <<
"] with the I/O component manager..." <<
endmsg;
211 <<
"problem while registering input/output files with "
212 <<
"the I/O component manager !" <<
endmsg;
250 for (
const auto& uid :
m_uids ) {
252 TObject* to = uid.second.obj;
255 if (to && to->IsA()->InheritsFrom(
"TTree")) {
256 TTree* tr =
dynamic_cast<TTree*
>(to);
257 if (tr->GetDirectory() != 0) {
258 dirname = tr->GetDirectory()->GetPath();
260 }
else if (to && to->IsA()->InheritsFrom(
"TGraph")) {
261 if (!uid.second.temp) {
262 dirname = uid.second.file->GetPath();
263 string id2(uid.second.id);
264 id2.erase(0,id2.find(
"/",1));
265 id2.erase(id2.rfind(
"/"), id2.length());
266 if (id2.find(
"/") == 0) {
273 }
else if (to && to->IsA()->InheritsFrom(
"TH1")) {
274 TH1* th =
dynamic_cast<TH1*
>(to);
278 if (th->GetDirectory() != 0) {
279 dirname = th->GetDirectory()->GetPath();
288 << uid.second.temp <<
" dir: " << dirname
302 vector<TFile*> deleted_files;
305 if (find(deleted_files.begin(), deleted_files.end(), itr.second.first) ==
306 deleted_files.end()) {
307 deleted_files.push_back(itr.second.first);
312 << itr.second.first->GetName()
327 m_log <<
"==> File: " << itr.second.first->GetName()
328 <<
" stream: " << itr.first <<
endmsg;
330 itr.second.first->Print(
"base");
333 string tmpfn=itr.second.first->GetName();
338 if (service(
"IncidentSvc",pi).isFailure()) {
343 if (itr.second.second==
SHARE) {
357 TFile *outputfile = (TFile*) vf;
373 TFile *inputfile = (TFile*) vf;
375 outputfile->SetCompressionLevel( inputfile->GetCompressionLevel() );
389 delete itr.second.first;
408 std::cerr <<
"TDirectory == 0" << std::endl;
417 cout <<
"-> " << dir->GetPath() <<
" "
418 << dir->GetListOfKeys()->GetSize() << endl;
421 TIter nextkey(dir->GetList());
422 while (TKey *key = (TKey*)nextkey()) {
424 TObject *obj = key->ReadObj();
425 if (!obj) { cout << key->GetName() <<
" obj==0"<< endl;
continue; }
427 cout <<
" Key: " << key->GetName() <<
" "
428 <<
" tit: " << obj->GetTitle() <<
" "
429 <<
" (" << key->GetClassName() <<
")" << endl;
433 nextkey = dir->GetListOfKeys();
434 while (TKey *key = (TKey*)nextkey()) {
436 TObject *obj = key->ReadObj();
437 if (!obj) { cout << key->GetName() <<
" obj==0"<< endl;
continue; }
438 if (obj->IsA()->InheritsFrom(
"TDirectory")) {
439 TDirectory *tt =
dynamic_cast<TDirectory*
>(obj);
454 gErrorIgnoreLevel = kBreak;
457 m_log <<
MSG::ERROR <<
"getTHists: No such TDirectory \"" << td->GetPath()
463 m_log <<
MSG::DEBUG <<
"getTHists: \"" << td->GetPath() <<
"\": found "
464 << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
466 TIter nextkey(td->GetListOfKeys());
467 while (TKey *key = (TKey*)nextkey()) {
470 TObject *obj = key->ReadObj();
471 if (obj != 0 && obj->IsA()->InheritsFrom(
"TDirectory")) {
473 m_log <<
" (" << obj->IsA()->GetName() <<
")";
474 }
else if (obj != 0 && obj->IsA()->InheritsFrom(
"TH1")) {
476 m_log <<
" (" << obj->IsA()->GetName() <<
")";
478 }
else if (obj != 0) {
480 m_log <<
" [" << obj->IsA()->GetName() <<
"]";
488 nextkey = td->GetListOfKeys();
489 while (TKey *key = (TKey*)nextkey()) {
490 TObject *obj = key->ReadObj();
491 if (obj && obj->IsA()->InheritsFrom(
"TDirectory")) {
492 TDirectory *tt =
dynamic_cast<TDirectory*
>(obj);
510 gErrorIgnoreLevel = kBreak;
514 std::string stream,rem,r2;
517 auto itr =
m_files.find(stream);
519 r2 = itr->second.first->GetName();
525 <<
"\" looks like a stream name." <<
" associated TFile: \""
526 << itr->second.first->GetName() <<
"\"" <<
endmsg;
528 if (gDirectory->cd(r2.c_str())) {
541 m_log <<
MSG::DEBUG <<
"getTHists: stream \"" << stream <<
"\" not found"
545 if (!gDirectory->cd(dir.c_str())) {
546 m_log <<
MSG::ERROR <<
"getTHists: No such TDirectory/stream \"" << dir
562 gErrorIgnoreLevel = kBreak;
566 << td->GetPath() <<
"\"" <<
endmsg;
571 m_log <<
MSG::DEBUG <<
"getTHists: \"" << td->GetPath() <<
"\": found "
572 << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
574 TIter nextkey(td->GetListOfKeys());
575 while (TKey *key = (TKey*)nextkey()) {
578 TObject *obj = key->ReadObj();
579 if (obj != 0 && obj->IsA()->InheritsFrom(
"TDirectory")) {
581 m_log <<
" (" << obj->IsA()->GetName() <<
")";
582 }
else if (obj != 0 && obj->IsA()->InheritsFrom(
"TTree")) {
584 m_log <<
" (" << obj->IsA()->GetName() <<
")";
586 }
else if (obj != 0) {
588 m_log <<
" [" << obj->IsA()->GetName() <<
"]";
595 nextkey = td->GetListOfKeys();
596 while (TKey *key = (TKey*)nextkey()) {
597 TObject *obj = key->ReadObj();
598 if (obj && obj->IsA()->InheritsFrom(
"TDirectory")) {
599 TDirectory *tt =
dynamic_cast<TDirectory*
>(obj);
615 gErrorIgnoreLevel = kBreak;
619 std::string stream,rem,r2;
622 auto itr =
m_files.find(stream);
624 r2 = itr->second.first->GetName();
630 <<
"\" looks like a stream name." <<
" associated TFile: \""
631 << itr->second.first->GetName() <<
"\"" <<
endmsg;
633 if (gDirectory->cd(r2.c_str())) {
641 m_log <<
MSG::DEBUG <<
"getTTrees: stream \"" << stream <<
"\" not found"
645 if (!gDirectory->cd(dir.c_str())) {
646 m_log <<
MSG::ERROR <<
"getTTrees: No such TDirectory/stream \"" << dir
663 gErrorIgnoreLevel = kBreak;
666 m_log <<
MSG::ERROR <<
"getTHists: No such TDirectory \"" << td->GetPath()
672 m_log <<
MSG::DEBUG <<
"getTHists: \"" << td->GetPath() <<
"\": found "
673 << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
675 TIter nextkey(td->GetListOfKeys());
676 while (TKey *key = (TKey*)nextkey()) {
679 TObject *obj = key->ReadObj();
680 if (obj && obj->IsA()->InheritsFrom(
"TDirectory")) {
682 m_log <<
" (" << obj->IsA()->GetName() <<
")";
683 }
else if (obj && obj->IsA()->InheritsFrom(
"TH1")) {
685 m_log <<
" (" << obj->IsA()->GetName() <<
")";
688 string dir = td->GetPath();
689 string fil = td->GetFile()->GetName();
690 dir.erase(0,fil.length()+1);
693 id =
id +
"/" + key->GetName();
695 id =
id + dir +
"/" + key->GetName();
699 m_log <<
" reg as \"" <<
id <<
"\"";
703 m_log <<
" already registered";
708 m_log <<
" [" << obj->IsA()->GetName() <<
"]";
716 nextkey = td->GetListOfKeys();
717 while (TKey *key = (TKey*)nextkey()) {
718 TObject *obj = key->ReadObj();
719 if (obj && obj->IsA()->InheritsFrom(
"TDirectory")) {
720 TDirectory *tt =
dynamic_cast<TDirectory*
>(obj);
737 gErrorIgnoreLevel = kBreak;
741 std::string stream,rem,r2;
744 auto itr =
m_files.find(stream);
746 r2 = itr->second.first->GetName();
752 <<
"\" looks like a stream name." <<
" associated TFile: \""
753 << itr->second.first->GetName() <<
"\"" <<
endmsg;
755 if (gDirectory->cd(r2.c_str())) {
767 m_log <<
MSG::DEBUG <<
"getTHists: stream \"" << stream <<
"\" not found"
771 if (!gDirectory->cd(dir.c_str())) {
772 m_log <<
MSG::ERROR <<
"getTHists: No such TDirectory/stream \"" << dir
778 <<
"without a valid stream name" <<
endmsg;
794 gErrorIgnoreLevel = kBreak;
798 << td->GetPath() <<
"\"" <<
endmsg;
803 m_log <<
MSG::DEBUG <<
"getTHists: \"" << td->GetPath() <<
"\": found "
804 << td->GetListOfKeys()->GetSize() <<
" keys" <<
endmsg;
806 TIter nextkey(td->GetListOfKeys());
807 while (TKey *key = (TKey*)nextkey()) {
810 TObject *obj = key->ReadObj();
811 if (obj && obj->IsA()->InheritsFrom(
"TDirectory")) {
813 m_log <<
" (" << obj->IsA()->GetName() <<
")";
814 }
else if (obj && obj->IsA()->InheritsFrom(
"TTree")) {
816 m_log <<
" (" << obj->IsA()->GetName() <<
")";
819 string dir = td->GetPath();
820 string fil = td->GetFile()->GetName();
821 dir.erase(0,fil.length()+1);
824 id =
id +
"/" + key->GetName();
826 id =
id + dir +
"/" + key->GetName();
830 m_log <<
" reg as \"" <<
id <<
"\"";
834 m_log <<
" already registered";
837 }
else if (obj != 0) {
839 m_log <<
" [" << obj->IsA()->GetName() <<
"]";
847 nextkey = td->GetListOfKeys();
848 while (TKey *key = (TKey*)nextkey()) {
849 TObject *obj = key->ReadObj();
850 if (obj && obj->IsA()->InheritsFrom(
"TDirectory")) {
851 TDirectory *tt =
dynamic_cast<TDirectory*
>(obj);
868 gErrorIgnoreLevel = kBreak;
872 std::string stream,rem,r2;
875 auto itr =
m_files.find(stream);
877 r2 = itr->second.first->GetName();
883 <<
"\" looks like a stream name." <<
" associated TFile: \""
884 << itr->second.first->GetName() <<
"\"" <<
endmsg;
886 if (gDirectory->cd(r2.c_str())) {
896 m_log <<
MSG::DEBUG <<
"getTTrees: stream \"" << stream <<
"\" not found"
900 if (!gDirectory->cd(dir.c_str())) {
901 m_log <<
MSG::ERROR <<
"getTTrees: No such TDirectory/stream \"" << dir
920 if (itr2 ==
m_uids.end()) {
923 <<
"\" with id \"" << hid.
id <<
"\"" <<
endmsg;
927 std::string id,
root,rem;
930 auto mitr =
m_ids.equal_range(rem);
931 auto itr3 = std::find_if( mitr.first, mitr.second, [&](idMap::const_reference
i)
932 { return i.second.obj == obj; } ) ;
933 if (itr3 != mitr.second ) {
936 <<
"\" with id \"" << hid.
id <<
"\"" <<
endmsg;
947 m_log <<
MSG::ERROR <<
"Cannot unregister TObject \"" << obj->GetName()
948 <<
"\": not known to THistSvc" <<
endmsg;
960 auto itr =
m_uids.find(
id);
961 if (itr ==
m_uids.end()) {
967 TObject* obj = itr->second.obj;
1005 TTree *hist =
nullptr;
1025 TGraph *hist =
nullptr;
1033 if ( strcmp(hist->GetName(),
"Graph") == 0 ) {
1035 std::string id2(
id);
1036 string::size_type
i = id2.rfind(
"/");
1037 if (i != string::npos) {
1041 m_log <<
MSG::INFO <<
"setting name of TGraph id: \"" <<
id <<
"\" to \""
1042 << id2 <<
"\" since it is unset" <<
endmsg;
1043 hist->SetName(id2.c_str());
1072 std::vector<std::string>
1075 std::vector<std::string> names;
1076 names.reserve(
m_uids.size());
1079 [](uidMap::const_reference
i) {
1080 return i.second.obj->IsA()->InheritsFrom(
"TH11"); }
1094 std::vector<std::string>
1097 std::vector<std::string> names;
1098 names.reserve(
m_uids.size());
1100 std::back_inserter(names),
1102 [](uidMap::const_reference
i) {
1103 return i.second.obj->IsA()->InheritsFrom(
"TTree"); }
1117 std::vector<std::string>
1120 std::vector<std::string> names;
1121 names.reserve(
m_uids.size());
1124 [](uidMap::const_reference
i) {
1125 return i.second.obj->IsA()->InheritsFrom(
"TTree"); }
1162 TFile*&
file)
const {
1164 auto pos =
id.find(
"/");
1166 if (pos == string::npos) {
1169 }
else if (pos != 0) {
1174 auto pos2 =
id.find(
"/",pos+1);
1176 if (pos2 == string::npos) {
1186 if (stream ==
"temp") {
1191 auto itr =
m_files.find(stream);
1192 file = (itr !=
m_files.end() ? itr->second.first : nullptr );
1195 <<
"\" associated with id: \"" <<
id <<
"\""
1206 auto pos =
id.find(
"/");
1208 if (pos == string::npos) {
1211 }
else if (pos == 0) {
1214 root =
id.substr(0,pos);
1215 rem =
id.substr(pos+1);
1227 <<
"Set it via the \"CL=\" parameter in the \"Output\" Property"
1241 m_log <<
MSG::DEBUG <<
"Delaying connection of Input Files until Initialize"
1242 <<
". now in " << FSMState()
1278 m_log <<
MSG::DEBUG <<
"Delaying connection of Input Files until Initialize"
1279 <<
". now in " << FSMState()
1316 for (
auto uitr=
m_uids.begin(); uitr !=
m_uids.end(); ++uitr) {
1320 << uitr->second.id <<
" " << uitr->second.mode <<
endmsg;
1322 TObject* to = uitr->second.obj;
1323 TFile* oldFile = uitr->second.file;
1326 }
else if ( uitr->second.temp || uitr->second.mode ==
READ ) {
1334 }
else if (to->IsA()->InheritsFrom(
"TTree")) {
1335 TTree* tr =
dynamic_cast<TTree*
>(to);
1336 TFile* newFile = tr->GetCurrentFile();
1338 if (oldFile != newFile) {
1339 std::string newFileName = newFile->GetName();
1340 std::string oldFileName, streamName, rem;
1341 TFile* dummy =
nullptr;
1342 findStream(uitr->second.id, streamName, rem, dummy);
1345 if (itr.second.first == oldFile) itr.second.first = newFile;
1348 for (
auto uitr2 = uitr; uitr2 !=
m_uids.end(); ++uitr2) {
1349 if (uitr2->second.file == oldFile) {
1350 uitr2->second.file = newFile;
1355 [&](streamMap::const_reference
s) {
1356 return s.second == streamName;
1363 <<
" stream: " << streamName
1364 <<
" oldFile: " << oldFileName
1365 <<
" newFile: " << newFileName
1370 if (!oldFileName.empty()) {
1377 <<
"\" to \"" << newFileName <<
"\" for stream \""
1378 <<
i->second <<
"\"" <<
endmsg;
1380 std::string
nm = std::move(
i->second);
1388 <<
"Problems updating fileStreams with new file name" <<
endmsg;
1403 std::for_each(
m_files.begin(),
m_files.end(), [](std::pair<const std::string,std::pair<TFile*,Mode>>&
i) {
1404 auto mode =
i.second.second;
1405 auto file =
i.second.first;
1407 file->Write(
"",TObject::kOverwrite);
1408 }
else if ( mode ==
APPEND ) {
1414 m_log <<
MSG::DEBUG <<
"THistSvc::write()::List of Files connected in ROOT "
1416 TSeqCollection *filelist=gROOT->GetListOfFiles();
1417 for (
int ii=0; ii<filelist->GetEntries(); ii++) {
1419 <<
"THistSvc::write()::List of Files connected in ROOT: \""
1420 << filelist->At(ii)->GetName()<<
"\""<<
endmsg;
1433 auto loc = ident.find(
" ");
1434 string stream = ident.substr(0,loc);
1436 typedef std::pair<std::string,std::string> Prop;
1437 std::vector<Prop> props;
1441 if (loc != string::npos) {
1442 using Parser = Gaudi::Utils::AttribStringParser;
1443 for (
auto attrib: Parser(ident.substr(loc + 1))) {
1444 auto TAG = boost::algorithm::to_upper_copy(attrib.tag);
1445 auto VAL = boost::algorithm::to_upper_copy(attrib.value);
1447 if (TAG ==
"FILE" || TAG ==
"DATAFILE") {
1448 filename = attrib.value;
1450 }
else if ( TAG ==
"OPT" ) {
1451 if ( VAL ==
"APPEND" || VAL ==
"UPDATE" ) {
1453 }
else if ( VAL ==
"CREATE" || VAL ==
"NEW" || VAL ==
"WRITE" ) {
1455 }
else if ( VAL ==
"RECREATE" ) {
1457 }
else if (VAL ==
"SHARE") {
1459 }
else if ( VAL ==
"OLD" || VAL ==
"READ" ) {
1466 }
else if (TAG ==
"TYP") {
1467 db_typ = std::move(attrib.value);
1468 }
else if (TAG ==
"CL") {
1469 cl = std::stoi(attrib.value);
1471 props.emplace_back( attrib.tag, attrib.value);
1477 if (stream ==
"temp") {
1479 <<
"\": stream name \"temp\" reserved."
1484 if (db_typ !=
"ROOT") {
1486 <<
"\": technology type \"" << db_typ <<
"\" not supported."
1494 <<
"\":\n stream \"" << stream <<
"\" already connected to file: \""
1495 <<
m_files[stream].first->GetName() <<
"\""
1503 }
else if (typ ==
'N') {
1505 }
else if (typ ==
'A') {
1507 }
else if (typ ==
'R') {
1509 }
else if (typ ==
'S') {
1513 m_log <<
MSG::ERROR <<
"No OPT= specified or unknown access mode in: "
1522 const std::string& oldstream = fitr.first->second;
1524 const auto& f_info =
m_files[oldstream];
1526 if (newMode != f_info.second) {
1528 <<
"\":\n file \"" << filename <<
"\" already opened by stream: \""
1529 << oldstream <<
"\" with different access mode."
1533 TFile *f2 = f_info.first;
1534 m_files[stream] = make_pair(f2,newMode);
1537 <<
"\" to previously opened TFile: \"" << filename <<
"\""
1545 if (service(
"IncidentSvc",pi).isFailure()) {
1559 m_log <<
"Unable to open ROOT file " << filename <<
" for reading"
1578 m_log <<
"Unable to open ROOT file " << filename <<
" for writing"
1592 <<
"\" for appending" <<
endmsg;
1604 static int ishared = 0;
1610 <<
"\" and realfilename="<<realfilename <<
endmsg;
1618 m_log <<
"Unable to open ROOT file " << filename <<
" for writing"
1632 m_log <<
"Unable to open ROOT file " << filename <<
" for appending"
1641 m_files[stream] = make_pair(f,newMode);
1645 m_log <<
MSG::DEBUG <<
"Opening TFile \"" << filename <<
"\" stream: \""
1646 << stream <<
"\" mode: \"" << typ <<
"\"" <<
" comp level: " << cl
1657 string uid = hid.
id;
1659 string stream, fdir, bdir, dir, id;
1670 while ( (dir =
dirname(fdir)) !=
"") {
1671 if (! gDirectory->GetKey(dir.c_str())) {
1672 gDirectory->mkdir(dir.c_str());
1674 gDirectory->cd(dir.c_str());
1687 string::size_type
i = dir.find(
"/");
1689 if (i == string::npos)
return {};
1696 string root = dir.substr(0,i);
1708 m_ge = gErrorIgnoreLevel;
1714 gErrorIgnoreLevel = m_ge;
1722 while (
id.find(
"//") != std::string::npos) {
1723 id.replace(
id.find(
"//"),2,
"/");
1734 TString
path( (
char*)strstr(target->GetPath(),
":") );
1738 TDirectory *current_sourcedir = gDirectory;
1741 TList *lkeys=current_sourcedir->GetListOfKeys();
1742 int nkeys=lkeys->GetEntries();
1744 for (
int jj=0; jj<nkeys; jj++) {
1745 key=(TKey*) lkeys->At(jj);
1746 string pathnameinsource=current_sourcedir->GetPath()+string(
"/")+key->GetName();
1751 TObject *obj=source->Get(pathnameinsource.c_str());
1754 if (obj->IsA()->InheritsFrom(
"TDirectory") ) {
1763 TDirectory *newtargetdir =
1764 target->mkdir(obj->GetName(), obj->GetTitle() );
1768 }
else if (obj->IsA()->InheritsFrom(
"TTree")) {
1771 TTree *mytree=
dynamic_cast<TTree*
>(obj);
1772 int nentries=(int) mytree->GetEntries();
1773 mytree->SetBranchStatus(
"*",1);
1785 mytree->CloneTree();
1793 obj->Write(key->GetName() );
1824 Long64_t mfs_warn = mfs * 95 / 100;
1828 map<string, pair<TFile*,Mode> >::const_iterator itr;
1829 for (
const auto& f :
m_files) {
1830 TFile* tf = f.second.first;
1835 << tf->GetName() <<
" size: " << tf->GetSize()
1840 if (tf->GetSize() > mfs) {
1845 <<
"\" associated with stream \"" << f.first
1846 <<
"\" has exceeded the max file size of "
1851 if (service(
"ApplicationMgr", evt,
true).isSuccess()) {
1857 }
else if (tf->GetSize() > mfs_warn) {
1859 <<
"\" associated with stream \"" << f.first
1860 <<
"\" is at 95% of its maximum allowable file size of "
1876 <<
"copyFileLayout() to dst path: " << dst->GetPath () <<
endmsg;
1879 TString
path ((
char*)strstr (dst->GetPath(),
":"));
1883 TDirectory *cur_src_dir = gDirectory;
1886 TList *key_list = cur_src_dir->GetListOfKeys ();
1887 int n = key_list->GetEntries ();
1888 for (
int j = 0; j <
n; ++j ) {
1889 TKey *k = (TKey*)key_list->At (j);
1890 const std::string src_pathname = cur_src_dir->GetPath()
1893 TObject *o=src->Get (src_pathname.c_str());
1895 if ( o && o->IsA()->InheritsFrom (
"TDirectory")) {
1900 TDirectory * dst_dir = dst->mkdir (o->GetName(), o->GetTitle());
1914 bool all_good =
true;
1922 if (service(
"IoComponentMgr", iomgr,
true).isFailure()) {
1931 gErrorIgnoreLevel = kFatal;
1933 typedef std::map<std::string, std::pair<TFile*,Mode> > FileReg_t;
1935 for (
auto & ifile :
m_files ) {
1936 TFile *f = ifile.second.first;
1937 std::string fname = f->GetName();
1940 << f->GetOption() <<
"] r:"
1941 << f->GetFileBytesRead()
1942 <<
" w:" << f->GetFileBytesWritten()
1943 <<
" cnt:" << f->GetFileCounter()
1946 if ( ifile.second.second ==
READ ) {
1949 <<
" TFile opened in READ mode: not reassigning names" <<
endmsg;
1966 Option_t *
opts = f->GetOption();
1970 <<
"\" for writing" <<
endmsg;
1973 TFile *newfile = (TFile*) vf;
1974 newfile->SetOption(opts);
1979 ifile.second.first = newfile;
1984 for (
auto& uid :
m_uids ) {
1986 if ( hid.
file != f )
continue;
1987 TDirectory *olddir = this->
changeDir (hid);
1990 TDirectory *newdir = this->
changeDir (hid);
1991 TClass *cl = hid.
obj->IsA();
1995 if (cl->InheritsFrom (
"TTree")) {
1996 dynamic_cast<TTree*
> (hid.
obj)->SetDirectory (newdir);
1997 dynamic_cast<TTree*
> (hid.
obj)->Reset();
1999 else if (cl->InheritsFrom (
"TH1")) {
2000 dynamic_cast<TH1*
> (hid.
obj)->SetDirectory (newdir);
2001 dynamic_cast<TH1*
> (hid.
obj)->Reset();
2003 else if (cl->InheritsFrom (
"TGraph")) {
2004 olddir->Remove (hid.
obj);
2005 newdir->Append (hid.
obj);
2008 <<
"id: \"" << hid.
id <<
"\" is not a inheriting from a class "
2009 <<
"we know how to handle (received [" << cl->GetName()
2010 <<
"], " <<
"expected [TTree, TH1 or TGraph]) !"
2012 <<
"attaching to current dir [" << newdir->GetPath() <<
"] "
2013 <<
"nonetheless..." <<
endmsg;
2014 olddir->Remove (hid.
obj);
2015 newdir->Append (hid.
obj);
2037 if (fa->
desc() !=
"HIST") {
2069 if (fa->
desc() !=
"HIST") {
virtual StatusCode io_retrieve(IIoComponent *iocomponent, std::string &fname)=0
: retrieve the new filename for a given IIoComponent and
StatusCode initialize() override
virtual const std::vector< const Property * > * getProperties(const std::string &client) const =0
Get the properties associated to a given client.
string to_string(const T &value)
std::vector< std::string > getTrees() const override
virtual StatusCode stopRun()=0
Schedule a stop of the current event processing.
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...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
StatusCode finalize() override
IntegerProperty m_autoFlush
MSG::Level level()
Retrieve output level.
const std::string & name() const
property name
IntegerProperty m_autoSave
constexpr struct select1st_t select1st
bool isSuccess() const
Test for a status code of SUCCESS.
auto begin(reverse_wrapper< T > &w)
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
bool browseTDir(TDirectory *dir) const
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
StatusCode getGraph(const std::string &name, TGraph *&) const override
void setupCompressionLevel(Property &cmp)
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
bool isFailure() const
Test for a status code of FAILURE.
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
virtual StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &d="")=0
StringArrayProperty m_inputfile
const std::string & name() const
StringArrayProperty m_outputfile
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
void setupOutputFile(Property &outputfile)
call-back method to handle output stream property
Main interface for the JobOptions service.
const std::string & desc() const
std::string dirname(std::string &dir) const
StatusCode readTree(const std::string &name, TTree *&) const
StatusCode getTree(const std::string &name, TTree *&) const override
auto end(reverse_wrapper< T > &w)
This class is used for returning status codes from appropriate routines.
std::map< std::string, std::pair< TFile *, Mode > > m_files
#define DECLARE_COMPONENT(type)
void handle(const Incident &) override
IntegerProperty m_maxFileSize
std::vector< std::string > getHists() const override
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
~GlobalDirectoryRestore()
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
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
const TYPE & value() const
explicit conversion
IntegerProperty m_compressionLevel
StatusCode regHist(const std::string &name) override
std::map< std::string, std::string > m_sharedFiles
Property base class allowing Property* collections to be "homogeneous".
virtual unsigned long release()=0
Release Interface instance.
StatusCode reinitialize() override
StatusCode regHist_i(T *hist, const std::string &name)
Base class used to extend a class implementing other interfaces.
StatusCode readHist_i(const std::string &name, T *&hist) 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.
void setLevel(int level)
Update outputlevel.
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
bool exists(const std::string &name) const override
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
StatusCode regGraph(const std::string &name) override
THistSvc(const std::string &name, ISvcLocator *svc)
void setupInputFile(Property &inputfile)
call-back method to handle input stream property
StatusCode io_reinit() override
callback method to reinitialize the internal state of the component for I/O purposes (e...
StatusCode getHist(const std::string &name, TH1 *&) const override
The interface implemented by the IncidentSvc service.
void MergeRootFile(TDirectory *target, TDirectory *source)
void removeDoubleSlash(std::string &) const
std::vector< std::string > getGraphs() const override
virtual Io::close_t close(const Io::Fd, const std::string &caller)=0