9Sorter::Sorter(std::vector<std::string> fns, std::string out, Int_t compression)
10 : fInFilename(fns), fChain(
"EventTree"), fCounter(0), fTotalEvents(0), fStatus(kFALSE), fXbins(4096), fXlow(0),
11 fXhigh(4096), fYbins(4096), fYlow(0), fYhigh(4096), fZbins(512), fZlow(0), fZhigh(512)
13 ROOT::EnableImplicitMT(std::thread::hardware_concurrency());
15 for (
const auto &fn : fInFilename) {
16 fChain.Add(fn.c_str());
18 fTotalEvents = fChain.GetEntries();
21 fProcessor =
new ROOT::TTreeProcessorMT(fChain);
23 fOutFile =
new TFile(out.c_str(),
"UPDATE");
24 if (fOutFile->IsZombie() || !fOutFile->IsOpen())
25 throw std::runtime_error(
"Error opening output file: " + out);
26 fOutFile->SetCompressionSettings(compression);
54 if (fMutex.try_lock()) {
55 auto now = std::chrono::system_clock::now();
56 std::cout <<
"\rProcessed Events: ";
57 std::cout << fCounter <<
" / " << fTotalEvents;
59 std::cout << std::fixed;
60 std::cout << std::setprecision(0);
61 std::cout << std::noshowpoint;
62 std::cout <<
" [" << 100.0 * fCounter / fTotalEvents <<
"%] ";
64 std::chrono::duration<double> sec = now - fTimeStart;
65 auto speed = fCounter / sec.count();
66 auto remain =
static_cast<ULong64_t
>((fTotalEvents - fCounter) / speed);
67 std::cout <<
"Time Remaining: ";
68 std::cout << remain / 3600 <<
":";
69 std::cout << std::setw(2) << std::setfill(
'0') << remain / 60 % 60 <<
":";
70 std::cout << std::setw(2) << std::setfill(
'0') << remain % 60;
71 std::cout <<
" [" << speed / 1000 <<
" k/s]";
72 std::cout << std::flush;
95 std::cout << std::endl <<
"Spectra" << std::endl;
96 for (
auto &h : fSafeSpecs) {
97 fOutFile->cd(folder.c_str());
98 auto m = h.second.Merge();
99 m->Write(
"", TObject::kWriteDelete);
100 std::cout <<
"\nWritten\t" << m->GetName();
101 std::cout <<
"\t=>\t" << fOutFile->GetName() << std::endl;
104 std::cout << std::endl <<
"Matrices" << std::endl;
105 for (
auto &h : fSafeMats) {
106 fOutFile->cd(folder.c_str());
107 auto m = h.second.Merge();
108 m->Write(
"", TObject::kWriteDelete);
109 std::cout <<
"Written\t" << m->GetName();
110 std::cout <<
"\t=>\t" << fOutFile->GetName() << std::endl;
113 std::cout << std::endl <<
"Cubes" << std::endl;
114 for (
auto &h : fSafeCubes) {
115 fOutFile->cd(folder.c_str());
116 auto m = h.second.Merge();
117 m->Write(
"", TObject::kWriteDelete);
118 std::cout <<
"Written\t" << m->GetName();
119 std::cout <<
"\t=>\t" << fOutFile->GetName() << std::endl;
175 std::shared_ptr<TH2D> h = fSafeMats[s].Get();
176 h->SetName(s.c_str());
177 h->SetTitle(s.c_str());
178 h->SetBins(fXbins, fXlow, fXhigh, fYbins, fYlow, fYhigh);
179 std::cout << std::endl <<
"Matrix\t" << s << std::endl;
185 std::shared_ptr<TH3D> h = fSafeCubes[s].Get();
186 h->SetName(s.c_str());
187 h->SetTitle(s.c_str());
188 h->SetBins(fXbins, fXlow, fXhigh, fYbins, fYlow, fYhigh, fZbins, fZlow, fZhigh);
189 std::cout << std::endl <<
"Cube\t" << s << std::endl;