GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GANIL/OnlineWatchersLLP.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (c) IPNL, IN2P3, CNRS *
3  * Contibutor(s) : *
4  * Olivier Stezowski stezow(AT)ipnl.in2p3.fr [2014] *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20  ***************************************************************************/
21 
22 #include "TROOT.h"
23 #include "TBrowser.h"
24 #include "WatcherClient.h"
25 
26 using namespace ADF;
27 using namespace Gw;
28 
29 // include there the macros that contains your own setup
30 // i.e. what are the watchers you would like to execute for a given data flow.
31 
32 #include "SetupWatchers.C"
33 
34 void OnlineWatchersLLP(TFile *file = 0x0, TFile *file_tag = 0x0, Bool_t start_loop = false);
35 void OnlineWatchersLLP(TString entrypoint, TString CrystalSel="");
36 Bool_t CheckCrystal(TString crystal);
37 
38 // protected by a namespace
39 namespace _OnlineWatchersLLP_ {
40 
41 TString CrystalSelection="";
42 
43 // Crystal in there, just set empty string to remove some of them
44 const Int_t gNumberOfCrystals = 32;
45 //
46 std::string gCrysLabel[gNumberOfCrystals] = {
47  "00A",
48  "00B",
49  "00C",
50  "02A",
51  "02B",
52  "02C",
53  "03A",
54  "03B",
55  "03C",
56  "04A",
57  "04B",
58  "04C",
59  "05A",
60  "05B",
61  "05C",
62  "09B",
63  "09C",
64  "10A",
65  "10B",
66  "10C",
67 // "11A",
68  "11B",
69  "11C",
70  "12A",
71  "12B",
72  "12C",
73  "13A",
74  "13B",
75  "13C",
76  "14A",
77  "14B",
78  "14C",
79 };
80 // in principle all preprocessing actors are one the same node
81 std::string gBaseName = "172.16.1.1";
82 std::string gMachine[gNumberOfCrystals] = {
83  "14",
84  "21",
85  "12",
86  "23",
87  "22",
88  "19",
89  "18",
90  "08",
91  "09",
92  "01",
93  "05",
94  "15",
95  "55",
96  "24",
97  "29",
98  "26",
99  "56",
100  "16",
101  "17",
102  "11",
103 // "28",
104  "02",
105  "57",
106  "25",
107  "04",
108  "03",
109  "10",
110  "07",
111  "20",
112  "13",
113  "06",
114  "27",
115 };
116 
117 TString EntryPoint="";
118 }
119 
120 
121 using namespace _OnlineWatchersLLP_;
122 
123 // logic for AGATA local level processing : 1 X YY Z
124 // X : in case processes along the chain are on the same machine 0,1,2,3 etc depending on the depth
125 // YY : crystal number
126 // Z : ABC = 012
127 Int_t ComputePort(std::string &which_crys, Int_t level_in_dataflow)
128 {
129  TString result = "", tmp = which_crys.data();
130 
131  tmp.ReplaceAll("A","0");
132  tmp.ReplaceAll("B","1");
133  tmp.ReplaceAll("C","2");
134 
135  result = Form("1%d%s",level_in_dataflow,tmp.Data());
136  return result.Atoi();
137 }
138 
139 void OnlineWatchersLLP(TString entrypoint, TString CrystalSel)
140 {
141  EntryPoint = entrypoint;
142 
143  CrystalSelection = CrystalSel;
144 
145  OnlineWatchersLLP(new TFile("Out/OnlineLLPHistory.root","UPDATE"),new TFile("Out/TagOnlineLLPHistory.root","UPDATE"),true);
146 }
147 
148 
149 void OnlineWatchersLLP(TFile *file, TFile *file_tag, Bool_t start_loop)
150 {
151  TDirectory *Watcher_dir = gROOT, *Watcher_dir_tag = gROOT;
152  if ( file )
153  Watcher_dir = file;
154  if ( file_tag )
155  Watcher_dir_tag = file_tag;
156 
157  // main task.
158  // Adding all emulators to this helps to loop in case Option is l in ExecuteTasks
159  TTask *Snooper = new LoopOnTasks(Watcher_dir,Watcher_dir_tag);
160  if ( start_loop ) {
161  LoopControl *control = (LoopControl *)Snooper->GetListOfTasks()->FindObject("LoopControl");
162  if ( control ) {
163  control->SetAutoTime(3600); // save every hours
164  }
165  }
166 
167  /* // ADF -------------------------------------------------------------
168  WatcherClient *wADF = new WatcherClient("ADF","Watchers on any Agata Frame",Watcher_dir,Watcher_dir_tag);
169  if ( SetupWatchers("ADF",wADF) ) {
170  Snooper->Add ( wADF );
171  wADF->SetConnection( Form("%s%s",gBaseName.data(),gCrysLabel[0].data()) , ComputePort(gCrysLabel[0],0) );
172  }
173  */
174 
175  // Crystal -------------------------------------------------------------
176  // to know if a Watcher has been added to the dispatcher
177  TString tmp = EntryPoint.Copy();
178  tmp.ReplaceAll("CCRYSTAL","");
179 
180  if((EntryPoint!="" &&tmp.Contains("CRYSTAL")) || EntryPoint=="")
181  {
182  for (Int_t i = 0; i < gNumberOfCrystals ; i++ )
183  {
184  // not in the setup
185  if ( gCrysLabel[i] == "" || ! CheckCrystal(gCrysLabel[i]) )
186  continue;
187 
188  WatcherClient *wCrys = new WatcherClient(Form("Crystal_%s",gCrysLabel[i].data()), "Watchers on Crystal Frame",Watcher_dir,Watcher_dir_tag);
189  if ( SetupWatchers("CRYSTAL",wCrys,gCrysLabel[i].data()) )
190  {
191  wCrys->SetConnection(Form("%s%s",gBaseName.data(),gMachine[i].data()), ComputePort(gCrysLabel[i],0) );
192  Snooper->Add ( wCrys );
193  }
194  else delete wCrys;
195  // Int_t p = ComputePort(gCrysLabel[i],0);
196  // printf("%d \n",p);
197  }
198  }
199  // CCrystal -------------------------------------------------------------
200  // to know if a Watcher has been added to the dispatcher
201  if((EntryPoint!="" && EntryPoint.Contains("CCRYSTAL") )|| EntryPoint=="")
202  {
203  for (Int_t i = 0; i < gNumberOfCrystals ; i++ ) {
204 
205  // not in the setup
206  if ( gCrysLabel[i] == "" || ! CheckCrystal(gCrysLabel[i]) )
207  continue;
208 
209  WatcherClient *wCrys = new WatcherClient(Form("CCrystal_%s",gCrysLabel[i].data()),
210  "Watchers on Calibrated Crystal Frame",Watcher_dir,Watcher_dir_tag);
211  if ( SetupWatchers("CCRYSTAL",wCrys,gCrysLabel[i].data()) ) {
212  wCrys->SetConnection(Form("%s%s",gBaseName.data(),gMachine[i].data()), ComputePort(gCrysLabel[i],1) );
213  Snooper->Add ( wCrys );
214  }
215  else delete wCrys;
216  }
217  }
218 
219  // PSA -------------------------------------------------------------
220  // to know if a Watcher has been added to the dispatcher
221  if((EntryPoint!="" && EntryPoint.Contains("PSA") )|| EntryPoint=="")
222  {
223  for (Int_t i = 0; i < gNumberOfCrystals ; i++ ) {
224  // not in the setup
225  if ( gCrysLabel[i] == "" || ! CheckCrystal(gCrysLabel[i]) )
226  continue;
227 
228  WatcherClient *wPSA = new WatcherClient(Form("PSA_%s",gCrysLabel[i].data()),
229  "Watchers on PSA Frame",Watcher_dir,Watcher_dir_tag);
230  if ( SetupWatchers("PSA",wPSA,gCrysLabel[i].data()) ) {
231  wPSA->SetConnection(Form("%s%s",gBaseName.data(),gMachine[i].data()), ComputePort(gCrysLabel[i],2));
232  Snooper->Add ( wPSA );
233  }
234  else delete wPSA;
235  }
236  }
237  //
238  // ANCILLARY
239  /*
240  WatcherClient *wAnc0 = new WatcherClient("ANC_PRO","Watchers on ancillary Data (ranc0)",Watcher_dir,Watcher_dir_tag);
241  if ( SetupWatchers("RANC0",wAnc0) ) {
242  Snooper->Add ( wAnc0 );
243  wAnc0->SetConnection("10.10.1.102", 9013);
244  }
245  else
246  delete wAnc0;
247  */
248  /*
249  WatcherClient *wAnc1 = new WatcherClient("ANC_FIL","Watchers on ancillary Data (ranc1)",Watcher_dir,Watcher_dir_tag);
250  if ( SetupWatchers("RANC1",wAnc1) ) {
251  Snooper->Add ( wAnc1 );
252  wAnc1->SetConnection("172.16.1.102", 9026);
253  }
254  else
255  delete wAnc1;
256  */
257  /*
258  WatcherClient *wAnc = new WatcherClient("ANC","Watchers on ancillary Data",Watcher_dir,Watcher_dir_tag);
259  if ( SetupWatchers("RANC0",wAnc) ) {
260  Snooper->Add ( wAnc );
261  wAnc->SetConnection( "172.16.1.194", 14102);
262  }
263  else
264  delete wAnc;
265 
266 
267  */
268  // add the main ADF to the list of task
269  TSRateCollector *TSCollector = new TSRateCollector("GTS_Rate","Global Timestamp rates");
270  TSCollector->SetDirectory(Watcher_dir,Watcher_dir_tag);
271  Snooper->Add(TSCollector);
272  DoTSRateCollector(Snooper,TSCollector);
273 
274  gROOT->GetListOfTasks()->Add(Snooper);
275 
276  /* for (Int_t i = 0; i < gNumberOfCrystals ; i++ ) {
277  printf("%d %s %d \n",i,gCrysLabel[i].data(),ComputePort(gCrysLabel[i],0) );
278  printf("%d %s %d \n",i,gCrysLabel[i].data(),ComputePort(gCrysLabel[i],1) );
279  printf("%d %s %d \n",i,gCrysLabel[i].data(),ComputePort(gCrysLabel[i],2) );
280  } */
281 
282  if ( !gROOT->IsBatch() ) {
283  TBrowser *b = (TBrowser*)gROOT->GetListOfBrowsers()->Last();
284 
285  TFolder *GwWatchersFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("GwWatchers");
286  if(GwWatchersFolder) b->Add(GwWatchersFolder);
287 
288  TFolder *RootFilesFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("ROOT Files");
289  if(RootFilesFolder) b->Add(RootFilesFolder);
290  }
291  if ( start_loop )
292  Snooper->ExecuteTask("l");
293 }
294 
296  gROOT->GetListOfTasks()->At(0)->Delete();
297 }
298 
299 Bool_t CheckCrystal(TString crystal)
300 {
301  if(CrystalSelection=="")
302  return true;
303  else if (CrystalSelection.Contains(crystal))
304  return true;
305  else
306  return false;
307 }
Bool_t CheckCrystal(TString crystal)
TBrowser * b
void CloseOnlineWatchers()
Int_t ComputePort(std::string &which_crys, Int_t level_in_dataflow)
Bool_t SetupWatchers(const char *df_type, FrameDispatcher *fd, const char *ext="")
It shows how to set up the watchers for different kind of data flow.
std::string gCrysLabel[gNumberOfCrystals]
void SetAutoTime(Int_t autotime=0)
change time to autosave
Definition: Watchers.cpp:1751
void DoTSRateCollector(TTask *top_task, TSRateCollector *collector)
browse all dispatchers to look for TSRate Watcher and add them to the rate collector ...
To get a buffer from an actor, trigg on a Frame and dispach the Frame to sub-watchers.
Bool_t SetConnection(const Char_t *machine="localhost", UInt_t port=9090)
change the place where are picked data
void OnlineWatchersLLP(TFile *file=0x0, TFile *file_tag=0x0, Bool_t start_loop=false)
To start a loop on tasks.
Definition: Watchers.h:551
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
std::string gMachine[gNumberOfCrystals]
compute histograms for several TSRate