ROOTANA
Loading...
Searching...
No Matches
manalyzer.h
Go to the documentation of this file.
1// manalyzer.h
2
3#ifndef MANALYZER_H
4#define MANALYZER_H
5
6#include <string>
7#include <vector>
8#include <deque>
9
10#include <thread>
11#include <mutex>
12#include <atomic>
13
14#include "midasio.h"
15#include "mvodb.h"
16
17class TARootHelper;
19class TAFlowEvent;
20
22{
23 public:
24 int fRunNo = 0;
25 std::string fFileName;
26 MVOdb* fOdb = NULL;
29 std::vector<std::string> fArgs;
30 std::vector<char> fBorOdbDump;
31 std::vector<char> fEorOdbDump;
32
33 static std::vector<std::string> fgFileList;
34 static int fgCurrentFileIndex; // this global variable is initialized in manalyzer.cxx
35
36 public:
37 TARunInfo(int runno, const char* filename, const std::vector<std::string>& args);
38 ~TARunInfo();
39
40 public:
43
44 private:
45 TARunInfo() {}; // hidden default constructor
46
47 private:
48 bool fAfterPreEndRun = false;
49 std::deque<TAFlowEvent*> fFlowQueue;
50
51 public:
53};
54
56{
57 public:
59
60 public:
62 virtual ~TAFlowEvent();
63
64 template<class T> T* Find()
65 {
66 TAFlowEvent* f = this;
67 while (f) {
68 T *ptr = dynamic_cast<T*>(f);
69 if (ptr) return ptr;
70 f = f->fNext;
71 }
72 return NULL;
73 }
74
75 private:
76 TAFlowEvent() {}; // hidden default constructor
77};
78
79typedef int TAFlags;
80
81#define TAFlag_OK 0
82#define TAFlag_SKIP (1<<0)
83#define TAFlag_QUIT (1<<1)
84#define TAFlag_WRITE (1<<2)
85#define TAFlag_DISPLAY (1<<3)
86#define TAFlag_SKIP_PROFILE (1<<4)
87
89{
90 public:
91 std::string fModuleName;
92 int fModuleOrder = 0;
93
94 public:
95 TARunObject(TARunInfo* runinfo); // ctor
96 virtual ~TARunObject() {}; // dtor
97
98 public:
99 virtual void BeginRun(TARunInfo* runinfo); // begin of run
100 virtual void EndRun(TARunInfo* runinfo); // end of run
101 virtual void NextSubrun(TARunInfo* runinfo); // next subrun file
102
103 virtual void PauseRun(TARunInfo* runinfo); // pause of run (if online)
104 virtual void ResumeRun(TARunInfo* runinfo); // resume of run (if online)
105
106 virtual void PreEndRun(TARunInfo* runinfo); // generate flow events before end of run
107
108 virtual TAFlowEvent* Analyze(TARunInfo* runinfo, TMEvent* event, TAFlags* flags, TAFlowEvent* flow);
109 virtual TAFlowEvent* AnalyzeFlowEvent(TARunInfo* runinfo, TAFlags* flags, TAFlowEvent* flow);
110 virtual void AnalyzeSpecialEvent(TARunInfo* runinfo, TMEvent* event);
111
112 private:
113 TARunObject(); // hidden default constructor
114};
115
117{
118 public:
119 TAFactory() {}; // ctor
120 virtual ~TAFactory() {}; // dtor
121
122 public:
123 virtual TARunObject* NewRunObject(TARunInfo* runinfo) = 0; // factory for Run objects
124
125 public:
126 virtual void Usage(); // Display usage (flags to pass to init etc)
127 virtual void Init(const std::vector<std::string> &args); // start of analysis
128 virtual void Finish(); // end of analysis
129};
130
131template<class T> class TAFactoryTemplate: public TAFactory
132{
134 {
135 return new T(runinfo);
136 }
137};
138
140{
141 public:
143 //static void Register(TAModuleInterface* m);
144 //static std::vector<TAModuleInterface*>* fgModules;
145 //static std::vector<TAModuleInterface*>* Get() const;
146};
147
148#ifdef HAVE_ROOT
149
150#include "TFile.h"
151#include "TDirectory.h"
152#include "TApplication.h"
153
154class XmlServer;
155class THttpServer;
156
158{
159 public:
160 std::string fOutputFileName;
161 TFile* fOutputFile = NULL;
162
163 public:
164 static std::string fgUserOutputDirectory;
165 static std::string fgUserOutputFileName;
167 static TApplication* fgApp;
168 static THttpServer* fgHttpServer;
169 static std::vector<std::string> fgOutputRootFiles;
170
171 public:
172 TARootHelper(const TARunInfo*);
173 ~TARootHelper(); // dtor
174 void Init();
175
176 private:
177 TARootHelper() { }; // hidden default constructor
178};
179#endif
180
181typedef std::deque<TAFlowEvent*> TAFlowEventQueue;
182typedef std::deque<TAFlags*> TAFlagsQueue;
183
185{
186public: // per-module queues and threads
187 std::vector<std::mutex> fMtFlowQueueMutex; // queue lock
188 std::vector<TAFlowEventQueue> fMtFlowQueue; // event queue
189 std::vector<TAFlagsQueue> fMtFlagQueue; // flags queue
190 std::vector<std::thread*> fMtThreads; // threads
191 std::vector<std::atomic<bool>> fMtThreadIsRunning; // "thread is running" flag
192 std::vector<std::atomic<bool>> fMtThreadIsBusy; // "thread is analyzing an event" flag
193
194public: // shutdown and quit control
195 std::atomic<bool> fMtShutdownRequested; // flag to shutdown all threads
196 std::atomic<bool> fMtQuitRequested; // flag TAFlag_QUIT from per-module threads
197
198public: // queue settings
199 size_t fMtQueueDepth = 0; // maximum number of flow events to queue
200 int fMtQueueFullUSleepTime = 0; // u seconds
201 int fMtQueueEmptyUSleepTime = 0; // u seconds
202
203public: // globals
204 static std::mutex gfLock; // Lock for modules to execute code that is not thread safe (many root fitting libraries)
205
206public:
207 TAMultithreadHelper(int nModules); // ctor
208 ~TAMultithreadHelper(); // dtor
209};
210
211// flag that this version of manalyzer implements the profiler
212
213#define HAVE_MANALYZER_PROFILER 1
214
215// virtualized clock
216
217#include <chrono>
218typedef std::chrono::high_resolution_clock::time_point TAClock;
219typedef std::chrono::duration<double> TAClockDuration;
220inline TAClock TAClockNow() { return std::chrono::high_resolution_clock::now(); }
221
222// user-controlled profiler
223
225{
226public:
229
230public:
231 const std::string fModuleName;
232
233public:
234 TAUserProfilerFlow(TAFlowEvent* flow, const char* name, const TAClock& start); // ctor
235 ~TAUserProfilerFlow(); // dtor
236 double GetTimer() const;
237};
238
239// main program
240
241int manalyzer_main(int argc, char* argv[]);
242
243#endif
244
245/* emacs
246 * Local Variables:
247 * tab-width: 8
248 * c-basic-offset: 3
249 * indent-tabs-mode: nil
250 * End:
251 */
252
Definition mvodb.h:21
virtual void Finish()
virtual TARunObject * NewRunObject(TARunInfo *runinfo)=0
virtual void Init(const std::vector< std::string > &args)
virtual void Usage()
virtual ~TAFactory()
Definition manalyzer.h:120
T * NewRunObject(TARunInfo *runinfo)
Definition manalyzer.h:133
virtual ~TAFlowEvent()
Definition manalyzer.cxx:98
TAFlowEvent * fNext
Definition manalyzer.h:58
T * Find()
Definition manalyzer.h:64
std::vector< TAFlagsQueue > fMtFlagQueue
Definition manalyzer.h:189
std::vector< std::mutex > fMtFlowQueueMutex
Definition manalyzer.h:187
std::atomic< bool > fMtShutdownRequested
Definition manalyzer.h:195
std::vector< std::thread * > fMtThreads
Definition manalyzer.h:190
std::vector< std::atomic< bool > > fMtThreadIsBusy
Definition manalyzer.h:192
std::vector< TAFlowEventQueue > fMtFlowQueue
Definition manalyzer.h:188
static std::mutex gfLock
Definition manalyzer.h:204
std::vector< std::atomic< bool > > fMtThreadIsRunning
Definition manalyzer.h:191
std::atomic< bool > fMtQuitRequested
Definition manalyzer.h:196
std::string fOutputFileName
Definition manalyzer.h:160
static std::string fgUserOutputFileName
Definition manalyzer.h:165
static TApplication * fgApp
Definition manalyzer.h:167
static std::string fgUserOutputDirectory
Definition manalyzer.h:164
static THttpServer * fgHttpServer
Definition manalyzer.h:168
static std::vector< std::string > fgOutputRootFiles
Definition manalyzer.h:169
TFile * fOutputFile
Definition manalyzer.h:161
static TDirectory * fgDir
Definition manalyzer.h:166
void AddToFlowQueue(TAFlowEvent *)
TAFlowEvent * ReadFlowQueue()
std::string fFileName
Definition manalyzer.h:25
std::vector< std::string > fArgs
Definition manalyzer.h:29
std::vector< char > fBorOdbDump
Definition manalyzer.h:30
MVOdb * fOdb
Definition manalyzer.h:26
int fRunNo
Definition manalyzer.h:24
std::deque< TAFlowEvent * > fFlowQueue
Definition manalyzer.h:49
static std::vector< std::string > fgFileList
Definition manalyzer.h:33
std::vector< char > fEorOdbDump
Definition manalyzer.h:31
bool fAfterPreEndRun
Definition manalyzer.h:48
TARootHelper * fRoot
Definition manalyzer.h:27
TAMultithreadHelper * fMtInfo
Definition manalyzer.h:28
static int fgCurrentFileIndex
Definition manalyzer.h:34
void SetAfterPreEndRun()
Definition manalyzer.h:52
virtual void EndRun(TARunInfo *runinfo)
virtual void ResumeRun(TARunInfo *runinfo)
virtual void AnalyzeSpecialEvent(TARunInfo *runinfo, TMEvent *event)
virtual void NextSubrun(TARunInfo *runinfo)
virtual TAFlowEvent * Analyze(TARunInfo *runinfo, TMEvent *event, TAFlags *flags, TAFlowEvent *flow)
virtual void PauseRun(TARunInfo *runinfo)
virtual void BeginRun(TARunInfo *runinfo)
virtual ~TARunObject()
Definition manalyzer.h:96
std::string fModuleName
Definition manalyzer.h:91
int fModuleOrder
Definition manalyzer.h:92
virtual TAFlowEvent * AnalyzeFlowEvent(TARunInfo *runinfo, TAFlags *flags, TAFlowEvent *flow)
virtual void PreEndRun(TARunInfo *runinfo)
const std::string fModuleName
Definition manalyzer.h:231
double GetTimer() const
std::chrono::high_resolution_clock::time_point TAClock
Definition manalyzer.h:218
int TAFlags
Definition manalyzer.h:79
int manalyzer_main(int argc, char *argv[])
std::chrono::duration< double > TAClockDuration
Definition manalyzer.h:219
TAClock TAClockNow()
Definition manalyzer.h:220
std::deque< TAFlowEvent * > TAFlowEventQueue
Definition manalyzer.h:181
std::deque< TAFlags * > TAFlagsQueue
Definition manalyzer.h:182
std::chrono::high_resolution_clock::time_point TAClock
Definition manalyzer.h:218