22#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 0)
25#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 36, 0)
26 fVerbosity = new ROOT::RLogScopedVerbosity(ROOT::Detail::RDF::RDFLogChannel(), ROOT::ELogLevel::kInfo);
28 fVerbosity = new ROOT::Experimental::RLogScopedVerbosity(ROOT::Detail::RDF::RDFLogChannel(), ROOT::Experimental::ELogLevel::kInfo);
35 if(treeName.empty()) {
36 TFile check(fOptions->RootInputFiles()[0].c_str());
37 if(check.Get(
"AnalysisTree") != nullptr) {
38 treeName =
"AnalysisTree";
39 }
else if(check.Get(
"FragmentTree") !=
nullptr) {
40 treeName =
"FragmentTree";
44 if(treeName.empty()) {
45 std::ostringstream str;
46 str <<
"Failed to find 'AnalysisTree' or 'FragmentTree' in '" << fOptions->RootInputFiles()[0] <<
"', either provide a different tree name via --tree-name flag or check input file" << std::endl;
47 throw std::runtime_error(str.str());
51 if(fOptions->GetMaxWorkers() == 1) {
52 ROOT::DisableImplicitMT();
55 ROOT::EnableImplicitMT(fOptions->GetMaxWorkers());
58 auto* chain =
new TChain(treeName.c_str());
64 for(
const auto& fileName : fOptions->RootInputFiles()) {
65 if(chain->Add(fileName.c_str(), 0) >= 1) {
66 TFile* file = TFile::Open(fileName.c_str());
69 TRunInfo::ReadInfoFromFile(file);
71 TRunInfo::AddCurrent();
73 auto* ppg = static_cast<TPPG*>(file->Get(
"PPG"));
77 TChannel::ReadCalFromFile(file);
80 std::cout <<
"Failed to open '" << fileName <<
"'" << std::endl;
84 std::cout <<
"Looped over " << chain->GetNtrees() <<
"/" << fOptions->RootInputFiles().size() <<
" files and got:" << std::endl;
88 fTotalEntries = chain->GetEntries();
90 fDataFrame =
new ROOT::RDataFrame(*chain);
93 auto* inputList =
new TList;
99 for(
const auto& valFile : fOptions->ValInputFiles()) {
100 inputList->Add(new TNamed(Form(
"valFile%d", index++), valFile.c_str()));
103 for(
const auto& calFile : fOptions->CalInputFiles()) {
104 inputList->Add(new TNamed(Form(
"calFile%d", index++), calFile.c_str()));
107 for(
const auto& cutFile : fOptions->InputCutFiles()) {
108 inputList->Add(new TNamed(Form(
"cutFile%d", index++), cutFile.c_str()));
115 fOutputPrefix = helper->
Prefix();
118 fOutput = helper->Book(fDataFrame);
128 std::cout <<
"Writing to " << outputFileName << std::endl;
130 TFile outputFile(outputFileName.c_str(),
"recreate");
133 const auto* outFile = redirect->
OutFile();
134 const auto* errFile = redirect->
ErrFile();
141#if ROOT_VERSION_CODE < ROOT_VERSION(6, 30, 0)
142 std::string progressBar;
143 const auto barWidth = 100;
150 entries.OnPartialResultSlot(everyN, [&everyN, &
fTotalEntries =
fTotalEntries, &progressBar, &barMutex](
unsigned int , ULong64_t& ) {
151 std::lock_guard<std::mutex> lock(barMutex);
152 static int counter = 1;
153 progressBar.push_back(
'#');
155 std::cout <<
"\r[" << std::left << std::setw(barWidth) << progressBar <<
' ' << std::setw(3) << (counter * everyN * 100) /
fTotalEntries <<
" %]" << std::flush;
160 ROOT::RDF::Experimental::AddProgressBar(*
fDataFrame);
169 if(gDirectory->GetDirectory(list.first.c_str()) && gDirectory->cd(list.first.c_str())) {
173 gDirectory->mkdir(list.first.c_str());
174 if(gDirectory->cd(list.first.c_str())) {
177 std::cout <<
"Error, failed to find or create path " << list.first <<
", writing into " << gDirectory->GetPath() << std::endl;
181 while(gDirectory->GetDirectory(
"..")) { gDirectory->cd(
".."); }
183#if ROOT_VERSION_CODE < ROOT_VERSION(6, 30, 0)
184 std::cout <<
"\r[" << std::left << std::setw(barWidth) << progressBar <<
' ' <<
"100 %]" << std::flush;
187 std::cout <<
DRED <<
"Exception in " << __PRETTY_FUNCTION__ <<
": " << e.
detail() <<
RESET_COLOR << std::endl;
191 std::cout <<
"Error, output list is nullptr!" << std::endl;
195 redirect =
new TRedirect(outFile, errFile,
true);
198 if(
fPpg !=
nullptr) {
201 std::cerr <<
"failed to find TPPG, can't write it!" << std::endl;
207 std::cout <<
"Closed '" << outputFile.GetName() <<
"'" << std::endl;