stream  0.10.0
stream analysis framework
ProcMgr.h
1 #ifndef BASE_PROGMGR_H
2 #define BASE_PROGMGR_H
3 
4 #include <vector>
5 #include <map>
6 
7 #include "base/defines.h"
8 #include "base/Buffer.h"
9 #include "base/Markers.h"
10 #include "base/Event.h"
11 
12 class TTree;
13 class TObject;
14 
15 namespace base {
16 
17  class Processor;
18  class StreamProc;
19  class EventProc;
20  class EventStore;
21 
30  class ProcMgr {
31 
32  friend class Processor;
33 
34  protected:
35 
36  enum { MaxBrdId = 256 };
37 
38  enum {
39  NoSyncIndex = 0xfffffffe,
40  DummyIndex = 0xffffffff
41  };
42 
44  typedef std::map<unsigned,StreamProc*> StreamProcMap;
45 
46  std::string fSecondName;
47  std::vector<StreamProc*> fProc;
49  std::vector<EventProc*> fEvProc;
51  unsigned fTimeMasterIndex;
52  AnalysisKind fAnalysisKind;
53  TTree *fTree{nullptr};
56  base::Event *fTrigEvent{nullptr};
57  int fDebug{0};
58 
59  static ProcMgr* fInstance;
60 
62  virtual unsigned SyncIdRange() const { return 0x1000000; }
63 
67  int SyncIdDiff(unsigned id1, unsigned id2) const;
68 
69  void DeleteAllProcessors();
70 
71  public:
72  ProcMgr();
73  virtual ~ProcMgr();
74 
75  static ProcMgr* instance();
76 
77  static void ClearInstancePointer(ProcMgr *mgr = nullptr);
78 
80 
81  static ProcMgr* AddProc(Processor* proc);
82 
84  void SetSecondName(const std::string &name = "second.C") { fSecondName = name; }
85 
88 
90  const std::string &GetSecondName() const { return fSecondName; }
91 
93  bool RegisterProc(StreamProc* proc, unsigned kind, unsigned brdid);
94 
96  unsigned NumProc() const { return fProc.size(); }
97 
99  StreamProc* GetProc(unsigned n) const { return n < NumProc() ? fProc[n] : nullptr; }
100 
102  StreamProc* FindProc(const char* name) const;
103 
104  void SetHistFilling(int lvl);
105 
107  void SetDebug(int lvl = 0) { fDebug = lvl; }
109  int GetDebug() const { return fDebug; }
110 
112  virtual void SetStoreKind(unsigned kind = 1);
113 
115  virtual bool InternalHistFormat() const { return true; }
116 
118  virtual void AddRunLog(const char *msg) {}
120  virtual void AddErrLog(const char *msg) {}
122  virtual bool DoLog() { return false; }
123  virtual void PrintLog(const char *msg);
124 
126  virtual void SetSortedOrder(bool = true) {}
128  virtual bool IsSortedOrder() { return false; }
129 
130  virtual H1handle MakeH1(const char* name, const char* title, int nbins, double left, double right, const char* xtitle = 0);
131  virtual bool GetH1NBins(H1handle h1, int &nbins);
132  virtual void FillH1(H1handle h1, double x, double weight = 1.);
133  virtual double GetH1Content(H1handle h1, int bin);
134  virtual void SetH1Content(H1handle h1, int bin, double v = 0.);
135  virtual void ClearH1(H1handle h1);
136  virtual void CopyH1(H1handle tgt, H1handle src);
138  virtual void SetH1Title(H1handle h1, const char* title) {}
140  virtual void TagH1Time(H1handle h1) {}
141 
142  virtual H2handle MakeH2(const char* name, const char* title, int nbins1, double left1, double right1, int nbins2, double left2, double right2, const char* options = 0);
143  virtual bool GetH2NBins(H2handle h2, int &nbins1, int &nbins2);
144  virtual void FillH2(H2handle h2, double x, double y, double weight = 1.);
145  virtual double GetH2Content(H2handle h2, int bin1, int bin2);
146  virtual void SetH2Content(H2handle h2, int bin1, int bin2, double v = 0.);
147  virtual void ClearH2(H2handle h2);
149  virtual void SetH2Title(H2handle h1, const char* title) {}
151  virtual void TagH2Time(H2handle h2) {}
152 
154  virtual void ClearAllHistograms() {}
155 
156  virtual C1handle MakeC1(const char* name, double left, double right, base::H1handle h1 = nullptr);
157  virtual void ChangeC1(C1handle c1, double left, double right);
158  virtual int TestC1(C1handle c1, double value, double *dist = nullptr);
159  virtual double GetC1Limit(C1handle c1, bool isleft = true);
160 
162  virtual bool CreateStore(const char* storename) { return false; }
164  virtual bool CloseStore() { return false; }
166  virtual bool CreateBranch(const char* name, const char* class_name, void** obj) { return false; }
168  virtual bool CreateBranch(const char* name, void* member, const char* kind) { return false; }
170  virtual bool StoreEvent() { return false; }
171 
174  virtual bool RegisterObject(TObject* tobj, const char* subfolder = nullptr) { return false; }
175 
176 
178  virtual bool CallFunc(const char* funcname, void* arg) { return false; }
179 
180  // this is list of generic methods for common data processing
181 
183  bool IsRawAnalysis() const { return fAnalysisKind == kind_Raw; }
184 
186  void SetRawAnalysis(bool on = true) { fAnalysisKind = on ? kind_Raw : kind_Stream; }
187 
189  bool IsTriggeredAnalysis() const { return fAnalysisKind == kind_Triggered; }
190 
192  void SetTriggeredAnalysis(bool on = true) { fAnalysisKind = on ? kind_Triggered : kind_Stream; }
193 
195  bool IsStreamAnalysis() const { return fAnalysisKind == kind_Stream; }
196 
198  void SetTimeSorting(bool on);
199 
201  void SetTimeMasterIndex(unsigned indx) { fTimeMasterIndex = indx; }
202 
203  void ProvideRawData(const Buffer& buf);
204 
205  bool AnalyzeSyncMarkers();
206 
207  bool CollectNewTriggers();
208 
209  bool ScanDataForNewTriggers();
210 
211  bool AnalyzeNewData(base::Event* &evt);
212 
214  bool HasTrigEvent() const { return fTrigEvent != nullptr; }
215 
216  bool AddToTrigEvent(const std::string& name, base::SubEvent* sub);
217 
218  bool ProduceNextEvent(base::Event* &evt);
219 
220  virtual bool ProcessEvent(base::Event* evt);
221 
222  void UserPreLoop(Processor* only_proc = nullptr, bool call_when_running = false);
223 
224  void UserPostLoop(Processor* only_proc = nullptr);
225  };
226 }
227 
228 #endif
Memory management class.
Definition: Buffer.h:49
Event - collection of several subevents.
Definition: Event.h:17
Central data and process manager.
Definition: ProcMgr.h:30
bool IsRawAnalysis() const
Returns true if raw analysis is configured.
Definition: ProcMgr.h:183
virtual void SetSortedOrder(bool=true)
Set if histograms folders should be created in sorted alphabetical order, default false.
Definition: ProcMgr.h:126
virtual H1handle MakeH1(const char *name, const char *title, int nbins, double left, double right, const char *xtitle=0)
Creates 1-dimensional histogram.
Definition: ProcMgr.cxx:142
std::map< unsigned, StreamProc * > StreamProcMap
map of stream processors
Definition: ProcMgr.h:44
void SetHistFilling(int lvl)
Set histogram fill level for all processors.
Definition: ProcMgr.cxx:103
virtual H2handle MakeH2(const char *name, const char *title, int nbins1, double left1, double right1, int nbins2, double left2, double right2, const char *options=0)
Creates 2-dimensional histogram.
Definition: ProcMgr.cxx:252
virtual void TagH1Time(H1handle h1)
Tag histogram time.
Definition: ProcMgr.h:140
StreamProc * GetProc(unsigned n) const
Get processor by sequence number.
Definition: ProcMgr.h:99
virtual double GetH2Content(H2handle h2, int bin1, int bin2)
Get content for 2D histogram.
Definition: ProcMgr.cxx:304
virtual bool CreateBranch(const char *name, const char *class_name, void **obj)
Create branch.
Definition: ProcMgr.h:166
void SetTriggeredAnalysis(bool on=true)
Enabled/disable triggered analysis is configured.
Definition: ProcMgr.h:192
void SetRawAnalysis(bool on=true)
Enable/disable raw analysis.
Definition: ProcMgr.h:186
virtual bool DoLog()
Returns true if logging is enabled.
Definition: ProcMgr.h:122
bool IsTriggeredAnalysis() const
Returns true if triggered analysis is configured.
Definition: ProcMgr.h:189
bool IsStreamAnalysis() const
Returns true if full timed stream analysis is configured.
Definition: ProcMgr.h:195
void ClearSecondName()
Clear name of second macro, will not be executed at all.
Definition: ProcMgr.h:87
unsigned fTimeMasterIndex
! processor index, which time is used for all other subsystems
Definition: ProcMgr.h:51
bool AnalyzeNewData(base::Event *&evt)
Analyze new data, if triggered analysis configured - immediately produce new event.
Definition: ProcMgr.cxx:767
std::vector< EventProc * > fEvProc
! all event processors
Definition: ProcMgr.h:49
virtual bool CreateStore(const char *storename)
create data store, for the moment - ROOT tree
Definition: ProcMgr.h:162
virtual bool StoreEvent()
Store event.
Definition: ProcMgr.h:170
virtual void ClearAllHistograms()
Clear all histograms.
Definition: ProcMgr.h:154
virtual bool GetH2NBins(H2handle h2, int &nbins1, int &nbins2)
get number of bins for 2D histogram
Definition: ProcMgr.cxx:271
static void ClearInstancePointer(ProcMgr *mgr=nullptr)
clear instance pointer
Definition: ProcMgr.cxx:54
virtual bool ProcessEvent(base::Event *evt)
Process event - consequently calls all event processors.
Definition: ProcMgr.cxx:879
void SetDebug(int lvl=0)
Set debug level.
Definition: ProcMgr.h:107
void ProvideRawData(const Buffer &buf)
Method to provide raw data on base of data kind to the processor.
Definition: ProcMgr.cxx:493
TTree * fTree
! abstract tree pointer, will be used in ROOT implementation
Definition: ProcMgr.h:53
int fDfltHistLevel
! default histogram fill level for any new created processor
Definition: ProcMgr.h:54
virtual void ClearH2(H2handle h2)
Clear 2D histogram.
Definition: ProcMgr.cxx:338
int SyncIdDiff(unsigned id1, unsigned id2) const
Method calculated difference id2-id1, used for sync markers identification Sync ID overflow is taken ...
Definition: ProcMgr.cxx:517
bool CollectNewTriggers()
Method to collect triggers.
Definition: ProcMgr.cxx:693
virtual void SetH1Content(H1handle h1, int bin, double v=0.)
set histogram content
Definition: ProcMgr.cxx:198
void DeleteAllProcessors()
Delete all processors.
Definition: ProcMgr.cxx:83
bool AddToTrigEvent(const std::string &name, base::SubEvent *sub)
add subevent with the name to the trigger event
Definition: ProcMgr.cxx:809
std::vector< StreamProc * > fProc
! all stream processors
Definition: ProcMgr.h:47
void SetTimeSorting(bool on)
Set sorting flag for all registered processors.
Definition: ProcMgr.cxx:484
int GetDebug() const
Returns debug level.
Definition: ProcMgr.h:109
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
const std::string & GetSecondName() const
Returns number of second macro.
Definition: ProcMgr.h:90
static ProcMgr * AddProc(Processor *proc)
add processor to instance
Definition: ProcMgr.cxx:451
unsigned NumProc() const
Get number of registered processors.
Definition: ProcMgr.h:96
int fDebug
! debug level
Definition: ProcMgr.h:57
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
void UserPostLoop(Processor *only_proc=nullptr)
post-loop
Definition: ProcMgr.cxx:419
virtual void CopyH1(H1handle tgt, H1handle src)
Copy 1D histogram.
Definition: ProcMgr.cxx:226
bool ScanDataForNewTriggers()
Method to produce data for new triggers.
Definition: ProcMgr.cxx:756
bool AnalyzeSyncMarkers()
Check current sync markers TODO: configure which processor is time master TODO: work with unsynchroni...
Definition: ProcMgr.cxx:542
virtual void TagH2Time(H2handle h2)
Tag histogram time.
Definition: ProcMgr.h:151
virtual double GetH1Content(H1handle h1, int bin)
get histogram context
Definition: ProcMgr.cxx:183
static ProcMgr * instance()
Return global instance of processor manager, provided by framework.
Definition: ProcMgr.cxx:46
virtual bool CloseStore()
Close store.
Definition: ProcMgr.h:164
AnalysisKind fAnalysisKind
! ignore all events, only single scan, not output events
Definition: ProcMgr.h:52
void SetSecondName(const std::string &name="second.C")
Set name of second macro, which executed after first.C.
Definition: ProcMgr.h:84
virtual void SetStoreKind(unsigned kind=1)
Set store kind for all processors.
Definition: ProcMgr.cxx:119
virtual void ChangeC1(C1handle c1, double left, double right)
change condition limits
Definition: ProcMgr.cxx:360
ProcMgr * AddProcessor(Processor *proc)
add processor
Definition: ProcMgr.cxx:438
GlobalMarksQueue fTriggers
!< list of current triggers
Definition: ProcMgr.h:50
virtual void ClearH1(H1handle h1)
Clear 1D histogram.
Definition: ProcMgr.cxx:213
bool HasTrigEvent() const
Returns true if trigger even exists.
Definition: ProcMgr.h:214
virtual void AddErrLog(const char *msg)
Add error log.
Definition: ProcMgr.h:120
virtual void FillH1(H1handle h1, double x, double weight=1.)
Fill histogram.
Definition: ProcMgr.cxx:168
virtual bool InternalHistFormat() const
When returns true, indicates that simple histogram format is used.
Definition: ProcMgr.h:115
virtual void SetH2Content(H2handle h2, int bin1, int bin2, double v=0.)
Set content for 2D histogram.
Definition: ProcMgr.cxx:321
ProcMgr()
constructor
Definition: ProcMgr.cxx:15
StreamProc * FindProc(const char *name) const
Find processor by name.
Definition: ProcMgr.cxx:71
virtual C1handle MakeC1(const char *name, double left, double right, base::H1handle h1=nullptr)
create condition
Definition: ProcMgr.cxx:351
virtual bool GetH1NBins(H1handle h1, int &nbins)
get number of histogram bins
Definition: ProcMgr.cxx:157
base::Event * fTrigEvent
! current event, filled when performing triggered analysis
Definition: ProcMgr.h:56
virtual void FillH2(H2handle h2, double x, double y, double weight=1.)
Fill 2D histogram.
Definition: ProcMgr.cxx:284
virtual ~ProcMgr()
destructor
Definition: ProcMgr.cxx:35
virtual bool CreateBranch(const char *name, void *member, const char *kind)
Create branch.
Definition: ProcMgr.h:168
virtual bool CallFunc(const char *funcname, void *arg)
method to call function by name
Definition: ProcMgr.h:178
std::string fSecondName
! name of second.C script
Definition: ProcMgr.h:46
static ProcMgr * fInstance
! instance
Definition: ProcMgr.h:59
StreamProcMap fMap
! map for fast access
Definition: ProcMgr.h:48
void UserPreLoop(Processor *only_proc=nullptr, bool call_when_running=false)
pre-loop
Definition: ProcMgr.cxx:385
virtual void AddRunLog(const char *msg)
Add run log.
Definition: ProcMgr.h:118
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
bool ProduceNextEvent(base::Event *&evt)
Very central method - select if possible data for next event.
Definition: ProcMgr.cxx:829
virtual bool IsSortedOrder()
Returns true if histograms folders created in sorted alphabetical order.
Definition: ProcMgr.h:128
virtual unsigned SyncIdRange() const
range for sync messages
Definition: ProcMgr.h:62
void SetTimeMasterIndex(unsigned indx)
Specify processor index, which is used as time reference for all others.
Definition: ProcMgr.h:201
int fDfltStoreKind
! default store kind for any new created processor
Definition: ProcMgr.h:55
virtual void PrintLog(const char *msg)
print log message
Definition: ProcMgr.cxx:63
virtual double GetC1Limit(C1handle c1, bool isleft=true)
get condition limit
Definition: ProcMgr.cxx:377
bool RegisterProc(StreamProc *proc, unsigned kind, unsigned brdid)
Enter processor for processing data of specified kind.
Definition: ProcMgr.cxx:459
Abstract processor.
Definition: base/Processor.h:62
Abstract processor of data streams.
Definition: StreamProc.h:21
SubEvent - base class for all event structures Need for: virtual destructor - to be able delete any i...
Definition: base/SubEvent.h:14