GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
Sorter.hh
Go to the documentation of this file.
1#ifndef GAMRSORT_SORTER_HH
2#define GAMRSORT_SORTER_HH
3
4/* STD */
5#include <atomic>
6#include <map>
7#include <memory>
8#include <mutex>
9#include <stdexcept>
10#include <string>
11#include <thread>
12#include <vector>
13
14/* ROOT */
15#include <TChain.h>
16#include <TFile.h>
17#include <TH1.h>
18#include <TH2.h>
19#include <TH3.h>
20#include <TObject.h>
21
22#include <ROOT/TThreadedObject.hxx>
23#include <ROOT/TTreeProcessorMT.hxx>
24
25namespace GamR {
26namespace Sort {
27
28class Sorter {
29private:
30 std::vector<std::string> fInFilename;
31 TFile *fOutFile;
32 TChain fChain;
33 ROOT::TTreeProcessorMT *fProcessor;
34 // std::unique_ptr<ROOT::TTreeProcessorMT> fProcessor;
35 std::map<std::string, ROOT::TThreadedObject<TH1D>> fSafeSpecs;
36 std::map<std::string, ROOT::TThreadedObject<TH2D>> fSafeMats;
37 std::map<std::string, ROOT::TThreadedObject<TH3D>> fSafeCubes;
38 std::chrono::system_clock::time_point fTimeStart;
39 std::atomic<size_t> fCounter;
40 std::atomic<size_t> fTotalEvents;
41 std::atomic<Bool_t> fStatus;
42 std::mutex fMutex;
43 ULong64_t fXbins;
44 Long64_t fXlow;
45 Long64_t fXhigh;
46 ULong64_t fYbins;
47 Long64_t fYlow;
48 Long64_t fYhigh;
49 ULong64_t fZbins;
50 Long64_t fZlow;
51 Long64_t fZhigh;
52
53private:
54 void Begin();
55 void End();
56
57public:
58 Sorter(std::vector<std::string> fns, std::string out, Int_t compression = 101);
59 ~Sorter();
60
61 Bool_t Done();
62 void Tick();
63
64 void SetXsize(ULong64_t bins, Long64_t low, Long64_t high);
65 void SetYsize(ULong64_t bins, Long64_t low, Long64_t high);
66 void SetZsize(ULong64_t bins, Long64_t low, Long64_t high);
67
68 std::shared_ptr<TH1D> GetSpectrum(std::string s);
69 std::shared_ptr<TH2D> GetMatrix(std::string s);
70 std::shared_ptr<TH3D> GetCube(std::string s);
71
72 template <class Sort>
73 void Process(std::vector<std::string> args)
74 {
75 Begin();
76 auto sort = Sort(this, args);
77 fProcessor->Process(sort);
78 End();
79 }
80
81 template <class Sort>
82 void Process(Sort &sort)
83 {
84 Begin();
85 fProcessor->Process(sort);
86 End();
87 }
88
89 void PrintStatus();
90 void Halt();
91 void Write(std::string folder = "/");
92 void WriteObject(TObject *obj, const char *folder = "/", const char *rename = "", bool quiet = kFALSE);
93 void Clear();
94};
95} // namespace Sort
96} // namespace GamR
97#endif
void SetZsize(ULong64_t bins, Long64_t low, Long64_t high)
Definition Sorter.cc:156
void PrintStatus()
Definition Sorter.cc:52
void WriteObject(TObject *obj, const char *folder="/", const char *rename="", bool quiet=kFALSE)
Definition Sorter.cc:123
std::shared_ptr< TH3D > GetCube(std::string s)
Definition Sorter.cc:183
void SetXsize(ULong64_t bins, Long64_t low, Long64_t high)
Definition Sorter.cc:142
Sorter(std::vector< std::string > fns, std::string out, Int_t compression=101)
Definition Sorter.cc:9
void Write(std::string folder="/")
Definition Sorter.cc:93
void Process(std::vector< std::string > args)
Definition Sorter.hh:73
Bool_t Done()
Definition Sorter.cc:89
void Process(Sort &sort)
Definition Sorter.hh:82
std::shared_ptr< TH2D > GetMatrix(std::string s)
Definition Sorter.cc:173
std::shared_ptr< TH1D > GetSpectrum(std::string s)
Definition Sorter.cc:163
void SetYsize(ULong64_t bins, Long64_t low, Long64_t high)
Definition Sorter.cc:149
Definition Gain.cc:19