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() > 0) {
52 ROOT::EnableImplicitMT(fOptions->GetMaxWorkers());
55 auto* chain =
new TChain(treeName.c_str());
61 for(
const auto& fileName : fOptions->RootInputFiles()) {
62 if(chain->Add(fileName.c_str(), 0) >= 1) {
63 TFile* file = TFile::Open(fileName.c_str());
66 TRunInfo::ReadInfoFromFile(file);
68 TRunInfo::AddCurrent();
70 auto* ppg = static_cast<TPPG*>(file->Get(
"PPG"));
74 TChannel::ReadCalFromFile(file);
77 std::cout <<
"Failed to open '" << fileName <<
"'" << std::endl;
81 std::cout <<
"Looped over " << chain->GetNtrees() <<
"/" << fOptions->RootInputFiles().size() <<
" files and got:" << std::endl;
85 fTotalEntries = chain->GetEntries();
87 fDataFrame =
new ROOT::RDataFrame(*chain);
90 auto* inputList =
new TList;
96 for(
const auto& valFile : fOptions->ValInputFiles()) {
97 inputList->Add(new TNamed(Form(
"valFile%d", index++), valFile.c_str()));
100 for(
const auto& calFile : fOptions->CalInputFiles()) {
101 inputList->Add(new TNamed(Form(
"calFile%d", index++), calFile.c_str()));
104 for(
const auto& cutFile : fOptions->InputCutFiles()) {
105 inputList->Add(new TNamed(Form(
"cutFile%d", index++), cutFile.c_str()));
112 fOutputPrefix = helper->
Prefix();
115 fOutput = helper->Book(fDataFrame);
125 std::cout <<
"Writing to " << outputFileName << std::endl;
127 TFile outputFile(outputFileName.c_str(),
"recreate");
130 const auto* outFile = redirect->
OutFile();
131 const auto* errFile = redirect->
ErrFile();
138#if ROOT_VERSION_CODE < ROOT_VERSION(6, 30, 0)
139 std::string progressBar;
140 const auto barWidth = 100;
147 entries.OnPartialResultSlot(everyN, [&everyN, &
fTotalEntries =
fTotalEntries, &progressBar, &barMutex](
unsigned int , ULong64_t& ) {
148 std::lock_guard<std::mutex> lock(barMutex);
149 static int counter = 1;
150 progressBar.push_back(
'#');
152 std::cout <<
"\r[" << std::left << std::setw(barWidth) << progressBar <<
' ' << std::setw(3) << (counter * everyN * 100) /
fTotalEntries <<
" %]" << std::flush;
157 ROOT::RDF::Experimental::AddProgressBar(*
fDataFrame);
166 if(gDirectory->GetDirectory(list.first.c_str()) && gDirectory->cd(list.first.c_str())) {
170 gDirectory->mkdir(list.first.c_str());
171 if(gDirectory->cd(list.first.c_str())) {
174 std::cout <<
"Error, failed to find or create path " << list.first <<
", writing into " << gDirectory->GetPath() << std::endl;
178 while(gDirectory->GetDirectory(
"..")) { gDirectory->cd(
".."); }
180#if ROOT_VERSION_CODE < ROOT_VERSION(6, 30, 0)
181 std::cout <<
"\r[" << std::left << std::setw(barWidth) << progressBar <<
' ' <<
"100 %]" << std::flush;
184 std::cout <<
DRED <<
"Exception in " << __PRETTY_FUNCTION__ <<
": " << e.
detail() <<
RESET_COLOR << std::endl;
188 std::cout <<
"Error, output list is nullptr!" << std::endl;
192 redirect =
new TRedirect(outFile, errFile,
true);
195 if(
fPpg !=
nullptr) {
198 std::cerr <<
"failed to find TPPG, can't write it!" << std::endl;
204 std::cout <<
"Closed '" << outputFile.GetName() <<
"'" << std::endl;