GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Watchers.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #ifndef Gw_Watchers
24 #define Gw_Watchers
25 
26 // ADF includes
27 #include "NarvalInterface.h"
28 #include "Trigger.h"
29 #include "GwLogMessage.h"
30 
31 // ROOT includes
32 #include "TTask.h"
33 #include "TStopwatch.h"
34 #include "TObjArray.h"
35 #include "TCanvas.h"
36 #include "TFile.h"
37 #include "TH1.h"
38 #include "TTimer.h"
39 #include "TROOT.h"
40 #include "TFolder.h"
41 
42 namespace Gw {
43 
45 
60 class Watcher : public TTask
61 {
62 public:
63  static const TList *GetListOfWatchers(){return fgListOfWatchers;}
64 
65 private:
67  static TList *fgListOfWatchers;
69 
72  static void Register(Watcher *, Option_t *opt = "+");
73 
74 public:
76 
80  static Watcher *GetLastRegistered(const Char_t *classname, Option_t *opt = "baseclass");
81 public:
83  static void SetFirst(Watcher *);
84 
85 protected:
86  mutable LogMessage fLog;
87 
88 private:
90  static Bool_t fgDeletePool;
91 
92 private:
94  Bool_t fDeletePool;
95 
97  TObjArray fPoolOfObjects;
99  TObjArray fTagged;
101  TObjArray fReference;
102 
103 protected:
105  TDirectory *fDirectory;
106  TDirectory *fTagDirectory;
108  TFolder *fTopFolder;
110 
111 private:
113  Short_t fLastExecStatus;
114 
115 protected:
118 
119 protected:
121 
125  // TString fKind;
126 
127 protected:
129 
133  void LoadObject(TObject *new_obj, TDirectory *root_dir);
134 
136 
140  TObject *AddToPool(TObject *ob);
141 
143 
146  TCanvas *NewCanvas(Option_t *);
147 
149  void DirToDir(TDirectory *, TDirectory *, TObjArray &, Bool_t load_objects = true);
150  void RemoveFromDir(TObject *, TDirectory *);
151  void AddToDir(TObject *, TDirectory *);
153  Bool_t MakeDir(TFolder *f, TDirectory *mother_dir, Bool_t do_top = true);
155  /*
156  In case of success, path has the form a/b/c/
157  Otherwise empty string. The path is not reset, the user gas to give an empty one
158  */
159  Bool_t GetPathOf(TFolder *f, TObject *searched, TString &path);
160 
161 protected:
163 // TDirectory * GetSubFolder(const Char_t *sub = "");
164  TFolder *GetSubFolder(TFolder *topfolder, const Char_t *sub = "");
165 
167  template <typename Histo_T> Histo_T *
168  MakeTH1(const Char_t *hname, const Char_t *htitle, Int_t binx, Double_t xmin, Double_t xmax, const Char_t *sub = "")
169  {
170  Bool_t def = TH1::AddDirectoryStatus();
171  TH1::AddDirectory(false);
172 
173  Histo_T *h = 0x0; TString subfolder = sub;
174  //
175  h = new Histo_T(hname,htitle,binx,xmin,xmax);
176  if ( h ) {
177  TFolder *folder = GetSubFolder(fTopFolder,sub);
178  folder->Add((TObject *)h);
179  AddToPool(h);
180  // does not belong to directory
181  h->SetDirectory(0);
182  }
183  TH1::AddDirectory(def);
184 
185  return h;
186  }
187  template <typename Histo_T> Histo_T *
188  MakeTH2(const Char_t *hname, const Char_t *htitle,
189  Int_t binx, Double_t xmin, Double_t xmax,
190  Int_t biny, Double_t ymin, Double_t ymax,
191  const Char_t *sub = "")
192  {
193  Bool_t def = TH1::AddDirectoryStatus();
194  TH1::AddDirectory(false);
195 
196  Histo_T *h = 0x0; TString subfolder = sub;
197  //
198  h = new Histo_T(hname,htitle,binx,xmin,xmax,biny,ymin,ymax);
199  if ( h ) {
200  TFolder *folder = GetSubFolder(fTopFolder,sub);
201  folder->Add(h);
202  AddToPool(h);
203  // does not belong to directory
204  h->SetDirectory(0);
205  }
206  TH1::AddDirectory(def);
207 
208  return h;
209  }
210  template <typename Histo_T> Histo_T *
211  MakeTH3(const Char_t *hname, const Char_t *htitle,
212  Int_t binx, Double_t xmin, Double_t xmax,
213  Int_t biny, Double_t ymin, Double_t ymax,
214  Int_t binz, Double_t zmin, Double_t zmax,
215  const Char_t *sub = "")
216  {
217  Bool_t def = TH1::AddDirectoryStatus();
218  TH1::AddDirectory(false);
219 
220  Histo_T *h = 0x0; TString subfolder = sub;
221  //
222  h = new Histo_T(hname,htitle,binx,xmin,xmax,biny,ymin,ymax,binz,zmin,zmax);
223  if ( h ) {
224  TFolder *folder = GetSubFolder(fTopFolder,sub);
225  folder->Add(h);
226  AddToPool(h);
227  // does not belong to directory
228  h->SetDirectory(0);
229  }
230  TH1::AddDirectory(def);
231 
232  return h;
233  }
234 
235 protected:
237  void TagOn(TObject *);
238 
240  void DrawTag(TCanvas *, Option_t *);
241 
242 protected:
244  virtual void DoCanvas(TCanvas *, Option_t *)
245  { ; }
246 
248 
252  Bool_t GetFromTrigger(ADF::DFTrigger *, const char *, ADF::SharedFP *&);
253 
254 public:
255  Watcher();
256  Watcher(const char *name, const char *title, TDirectory *mother_dir_of_watcher = 0x0, TDirectory *mother_dir_tag = 0x0);
257  virtual ~Watcher();
258 
260  virtual void CleanTasks();
261 
263  /*
264  void SetKind(const char *kind)
265  {
266  fKind = kind;
267  }
268 
269  Bool_t IsKind(const char *kind) const
270  {
271  return fKind.Contains(kind);
272  }
273  */
274 
276 
285  virtual UInt_t Snapshot(Option_t * = "*"); //*MENU*
286 
288  void SetLastError(Short_t s = 0)
289  { fLastExecStatus = s ; }
290  Short_t GetLastError() const
291  { return fLastExecStatus ; }
292 
294  void SetLastExecStatus(Short_t s = 0)
295  {
296  fLastExecStatus = s ;
297  }
298 
300  Short_t GetLastExecStatus() const
301  {
302  return fLastExecStatus ;
303  }
304 
306  //virtual TDirectory *GetDirectory(Option_t * /*opt*/ = "")
307  // { return fDirectory; }
308  virtual TDirectory *GetDirectory(Option_t * opt = "")
309  {
310  TString o = opt;
311  if ( o.Contains("tag") )
312  return fTagDirectory;
313  return fDirectory;
314  }
315 
316  virtual TObjArray &GetPoolOfObject()
317  { return fPoolOfObjects; }
318  virtual TObjArray &GetReference()
319  { return fReference; }
320 
322 
327  virtual void SetDirectory(TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_tag, Bool_t load_objects = true);
328 
330 
334  void Pass();
335 
337  virtual void Continue()
338  {;}
339  virtual void Abort()
340  {;}
341  virtual void SetBreakin(Int_t /*breakin*/ = 1)
342  {;}
343  virtual void SetBreakout(Int_t /*breakout*/ = 1)
344  {;}
345 
347 
350  virtual void Add(TTask *);
351 
353 
357  virtual Bool_t SetTrigger(ADF::DFTrigger *);
358 
360  virtual ADF::DFTrigger *GetTrigger() const
361  { return fTrigger; }
362 
364  static void SetGlobalDeletePool(Bool_t d)
365  { fgDeletePool = d; }
366 
368  virtual void SetDeletePool(Bool_t d)
369  { fDeletePool = d; }
370 
372  virtual Bool_t GetDeletePool() const
373  { return fDeletePool; }
374 
376  // virtual void Exec(Option_t *option="")
377 
379 
390  virtual void Zero(Option_t *hname="pool", Option_t *binning=""); //*MENU*
391 
393  void ShowCanvas(Option_t *option="") ; //*MENU*
394 
396  virtual Bool_t TestTag(Option_t *opt); //*MENU*
397 
399  virtual void Tag(Option_t *opt = ""); //*MENU*
400 
401  ClassDef(Watcher,0) // base class for a watcher
402 };
403 
404 class WatcherWithTag : public Watcher
405 {
406 private:
408  //TObjArray fTagged;
410  //TObjArray fReference;
411 
412 protected:
413  //TObjArray &GetReference()
414  // { return fReference; }
415 
416 protected:
418 // TDirectory *fTagDirectory; //!
419 
420 protected:
422  //void TagOn(TObject *);
423 
425  //void DrawTag(TCanvas *, Option_t *);
426 
427 public:
428  WatcherWithTag();
429  WatcherWithTag(const char *name, const char *title, TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_tag);
430  virtual ~WatcherWithTag()
431  {;}
432 
434 
437  // virtual void SetDirectory(TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_tag = 0x0, Bool_t load_objects = true);
438 
440  //virtual TDirectory *GetDirectory(Option_t * opt = "")
441  // { TString o = opt; if ( o.Contains("tag") ) return fTagDirectory; return Watcher::GetDirectory(); }
442 
444  //virtual void Zero(Option_t *hname="pool", Option_t *binning=""); //*MENU*
445 
446  //virtual void Add(TTask *);
447 
449  //virtual Bool_t TestTag(Option_t *opt); //*MENU*
450 
452  //virtual void Tag(Option_t *opt = ""); //*MENU*
453 
454  ClassDef(WatcherWithTag,0) // To handle watchers with tagged histograms
455 };
456 
458 {
459 private:
461  TH1 *fLoopTime;
462 private:
464  TStopwatch fTimeControl;
466  Double_t fDelta;
467 private:
468  TTask *fMother;
469 private:
470  TDirectory *fMotherDirWatcher;
471  TDirectory *fMotherDirTag;
472 
473 private:
475  TTimer *fTimer;
477  TString fLastSaveArg1;
478  TString fLastSaveArg2;
479  TString fLastSaveArg3;
480  Int_t fLastSaveArg4;
481 
482 protected:
484  virtual void DoCanvas(TCanvas *, Option_t *);
485 
486 public:
487  LoopControl(TTask *, TDirectory *, TDirectory *);
488  virtual ~LoopControl();
489 
491  virtual void Zero(Option_t * hname = "pool", Option_t *binning=""); //*MENU*
492 
494 
515 // void Save(const Char_t *main_file = "", const Char_t *tag_file = "0", Option_t *option = "", Int_t autotime = 0); //*MENU* *ARGS={main_file=>fLastSaveArg1,tag_file=>fLastSaveArg2,option=>fLastSaveArg3,autotime=>fLastSaveArg4}
516  void Save(const Char_t *main, const Char_t *tag, const Char_t *option, Int_t autotime); // *MENU* *ARGS={main=>fLastSaveArg1,tag=>fLastSaveArg2,option=>fLastSaveArg3,autotime=>fLastSaveArg4}
517 
519  void AutoSave();
521  void SetAutoTime(Int_t autotime = 0); //*MENU*
523  const Char_t *GetLastSaveArg1()
524  { return fLastSaveArg1.Data(); }
525  const Char_t *GetLastSaveArg2()
526  { return fLastSaveArg2.Data(); }
527  const Char_t *GetLastSaveArg3()
528  { return fLastSaveArg3.Data(); }
530  { return fLastSaveArg4; }
531 
533  //void ShowCanvas(Option_t *option = "") ;//*MENU*
534 
535  virtual void Exec(Option_t *option);
536 
537  ClassDef(LoopControl,0) // to control the execution of LoopOnTasks
538 };
539 
541 
551 class LoopOnTasks : public TTask
552 {
553 private:
555  Bool_t fIsLoop;
557  TTimer *fTimer;
558 
559 private:
560  virtual Bool_t HandleTimer(TTimer* timer);
561 
562 private:
563  LoopControl *fControl;
564 
565 public:
566  LoopOnTasks(TDirectory *dir_watchers, TDirectory *dir_tag) :
567  TTask("LoopOnTask","0"),
568  fIsLoop(false),
569  fTimer(new TTimer()),
570  fControl(new LoopControl(this,dir_watchers,dir_tag)) { Add(fControl); }
571  virtual ~LoopOnTasks()
572  {
573  /* delete fControl */
574  ;
575  // no need to do it, done by task destructor
576  }
577 
579  virtual void Continue()
580  {;}
581  virtual void SetBreakin(Int_t /*breakin*/ = 1)
582  {;}
583  virtual void SetBreakout(Int_t /*breakout*/ = 1)
584  {;}
585 
587  virtual void SetActive(Bool_t active=kTRUE); // *TOGGLE*
588 
590  virtual void Abort(); //*MENU*
591 
592  virtual void ExecuteTask(Option_t* option = "l"); // *MENU*
593 
595  virtual void Exec(Option_t *option);
596 
597  ClassDef(LoopOnTasks,0) // to loop on task once or infinitely
598 };
599 
600 } // end namespace
601 
602 #endif
603 
604 
virtual ~WatcherWithTag()
Definition: Watchers.h:430
void Pass()
force fHasExecuted (recursively) to true
Definition: Watchers.cpp:862
virtual void Add(TTask *)
add only Watchers to the list of tasks to avoid problems.
Definition: Watchers.cpp:244
void DirToDir(TDirectory *, TDirectory *, TObjArray &, Bool_t load_objects=true)
utilities to add/move/remove objects from one dir to another one
Definition: Watchers.cpp:343
TCanvas * NewCanvas(Option_t *)
It creates a new embedded canvas.
Definition: Watchers.cpp:1057
virtual void Continue()
to remove them from the menu
Definition: Watchers.h:579
virtual ~Watcher()
Definition: Watchers.cpp:196
Histo_T * MakeTH2(const Char_t *hname, const Char_t *htitle, Int_t binx, Double_t xmin, Double_t xmax, Int_t biny, Double_t ymin, Double_t ymax, const Char_t *sub="")
Definition: Watchers.h:188
Bool_t GetPathOf(TFolder *f, TObject *searched, TString &path)
in a folder look for the path to an elmement that is not a folder
Definition: Watchers.cpp:270
TDirectory * fTagDirectory
Tagged Objects are in folders. They can be saved/load in/from directory. This is the mother in which ...
Definition: Watchers.h:107
virtual void SetActive(Bool_t active=kTRUE)
To set this active/inactive.
Definition: Watchers.cpp:1867
virtual void DoCanvas(TCanvas *, Option_t *)
To be overwritten by real implementation if a canvas is produced.
Definition: Watchers.h:244
TFolder * GetSubFolder(TFolder *topfolder, const Char_t *sub="")
for a new histogram, it returns the folder it belongs to. It creates sub and all intermediates if req...
Definition: Watchers.cpp:205
Short_t GetLastError() const
Definition: Watchers.h:290
virtual void Exec(Option_t *option)
the main loop
Definition: Watchers.cpp:1824
Bool_t GetFromTrigger(ADF::DFTrigger *, const char *, ADF::SharedFP *&)
Extract from the trigger and given frame pointer (usefull for other watchers)
Definition: Watchers.cpp:792
virtual TDirectory * GetDirectory(Option_t *opt="")
to each watcher a TDirectory is associated
Definition: Watchers.h:308
const Char_t * GetLastSaveArg2()
Definition: Watchers.h:525
int main(int argc, char **argv)
Definition: Benchmark.C:100
const Char_t * GetLastSaveArg3()
Definition: Watchers.h:527
static Watcher * GetLastRegistered(const Char_t *classname, Option_t *opt="baseclass")
to retrieve the last registered watcher of one type.
Definition: Watchers.cpp:86
virtual void Continue()
to remove them from the TTask menu
Definition: Watchers.h:337
TObject * AddToPool(TObject *ob)
facility for other watchers: keep a list of all histograms (objects) for global operations ...
Definition: Watchers.cpp:446
TFolder * fTopFolder
Top folder in which ae stored all spectra.
Definition: Watchers.h:109
Int_t zmin
virtual TObjArray & GetReference()
Definition: Watchers.h:318
virtual void Zero(Option_t *hname="pool", Option_t *binning="")
watch the current frame ... to be overwritten by the watcher
Definition: Watchers.cpp:617
Base class for a Log message.
Definition: GwLogMessage.h:94
virtual void SetBreakin(Int_t=1)
Definition: Watchers.h:341
virtual void CleanTasks()
overloaded for efficiency reasons. allocation of TIter is see in Shark (macos) as time consuming ...
Definition: Watchers.cpp:841
Histo_T * MakeTH3(const Char_t *hname, const Char_t *htitle, Int_t binx, Double_t xmin, Double_t xmax, Int_t biny, Double_t ymin, Double_t ymax, Int_t binz, Double_t zmin, Double_t zmax, const Char_t *sub="")
Definition: Watchers.h:211
void RemoveFromDir(TObject *, TDirectory *)
Definition: Watchers.cpp:374
Base class for a Watcher.
Definition: Watchers.h:60
TDirectory * fDirectory
Objects are in folders. They can be saved/load in/from directory. This is the mother in which this wa...
Definition: Watchers.h:105
header file for GwLogMessage.cpp
LoopOnTasks(TDirectory *dir_watchers, TDirectory *dir_tag)
Definition: Watchers.h:566
void ShowCanvas(Option_t *option="")
Display some results.
Definition: Watchers.cpp:1095
void DrawTag(TCanvas *, Option_t *)
To display tagged histograms and their reference.
Definition: Watchers.cpp:1003
header file for Trigger.cpp
virtual void SetBreakin(Int_t=1)
Definition: Watchers.h:581
void AutoSave()
Auto save in case of timer set. To stop timer, use SetAutoTime(0)
Definition: Watchers.cpp:1744
void SetLastExecStatus(Short_t s=0)
reset last status. 0 means no error, 0 < means error, > 0 means ok with conditions ...
Definition: Watchers.h:294
virtual Bool_t TestTag(Option_t *opt)
Compare the current spectra with the tagged ones using Kolmogorov test.
Definition: Watchers.cpp:943
LogMessage fLog
Definition: Watchers.h:86
virtual void SetBreakout(Int_t=1)
Definition: Watchers.h:343
void SetAutoTime(Int_t autotime=0)
change time to autosave
Definition: Watchers.cpp:1751
Bool_t MakeDir(TFolder *f, TDirectory *mother_dir, Bool_t do_top=true)
in order to save/load, the structure of the top folders should exists in the root dir ...
Definition: Watchers.cpp:291
Histo_T * MakeTH1(const Char_t *hname, const Char_t *htitle, Int_t binx, Double_t xmin, Double_t xmax, const Char_t *sub="")
Build an histogram, set it to sub directories if required and add it to the pool. ...
Definition: Watchers.h:168
static void SetGlobalDeletePool(Bool_t d)
set static flag to delete objects in pool
Definition: Watchers.h:364
virtual void SetDeletePool(Bool_t d)
set flag to delete objects in pool
Definition: Watchers.h:368
static void SetFirst(Watcher *)
move a watcher on top of the list
Definition: Watchers.cpp:119
static const TList * GetListOfWatchers()
Definition: Watchers.h:63
virtual void SetBreakout(Int_t=1)
Definition: Watchers.h:583
WatcherWithTag()
list of tagged histograms
Definition: Watchers.cpp:1123
virtual UInt_t Snapshot(Option_t *="*")
change kind of Watcher
Definition: Watchers.cpp:534
virtual void Tag(Option_t *opt="")
Tag the current watcher.
Definition: Watchers.cpp:987
void AddToDir(TObject *, TDirectory *)
Definition: Watchers.cpp:386
A Shared Frame Pointer.
Definition: Frame.h:597
void TagOn(TObject *)
Add this histogram to the list of tagged histograms.
Definition: Watchers.cpp:901
virtual void Abort()
Abort looping if started.
Definition: Watchers.cpp:1861
Base class for a trigger on a data flow.
Definition: Trigger.h:155
ADF::DFTrigger * fTrigger
trigger associated to this watcher
Definition: Watchers.h:117
virtual void Abort()
Definition: Watchers.h:339
Short_t GetLastExecStatus() const
to get the last status
Definition: Watchers.h:300
header file for NarvalInterface.cpp
To start a loop on tasks.
Definition: Watchers.h:551
LoopControl(TTask *, TDirectory *, TDirectory *)
Definition: Watchers.cpp:1424
virtual void Exec(Option_t *option)
Display some results.
Definition: Watchers.cpp:1787
virtual void DoCanvas(TCanvas *, Option_t *)
To be overwritten by real implementation if a canvas is produced.
Definition: Watchers.cpp:1810
virtual ~LoopControl()
Definition: Watchers.cpp:1453
virtual TObjArray & GetPoolOfObject()
Definition: Watchers.h:316
void LoadObject(TObject *new_obj, TDirectory *root_dir)
to specify what kind of watcher
Definition: Watchers.cpp:399
virtual void SetDirectory(TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_tag, Bool_t load_objects=true)
to change the directory in which watcher's objects are stored
Definition: Watchers.cpp:458
virtual ADF::DFTrigger * GetTrigger() const
To know the trigger in which the frame to be watched is embedded.
Definition: Watchers.h:360
virtual Bool_t SetTrigger(ADF::DFTrigger *)
To set the Frames (through a trigger) associated to this watcher.
Definition: Watchers.cpp:829
Int_t GetLastSaveArg4()
Definition: Watchers.h:529
void Save(const Char_t *main, const Char_t *tag, const Char_t *option, Int_t autotime)
Save the spectra in files.
Definition: Watchers.cpp:1473
const Char_t * GetLastSaveArg1()
Definition: Watchers.h:523
virtual void ExecuteTask(Option_t *option="l")
Definition: Watchers.cpp:1854
virtual ~LoopOnTasks()
Definition: Watchers.h:571
virtual Bool_t GetDeletePool() const
get flag to delete objects in pool
Definition: Watchers.h:372
virtual void Zero(Option_t *hname="pool", Option_t *binning="")
call Zero for all the watchers
Definition: Watchers.cpp:1458
void SetLastError(Short_t s=0)
TMP : migration to TreeWatcher with Cuts : should be removed.
Definition: Watchers.h:288