KaliVeda
Toolkit for HIC analysis
KVDataAnalyser.h
1 /*
2 $Id: KVDataAnalyser.h,v 1.18 2009/04/01 09:28:34 franklan Exp $
3 $Revision: 1.18 $
4 $Date: 2009/04/01 09:28:34 $
5 $Author: franklan $
6 */
7 
8 #ifndef __KVDATAANALYSER_H
9 #define __KVDATAANALYSER_H
10 
11 #include "TObject.h"
12 #include "TTree.h"
13 #include "KVList.h"
14 #include "KVBatchSystem.h"
15 #include "KVString.h"
16 #include "KVNumberList.h"
17 #include "TEnv.h"
18 #include "KV2Body.h"
19 #include "KVUnownedList.h"
20 class KVDBRun;
21 class KVDBRunFile;
22 class KVDBSystem;
23 class KVDataAnalysisTask;
24 
59 class KVDataAnalyser : public TObject {
60 
61 public:
62  struct UserClass {
63  KVString name; // the name of the class
64  KVString imp_file; // the name of the implementation file
65  KVString dec_file; // the name of the header file
66  KVString dir_name = "$(PWD)"; // the name of the directory containing the files
67 
68  /* N.B.: TSystem::ExpandPathName does not expand ".", this is why we use "$(PWD)" */
69 
70  KVString get_full_path(const KVString&, const KVString& = "") const;
71  KVString full_path_imp(const KVString& other_dir = "") const
72  {
73  return get_full_path(imp_file, other_dir);
74  }
75  KVString full_path_dec(const KVString& other_dir = "") const
76  {
77  return get_full_path(dec_file, other_dir);
78  }
80  {
81  return !imp_file.IsNull() && !dec_file.IsNull();
82  }
83  void reset()
84  {
85  name = imp_file = dec_file = "";
86  dir_name = "$(PWD)";
87  }
88  };
89 
90 private:
91  KVDataAnalysisTask* fTask;
92  KVString fDataType;
93  Bool_t fBatch;
94  KVString fBatchName;
95  Long64_t nbEventToRead;
96 
97  Bool_t fMenus;
98  Bool_t fQuit;
99  Bool_t fSubmit;
100 
101  KVString fIncludes;
102  KVString fLibraries;
103  UserClass fUserClass;
104  Bool_t fUserClassIsOK;
105  KVString fUserClassOptions;
106  KVString fUserClassAlternativeBaseClass;
107 
108  KVDataAnalyser* fParent;
109 
110  std::unique_ptr<TEnv> fBatchEnv;
111  KVBatchSystem* fBatchSystem;
112  Bool_t fChoseRunMode;
113 
114  TList* fWorkDirEnd;
115  static Bool_t fCleanAbort;
116  Bool_t fUseBaseClassSubmitTask;
117 
118  Double_t fStatusUpdateInterval;
119 
120 protected:
121  TList* fWorkDirInit;
122  void ScanWorkingDirectory(TList**);
123  void CopyAnalysisResultsToLaunchDirectory();
124 
125  virtual Bool_t CheckIfUserClassIsValid(const KVString& alternative_base_class = "");
126  TObject* GetInstanceOfUserClass(const KVString& alternative_base_class = "");
127 
128  const Char_t* GetACliCMode();
129 
130  void OpenBatchInfoFile(const TString& filename)
131  {
135 
136  if (!fBatchEnv || filename != fBatchEnv->GetRcName()) {
137  fBatchEnv.reset(new TEnv(filename));
138  }
139  }
140  TEnv* GetBatchInfoFile() const
141  {
142  return fBatchEnv.get();
143  }
144  virtual Bool_t PreSubmitCheck()
145  {
146  return kTRUE;
147  }
148  virtual void PostRunReset();
149  virtual Bool_t NeedToChooseWhatToDo() const
150  {
151  return !GetAnalysisTask();
152  }
153  virtual Bool_t NeedToChooseWhatToAnalyse() const
154  {
155  AbstractMethod("NeedToChooseWhatToAnalyse");
156  return kTRUE;
157  }
158  virtual void ChooseWhatToAnalyse()
159  {
160  }
161  virtual void ChooseWhatToDo()
162  {
163  }
164  virtual Bool_t CheckWhatToAnalyseAndHow();
165 
166  virtual void set_up_analyser_for_task(KVDataAnalyser* the_analyser);
167 
168 public:
169  enum EProofMode {
172  Proof
173  };
174 private:
175  EProofMode fProofMode;
176 public:
178  {
179  fProofMode = e;
180  }
182  {
183  return fProofMode;
184  }
185 
186  static void SetAbortProcessingLoop(Bool_t now = kTRUE)
187  {
189  fCleanAbort = now;
190  }
192  {
193  return fCleanAbort;
194  }
195 
196  KVDataAnalyser();
197  virtual ~KVDataAnalyser();
198 
199  void SetUserClass(const UserClass& kvs, Bool_t check = kTRUE);
201  {
202  return fUserClass.name;
203  }
204  const UserClass& GetUserClass() const
205  {
206  return fUserClass;
207  }
209  {
210  return fUserClassIsOK;
211  }
212 
214  {
215  return 0;
216  }
217 
218  virtual void Run();
219  virtual void RunMenus();
220  void ChooseUserClass();
221  void ChooseRunningMode();
222  virtual void SubmitTask();
223  virtual Bool_t CheckTaskVariables();
225 
226  void SetBatchMode(Bool_t on = kTRUE)
227  {
228  fBatch = on;
229  }
231  {
232  return fBatch;
233  }
234  void SetBatchName(const Char_t* batchname)
235  {
236  fBatchName = batchname;
237  }
239  {
240  return fBatchName.Data();
241  }
243  {
244  fBatchSystem = bs;
245  fChoseRunMode = kTRUE;
246  if (bs) fBatchSystem->cd();
247  }
248  virtual const KVBatchSystem* GetBatchSystem()
249  {
250  return fBatchSystem;
251  }
253 
254  const Char_t* GetLaunchDirectory() const;
256  const Char_t* GetBatchStatusFileName() const;
257  void UpdateBatchStatusFile(Int_t totev, Int_t evread, TString disk) const;
258  void DeleteBatchStatusFile() const;
260  {
261  return 0;
262  }
263  virtual Bool_t CheckStatusUpdateInterval(Long64_t nevents) const;
264  void SetStatusUpdateInterval(double t)
265  {
266  fStatusUpdateInterval = t;
267  }
269  {
270  return fStatusUpdateInterval;
271  }
272 
273  void DoStatusUpdate(Long64_t nevents) const;
274 
276  {
277  return fTask;
278  }
279  const KVString& GetDataType() const
280  {
281  return fDataType;
282  }
283  const KVString& GetUserIncludes() const
284  {
285  return fIncludes;
286  }
287  const KVString& GetUserLibraries() const
288  {
289  return fLibraries;
290  }
291  virtual void SetFileList(const KVUnownedList&)
292  {
293  AbstractMethod("SetFileList(KVUnownedList&)");
294  }
295  virtual void SetAuxFileList(const KVUnownedList&)
296  {
297  AbstractMethod("SetAuxFileList(const KVUnownedList&))");
298  }
299 
301  {
302  Info("SetNbEventToRead", "called with %lld", nb);
303  nbEventToRead = nb;
304  }
305 
307  {
308  return nbEventToRead;
309  }
310 
311  void ChooseNbEventToRead();
313  void SetDataType(const Char_t* name)
314  {
315  fDataType = name;
316  }
317 
318  void SetUserIncludes(const Char_t* incDirs = 0);
319  void SetUserLibraries(const Char_t* libs = 0);
320 
321  virtual void Reset();
322 
324  {
325  fParent = da;
326  }
328  {
329  return fParent;
330  }
331 
332  static KVDataAnalyser* GetAnalyser(const Char_t* plugin);
333  virtual Bool_t ReadBatchEnvFile(const TString&);
334  virtual void WriteBatchEnvFile(const TString&, Bool_t sav = kTRUE);
335 
336  virtual TString ExpandAutoBatchName(const Char_t* format) const;
337 
338  /* methods which can be used to customise analysis class behaviour.
339  they can be called from the analysis class using the global
340  pointer to the current data analyser, gDataAnalyser */
341  virtual void preInitAnalysis() {}
342  virtual void postInitAnalysis() {}
343  virtual void preInitRun() {}
344  virtual void postInitRun() {}
345  virtual void preAnalysis() {}
346  virtual void postAnalysis() {}
347  virtual void preEndRun() {}
348  virtual void postEndRun() {}
349  virtual void preEndAnalysis() {}
350  virtual void postEndAnalysis() {}
351 
352  void WriteBatchInfo(TTree*);
353 
354  virtual void RegisterUserClass(TObject*) {}
355 
356  void SetUserClassOptions(const Char_t* o = "")
357  {
358  fUserClassOptions = o;
359  }
361  {
362  return fUserClassOptions;
363  }
364 
365  static void RunAnalyser(const Char_t* plugin = "");
366 
368 
369  virtual void AddJobDescriptionList(TList*);
370 
371  void SetMenus(Bool_t on = kTRUE)
372  {
373  fMenus = on;
374  }
375  Bool_t IsMenus() const
376  {
377  return fMenus;
378  }
379  void SetQuit(Bool_t yes = kTRUE)
380  {
381  fQuit = yes;
382  }
383  Bool_t IsQuit() const
384  {
385  return fQuit;
386  }
387  void SetSubmit(Bool_t yes = kTRUE)
388  {
389  fSubmit = yes;
390  }
391  Bool_t IsSubmit() const
392  {
393  return fSubmit;
394  }
396  {
397  AbstractMethod("GetRootDirectoryOfDataToAnalyse");
398  return "";
399  }
400  virtual const Char_t* GetRecognisedAutoBatchNameKeywords() const;
402  {
403  fUseBaseClassSubmitTask = kTRUE;
404  }
408  virtual const KV2Body* GetKinematics() const
409  {
410  return nullptr;
411  }
412  virtual KVDBSystem* GetAnalysedSystem() const
413  {
414  return nullptr;
415  }
416  virtual KVDBRun* GetAnalysedRun() const
417  {
418  return nullptr;
419  }
421  {
422  return nullptr;
423  }
424  virtual void SetTriggerConditionsForRun(int) {}
425 
426  virtual void SetAnalysedTree(TTree*) {}
427  virtual TTree* GetAnalysedTree() const
428  {
433 
434  return nullptr;
435  }
437  {
438  return "";
439  }
440 
441  ClassDef(KVDataAnalyser, 0) //For submitting & performing data analysis tasks
442 };
443 
445 R__EXTERN KVDataAnalyser* gDataAnalyser;
446 
447 #endif
int Int_t
#define R__EXTERN
#define e(i)
bool Bool_t
char Char_t
double Double_t
constexpr Bool_t kTRUE
#define ClassDef(name, id)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
char name[80]
Relativistic binary kinematics calculator.
Definition: KV2Body.h:178
Base class for interface to a batch job management system.
Definition: KVBatchSystem.h:78
void cd()
Make this the default batch system.
A single raw data file associated with an experimental run ,,.
Definition: KVDBRunFile.h:39
Description of an experimental run in database ,,.
Definition: KVDBRun.h:41
Database class used to store information on different colliding systems studied during an experiment....
Definition: KVDBSystem.h:51
Manager class which sets up and runs data analysis tasks.
virtual void SetTriggerConditionsForRun(int)
virtual void SetAnalysedTree(TTree *)
virtual void postEndRun()
virtual TTree * GetAnalysedTree() const
Bool_t IsMenus() const
Double_t GetStatusUpdateInterval() const
virtual KVDBRun * GetAnalysedRun() const
const UserClass & GetUserClass() const
void UseBaseClassSubmitTask()
void DoStatusUpdate(Long64_t nevents) const
Print infos on events treated, disk usage, memory usage.
virtual void SetFileList(const KVUnownedList &)
virtual TString ExpandAutoBatchName(const Char_t *format) const
void SetParent(KVDataAnalyser *da)
const KVString & GetUserLibraries() const
virtual void Run()
Check all task variables, then run analyser.
virtual void Reset()
virtual void AddJobDescriptionList(TList *)
virtual void WriteBatchEnvFile(const TString &, Bool_t sav=kTRUE)
void SetBatchSystem(KVBatchSystem *bs)
void ChooseNbEventToRead()
Ask user to set number of events to read.
virtual void preInitAnalysis()
void SetUserClassOptions(const Char_t *o="")
Bool_t RunningInLaunchDirectory()
virtual const KVBatchSystem * GetBatchSystem()
virtual void postAnalysis()
void SetBatchMode(Bool_t on=kTRUE)
const KVString & GetDataType() const
void SetUserLibraries(const Char_t *libs=0)
static void SetAbortProcessingLoop(Bool_t now=kTRUE)
KVDataAnalyser * GetParent() const
void SetBatchName(const Char_t *batchname)
TString GetPathToFileInLaunchDirectory(const TString &) const
KVString GetUserClassName()
void WriteBatchInfo(TTree *)
virtual const KV2Body * GetKinematics() const
virtual void RunMenus()
Run data analyser in menu-driven mode.
virtual Bool_t CheckTaskVariables()
void SetSubmit(Bool_t yes=kTRUE)
Bool_t DoUserClassFilesExist()
const Char_t * GetBatchName()
const Char_t * GetLaunchDirectory() const
virtual void SetAuxFileList(const KVUnownedList &)
virtual TString GetAnalyserClassNameForBatchJob()
void SetAnalysisTask(KVDataAnalysisTask *at)
void SetProofMode(EProofMode e)
const KVString & GetUserIncludes() const
virtual const Char_t * GetRecognisedAutoBatchNameKeywords() const
virtual Bool_t CheckStatusUpdateInterval(Long64_t nevents) const
void SetQuit(Bool_t yes=kTRUE)
virtual void SubmitTask()
void SetUserClass(const UserClass &kvs, Bool_t check=kTRUE)
const Char_t * GetBatchStatusFileName() const
Returns full path to file used to store status of running batch jobs.
virtual void preAnalysis()
virtual Long64_t GetTotalEntriesToRead() const
KVDataAnalyser()
Default constructor.
virtual Int_t GetNumberOfFilesToAnalyse() const
const KVString & GetUserClassOptions() const
static KVDataAnalyser * GetAnalyser(const Char_t *plugin)
virtual KVDBRunFile * GetAnalysedRunFile() const
EProofMode GetProofMode() const
static Bool_t IsRunningBatchAnalysis()
void SetDataType(const Char_t *name)
virtual KVString GetRootDirectoryOfDataToAnalyse() const
virtual ~KVDataAnalyser()
Default destructor.
virtual void preEndRun()
virtual void postInitRun()
static void RunAnalyser(const Char_t *plugin="")
void ChooseUserClass()
Choose the user's analysis class.
static Bool_t AbortProcessingLoop()
Long64_t GetNbEventToRead(void) const
virtual void postEndAnalysis()
virtual void preEndAnalysis()
void SetMenus(Bool_t on=kTRUE)
virtual Bool_t ReadBatchEnvFile(const TString &)
void DeleteBatchStatusFile() const
Delete batch status file (and backup - '.bak') for batch job.
void SetStatusUpdateInterval(double t)
virtual void preInitRun()
virtual void RegisterUserClass(TObject *)
void SetUserIncludes(const Char_t *incDirs=0)
Bool_t IsUserClassValid() const
KVDataAnalysisTask * GetAnalysisTask() const
Bool_t BatchMode() const
virtual void postInitAnalysis()
virtual KVDBSystem * GetAnalysedSystem() const
Bool_t IsSubmit() const
void UpdateBatchStatusFile(Int_t totev, Int_t evread, TString disk) const
Update infos in batch status file.
Bool_t IsQuit() const
void SetNbEventToRead(Long64_t nb=0)
Define and manage data analysis tasks.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
Extended TList class which does not own its objects by default.
Definition: KVUnownedList.h:20
void AbstractMethod(const char *method) const
virtual void Info(const char *method, const char *msgfmt,...) const
const char * Data() const
Bool_t IsNull() const
long long Long64_t
KVString full_path_dec(const KVString &other_dir="") const
KVString get_full_path(const KVString &, const KVString &="") const
KVString full_path_imp(const KVString &other_dir="") const