78 for (
auto filename : rootfn) {
79 if (!
fRawChain->AddFile(filename.c_str())) {
80 throw std::runtime_error(
"file invalid: " + filename);
83 std::cout <<
"Added file " + filename +
" to chain" << std::endl;
88 TObjArray *branchlist =
fRawChain->GetListOfBranches();
90 std::cout <<
"Got list of branches, size: " <<
fRawChain->GetNbranches() << std::endl;
94 for (
const auto &branch : *branchlist) {
95 std::string brname = branch->GetName();
96 fBranchMap[brname] = std::malloc(8 *
sizeof(Char_t));
116 std::cout <<
"[" << brname <<
"] ";
120 std::cout << std::endl;
124 std::ifstream t(inifn);
125 fINI.assign((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
131 throw std::runtime_error(
"Can't load " + inifn);
135 std::stringstream
ss;
139 if (
ss.str().empty()) {
140 throw std::runtime_error(
"Couldn't find any detector groups");
142 std::cout <<
"Active groups: " <<
ss.str() << std::endl;
147 while (
ss >> group) {
154 throw std::runtime_error(
"Experiment Definition expects " + std::to_string(
sizeof...(ADefns)) +
" groups.");
160 std::cout <<
"Experiment defined successfully." << std::endl;
235 Int_t compression, ULong64_t splitmb, Bool_t overwrite)
241 fOutFile =
new TFile(outfn.c_str(),
"RECREATE");
243 fOutFile =
new TFile(outfn.c_str(),
"NEW");
248 std::cout <<
"Outfile already exists, overwrite y/n? ";
250 if (std::fgets(overwrite,
sizeof overwrite, stdin) == NULL || overwrite[0] ==
'\n') {
252 }
else if (overwrite[1] ==
'\n') {
253 if (overwrite[0] ==
'y') {
254 fOutFile =
new TFile(outfn.c_str(),
"RECREATE");
256 }
else if (overwrite[0] ==
'n') {
257 std::cout <<
"Outfile invalid, quitting" << std::endl;
265 fOutFile->SetCompressionSettings(compression);
271 TNamed defn(
"TreeDefn",
fINI.c_str());
276 fOutTree =
new TTree(
"EventTree", outfn.c_str());
277 fOutTree->SetMaxTreeSize(splitmb * 1000000LL);
278 EventType::Class()->IgnoreTObjectStreamer();
279 EventType *ptrEvent =
new EventType();
290 auto nRawEntries =
static_cast<ULong64_t
>(
fRawChain->GetEntries());
291 if (nevents && nevents < nRawEntries) {
292 nRawEntries = nevents;
295 auto timestart = std::chrono::system_clock::now();
297 for (ULong64_t ixEventNum : ROOT::TSeqUL(nRawEntries)) {
300 ULong64_t ixLocalNum =
fRawChain->LoadTree(ixEventNum);
304 if (!quiet && ixEventNum % 10000 == 0) {
305 auto now = std::chrono::system_clock::now();
306 std::chrono::duration<double> sec = now - timestart;
307 auto speed = ixEventNum / sec.count();
308 auto remain =
static_cast<ULong64_t
>((nRawEntries - ixEventNum) / speed);
309 auto hours = remain / 3600;
310 auto minutes = remain / 60 % 60;
311 auto seconds = remain % 60;
312 Float_t percent = 100.0f * ixEventNum / nRawEntries;
313 printf(
"\rConverted Events: %lld/%lld [%.1f%%] Time Remaining: "
314 "%02llu:%02llu:%02llu [%.0f k/s]",
315 ixEventNum, nRawEntries, percent, hours, minutes, seconds, speed / 1000);
321 fRawChain->GetTree()->GetEntry(ixLocalNum);
326 ptrEvent->SetEventNum(ixEventNum + eventoffset);
336 std::cout << std::endl;
337 fOutFile->Write(
"", TObject::kOverwrite);
339 fOutTree->GetCurrentFile()->Write(
"", TObject::kOverwrite);