stream  0.10.0
stream analysis framework
base/Processor.h
1 #ifndef BASE_PROCESSOR_H
2 #define BASE_PROCESSOR_H
3 
4 #include <string>
5 
6 #include "base/ProcMgr.h"
7 
8 #define DefFillH1(h1, x, w) { \
9  if (h1 && fIntHistFormat) { \
10  double* arr = (double*) h1; \
11  int nbin = (int) arr[0]; \
12  int bin = (int) (nbin * (x - arr[1]) / (arr[2] - arr[1])); \
13  if (bin<0) arr[3]+=w; else \
14  if (bin>=nbin) arr[4+nbin]+=w; else arr[4+bin]+=w; \
15  } else { \
16  if (h1) mgr()->FillH1(h1, x, w); \
17  } \
18 }
19 
20 #define DefFastFillH1(h1,x,weight) { \
21  if (h1) { \
22  if (fIntHistFormat) \
23  ((double*) h1)[4+(x)] += weight; \
24  else \
25  mgr()->FillH1(h1, (x), weight); \
26  } \
27 }
28 
29 #define DefFillH2(h2,x,y,weight) { \
30  if (h2 && fIntHistFormat) { \
31  double* arr = (double*) h2; \
32  int nbin1 = (int) arr[0]; \
33  int nbin2 = (int) arr[3]; \
34  int bin1 = (int) (nbin1 * (x - arr[1]) / (arr[2] - arr[1])); \
35  int bin2 = (int) (nbin2 * (y - arr[4]) / (arr[5] - arr[4])); \
36  if (bin1<0) bin1 = -1; else if (bin1>nbin1) bin1 = nbin1; \
37  if (bin2<0) bin2 = -1; else if (bin2>nbin2) bin2 = nbin2; \
38  arr[6 + (bin1+1) + (bin2+1)*(nbin1+2)]+=weight; \
39 } else { \
40  if (h2) mgr()->FillH2(h2, x, y, weight); \
41 } }
42 
43 #define DefFastFillH2(h2,x,y) { \
44  if (h2 && fIntHistFormat) { \
45  ((double*) h2)[6 + (x+1) + (y+1) * ((int) *((double*)h2) + 2)] += 1.; \
46  } else { \
47  if (h2) mgr()->FillH2(h2, x, y, 1.); \
48  } \
49 }
50 
51 
52 
53 namespace base {
54 
62  class Processor {
63  friend class ProcMgr;
64 
65  private:
66 
67  void SetManager(base::ProcMgr* m);
68 
69 
70  protected:
71 
72  enum { DummyBrdId = 0xffffffff };
73 
74  std::string fName;
75  unsigned fID;
77  std::string fPathPrefix;
78  std::string fPrefix;
79  std::string fSubPrefixD;
80  std::string fSubPrefixN;
82  unsigned fStoreKind;
84 
86  Processor(const char* name = "", unsigned brdid = DummyBrdId);
87 
89  void SetBoardId(unsigned id) { fID = id; }
90 
92  void SetPathPrefix(const std::string &prefix) { fPathPrefix = prefix; }
93 
95  void SetSubPrefix(const char* subname = "", int indx = -1, const char* subname2 = "", int indx2 = -1);
96 
98  void SetSubPrefix2(const char* subname = "", int indx = -1, const char* subname2 = "", int indx2 = -1);
99 
100  H1handle MakeH1(const char* name, const char* title, int nbins, double left, double right, const char* xtitle = 0);
101 
103  inline void FillH1(H1handle h1, double x, double weight = 1.)
104  { DefFillH1(h1,x,weight); }
105 
108  inline void FastFillH1(H1handle h1, int x, double weight = 1.)
109  { DefFastFillH1(h1,x, weight); }
110 
112  inline double GetH1Content(H1handle h1, int nbin)
113  {
114  return h1 ? mgr()->GetH1Content(h1, nbin) : 0.;
115  }
116 
118  inline void SetH1Content(H1handle h1, int nbin, double v = 0.)
119  {
120  if (h1) mgr()->SetH1Content(h1, nbin, v);
121  }
122 
124  inline int GetH1NBins(H1handle h1)
125  {
126  int nbins = 0;
127  bool isGood = mgr()->GetH1NBins(h1, nbins);
128  return isGood ? nbins : 0;
129  }
130 
132  inline void ClearH1(H1handle h1)
133  {
134  if (h1) mgr()->ClearH1(h1);
135  }
136 
138  inline void CopyH1(H1handle tgt, H1handle src)
139  {
140  mgr()->CopyH1(tgt, src);
141  }
142 
144  inline void SetH1Title(H1handle h1, const char *title)
145  {
146  mgr()->SetH1Title(h1, title);
147  }
148 
149  H2handle MakeH2(const char* name, const char* title, int nbins1, double left1, double right1, int nbins2, double left2, double right2, const char* options = 0);
150 
152  inline void FillH2(H1handle h2, double x, double y, double weight = 1.)
153  { DefFillH2(h2,x,y,weight); }
154 
157  inline void FastFillH2(H1handle h2, int x, int y)
158  { DefFastFillH2(h2,x,y); }
159 
161  inline void SetH2Content(H2handle h2, int nbin1, int nbin2, double v = 0.)
162  {
163  if (h2) mgr()->SetH2Content(h2, nbin1, nbin2, v);
164  }
165 
167  inline double GetH2Content(H2handle h2, int bin1, int bin2)
168  {
169  return h2 ? mgr()->GetH2Content(h2, bin1, bin2) : 0.;
170  }
171 
173  inline bool GetH2NBins(H2handle h2, int &nBins1, int &nBins2)
174  {
175  bool isGood = mgr()->GetH2NBins(h2, nBins1, nBins2);
176  return isGood;
177  }
178 
180  inline void ClearH2(base::H2handle h2)
181  {
182  if (h2) mgr()->ClearH2(h2);
183  }
184 
186  inline void SetH2Title(H2handle h2, const char* title)
187  {
188  mgr()->SetH2Title(h2, title);
189  }
190 
191  C1handle MakeC1(const char* name, double left, double right, H1handle h1 = 0);
192 
193  void ChangeC1(C1handle c1, double left, double right);
194 
196  inline int TestC1(C1handle c1, double value, double* dist = 0)
197  {
198  return mgr()->TestC1(c1, value, dist);
199  }
200 
201  double GetC1Limit(C1handle c1, bool isleft = true);
202 
204  virtual void CreateBranch(TTree*) {}
205 
207  virtual bool RegisterObject(TObject* tobj, const char* subfolder = 0)
208  {
209  return mgr()->RegisterObject(tobj, subfolder);
210  }
211 
212  public:
213 
214  virtual ~Processor();
215 
217  ProcMgr* mgr() const { return fMgr; }
218 
220  const char* GetName() const { return fName.c_str(); }
222  unsigned GetID() const { return fID; }
223 
225  inline void SetHistFilling(int lvl = 99) { fHistFilling = lvl; }
227  inline bool IsHistFilling() const { return fHistFilling > 0; }
229  inline int HistFillLevel() const { return fHistFilling; }
230 
232  unsigned GetStoreKind() const { return fStoreKind; }
234  bool IsStoreEnabled() const { return GetStoreKind() != 0; }
235 
237  virtual void SetStoreKind(unsigned kind = 1) { fStoreKind = kind; }
239  void SetStoreEnabled(bool on = true) { SetStoreKind(on ? 1 : 0); }
240 
242  virtual void UserPreLoop() {}
243 
245  virtual void UserPostLoop() {}
246  };
247 
248 
249 }
250 
251 #endif
Central data and process manager.
Definition: ProcMgr.h:30
virtual double GetH2Content(H2handle h2, int bin1, int bin2)
Get content for 2D histogram.
Definition: ProcMgr.cxx:304
virtual bool GetH2NBins(H2handle h2, int &nbins1, int &nbins2)
get number of bins for 2D histogram
Definition: ProcMgr.cxx:271
virtual void ClearH2(H2handle h2)
Clear 2D histogram.
Definition: ProcMgr.cxx:338
virtual void SetH1Content(H1handle h1, int bin, double v=0.)
set histogram content
Definition: ProcMgr.cxx:198
virtual void SetH2Title(H2handle h1, const char *title)
Set histogram title.
Definition: ProcMgr.h:149
virtual void SetH1Title(H1handle h1, const char *title)
Set histogram title.
Definition: ProcMgr.h:138
virtual int TestC1(C1handle c1, double value, double *dist=nullptr)
Condition check 0 - inside, -1 left , +1 - right If variable dist specified, will contain distance to...
Definition: ProcMgr.cxx:369
virtual void CopyH1(H1handle tgt, H1handle src)
Copy 1D histogram.
Definition: ProcMgr.cxx:226
virtual double GetH1Content(H1handle h1, int bin)
get histogram context
Definition: ProcMgr.cxx:183
virtual void ClearH1(H1handle h1)
Clear 1D histogram.
Definition: ProcMgr.cxx:213
virtual void SetH2Content(H2handle h2, int bin1, int bin2, double v=0.)
Set content for 2D histogram.
Definition: ProcMgr.cxx:321
virtual bool GetH1NBins(H1handle h1, int &nbins)
get number of histogram bins
Definition: ProcMgr.cxx:157
virtual bool RegisterObject(TObject *tobj, const char *subfolder=nullptr)
method to register ROOT objects, object should be derived from TObject class if returns true,...
Definition: ProcMgr.h:174
Abstract processor.
Definition: base/Processor.h:62
double GetH1Content(H1handle h1, int nbin)
Get bin content of 1-D histogram.
Definition: base/Processor.h:112
int GetH1NBins(H1handle h1)
Get bins numbers for 1-D histogram.
Definition: base/Processor.h:124
bool fIntHistFormat
if true, internal histogram format is used
Definition: base/Processor.h:83
void FastFillH2(H1handle h2, int x, int y)
Fast fill 2-D histogram.
Definition: base/Processor.h:157
void SetSubPrefix2(const char *subname="", int indx=-1, const char *subname2="", int indx2=-1)
Set subprefix for histograms and conditions, index uses 2 symbols.
Definition: base/Processor.cxx:96
void FillH2(H1handle h2, double x, double y, double weight=1.)
Fill 2-D histogram.
Definition: base/Processor.h:152
C1handle MakeC1(const char *name, double left, double right, H1handle h1=0)
Create condition.
Definition: base/Processor.cxx:175
unsigned GetStoreKind() const
Get store kind.
Definition: base/Processor.h:232
int fHistFilling
level of histogram filling
Definition: base/Processor.h:81
ProcMgr * mgr() const
Return manager instance.
Definition: base/Processor.h:217
virtual void UserPostLoop()
post loop
Definition: base/Processor.h:245
virtual bool RegisterObject(TObject *tobj, const char *subfolder=0)
Register object.
Definition: base/Processor.h:207
H2handle MakeH2(const char *name, const char *title, int nbins1, double left1, double right1, int nbins2, double left2, double right2, const char *options=0)
Adds processor prefix to histogram name and calls base::ProcMgr::MakeH2 method.
Definition: base/Processor.cxx:154
void FastFillH1(H1handle h1, int x, double weight=1.)
Fast fill 1-D histogram.
Definition: base/Processor.h:108
bool IsHistFilling() const
Is histogram filling enabled.
Definition: base/Processor.h:227
unsigned GetID() const
Get processor ID.
Definition: base/Processor.h:222
void SetH2Content(H2handle h2, int nbin1, int nbin2, double v=0.)
Set bin content of 2-D histogram.
Definition: base/Processor.h:161
std::string fName
processor name, used for event naming
Definition: base/Processor.h:74
virtual void SetStoreKind(unsigned kind=1)
Set store kind.
Definition: base/Processor.h:237
unsigned fID
identifier, used mostly for debugging
Definition: base/Processor.h:75
void SetH2Title(H2handle h2, const char *title)
Change title of 2-D histogram.
Definition: base/Processor.h:186
void SetPathPrefix(const std::string &prefix)
Set path prefix for histogramsid.
Definition: base/Processor.h:92
bool GetH2NBins(H2handle h2, int &nBins1, int &nBins2)
Get number of bins for 2-D histogram.
Definition: base/Processor.h:173
int TestC1(C1handle c1, double value, double *dist=0)
Test condition.
Definition: base/Processor.h:196
int HistFillLevel() const
Get histogram filling level.
Definition: base/Processor.h:229
H1handle MakeH1(const char *name, const char *title, int nbins, double left, double right, const char *xtitle=0)
Adds processor prefix to histogram name and calls base::ProcMgr::MakeH1 method.
Definition: base/Processor.cxx:132
void ClearH1(H1handle h1)
Clear 1-D histogram.
Definition: base/Processor.h:132
void SetStoreEnabled(bool on=true)
Enable store - set store kind 1.
Definition: base/Processor.h:239
void SetH1Content(H1handle h1, int nbin, double v=0.)
Set bin content of 1-D histogram.
Definition: base/Processor.h:118
unsigned fStoreKind
if >0, store will be enabled for processor
Definition: base/Processor.h:82
double GetC1Limit(C1handle c1, bool isleft=true)
Get condition limit.
Definition: base/Processor.cxx:199
virtual void CreateBranch(TTree *)
Create branch.
Definition: base/Processor.h:204
std::string fSubPrefixD
sub-prefix for histogram directory
Definition: base/Processor.h:79
ProcMgr * fMgr
direct pointer on manager
Definition: base/Processor.h:76
Processor(const char *name="", unsigned brdid=DummyBrdId)
Make constructor protected - no way to create base class instance.
Definition: base/Processor.cxx:12
const char * GetName() const
Get processor name.
Definition: base/Processor.h:220
std::string fPrefix
prefix, used for histogram names
Definition: base/Processor.h:78
void SetH1Title(H1handle h1, const char *title)
Set 1-D histogram title.
Definition: base/Processor.h:144
void ChangeC1(C1handle c1, double left, double right)
Change condition limits.
Definition: base/Processor.cxx:191
void CopyH1(H1handle tgt, H1handle src)
Copy 1-D histogram from src to tgt.
Definition: base/Processor.h:138
bool IsStoreEnabled() const
Is store enabled.
Definition: base/Processor.h:234
void ClearH2(base::H2handle h2)
Clear 2-D histogram.
Definition: base/Processor.h:180
double GetH2Content(H2handle h2, int bin1, int bin2)
Get bin content of 2-D histogram.
Definition: base/Processor.h:167
void FillH1(H1handle h1, double x, double weight=1.)
Fill 1-D histogram.
Definition: base/Processor.h:103
void SetBoardId(unsigned id)
Set board id.
Definition: base/Processor.h:89
void SetSubPrefix(const char *subname="", int indx=-1, const char *subname2="", int indx2=-1)
Set subprefix for histograms and conditions.
Definition: base/Processor.cxx:60
void SetHistFilling(int lvl=99)
Set histogram filling level.
Definition: base/Processor.h:225
virtual ~Processor()
destructor
Definition: base/Processor.cxx:39
virtual void UserPreLoop()
pre loop
Definition: base/Processor.h:242
std::string fSubPrefixN
sub-prefix for histogram names
Definition: base/Processor.h:80
std::string fPathPrefix
histogram path prefix, used for histogram folder name
Definition: base/Processor.h:77