GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoadStogsWatchers.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (c) IPNL, IN2P3, CNRS *
3  * Contibutor(s) : *
4  * Jeremie Dudouet dudouet(AT)ipnl.in2p3.fr [2014] *
5  * Olivier Stezowski stezow(AT)ipnl.in2p3.fr [2014] *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
24 void LoadClass(TString cpp_path);
25 void AddInclude(TString what_directory);
26 void BeginLoadWatchers();
27 void PreLoad();
28 void LoadWatchers_AGATA();
30 void EndLoadWatchers();
31 void CleanWatchers();
32 void CleanDir(TString Dir);
33 
34 // some globals protected by a namespace
35 namespace __LoadWatchers__ {
36 // used for subdirectories containing campaign related [in Default and Macros]
37 TString CAMPAIGN = "GANIL";
38 
39 // to force compilation / debugging @ the ACLIC level
40 TString CompOpt = "";
41 // just a usefull String
42 TString tmp;
43 // path to agapro
44 TString AGAPRO;
45 // Has GANIL: tested in BeginWatchers, used by other methods
46 Bool_t HAS_GANIL = false; TString MFMDIR(""), VAMOSDIR(""), GRUDIR("");
47 
48 TString WatchersPath = "../../adf";
49 
50 Char_t DefaultW[100]; Char_t MyW[100]; Char_t AncW[100]; Char_t WarningW[100]; Char_t EndColor[100];
51 
52 }
53 using namespace __LoadWatchers__ ;
54 
56 
65 void LoadStogsWatchers(const Char_t *comp_opt = "g", const Char_t *path_to_agapro = "")
66 {
67  // to modify to Aclic compilation's options + to force re-compilation, g for debugging
68  CompOpt = comp_opt;
69 
70  // keep path to agapro to set up WatcherConfig.h so that is knows AGAPRO
71  AGAPRO = path_to_agapro;
72 
74  PreLoad();
77 
79 }
80 
82 void LoadClass(TString cpp_path)
83 {
84  if(!gSystem->IsFileInIncludePath(cpp_path))
85  {
86  cout<<cpp_path<<" not found, class not loaded."<<endl;
87  return;
88  }
89  else
90  {
91  TString CompileLine = ".L " + cpp_path + Form("+%s",CompOpt.Data());
92  gROOT->ProcessLine(CompileLine.Data());
93  }
94 }
95 
96 // add a directory containing includes
97 void AddInclude(TString what_directory)
98 {
99  if(!what_directory.BeginsWith("/"))
100  {
101  TString CurrentDir = gSystem->pwd();
102  CurrentDir += "/";
103  what_directory.Prepend(CurrentDir);
104  }
105  tmp = what_directory; printf("{Conf} Add %s to the include path \n",tmp.Data());
106  tmp.Prepend(" .include ");
107  gROOT->ProcessLine(tmp.Data());
108 }
109 
110 // called before loading any Watchers
111 void PreLoad()
112 {
113  sprintf(DefaultW," \033[1;34m [*] "); sprintf(MyW," \033[1;32m [+] "); sprintf(WarningW," \033[1;31m [!] "); sprintf(AncW," \033[1;35m [+] "); sprintf(EndColor,"\033[0m");
114 
115  LoadClass(Form("%s/Macros/WatchersUtilities.C",WatchersPath.Data()));
116  LoadClass(Form("%s/EmulatorControl.C",WatchersPath.Data()));
117 
119  AddInclude("../");
120  LoadClass("../SToGS_BaseROOTEvents.C");
121 
123  AddInclude("../producer/");
124  LoadClass("../producer/StogsAFP.cpp");
125 
127  AddInclude(Form("%s/Macros/Visu/",WatchersPath.Data()));
128  LoadClass(Form("%s/Macros/Visu/LoupeOnPad.cpp",WatchersPath.Data()));
129 }
130 
133 {
134  // ---> GammaWare PART /////////////////////////
135  printf("******************************************************************** \n") ;
136  printf(" Configure/Compile/Load Watcher for the GANIL phase \n") ;
137  printf("******************************************************************** \n") ;
138 
139  // to add to ROOT the Gw path to look for macros
140  TString tmp, macroPATH;
141 
142  macroPATH = gROOT->GetMacroPath(); tmp = Gw::Env::GetPath("MacrosPath");
143  if ( macroPATH.Contains(tmp.Data()) == false ) {
144  printf("{Conf} Add %s to the macros path \n",tmp.Data());
145  tmp += ":";
146  macroPATH.Prepend(tmp.Data()); gROOT->SetMacroPath(macroPATH.Data());
147  }
148 
149  // add GammaWare include path to ROOT for compilation
150  AddInclude(Gw::Env::GetPath("IncludePath"));
151 
152  // load the different Gw libraries needed
153  gSystem->Load("libGWCORE.so");
154  gSystem->Load("libGWADF.so");
155  gSystem->Load("libGWADFE.so");
156  gSystem->Load("libGWTOOLS.so");
157 
158  if ( AGAPRO.Contains("/") ) {
159 
160  AGAPRO.Append("/include"); printf("{Conf} Add path to AGAPRO includes [%s] to the include path \n",AGAPRO.Data());
161  AGAPRO.Prepend(" .include ");
162  gROOT->ProcessLine(AGAPRO.Data());
163 
164  gSystem->Load("libAgaProCommon.so");
165  gSystem->Load("libCrystalProducer.so");
166  gSystem->Load("libPreprocessingFilter.so");
167  gSystem->Load("libTrackingFilter.so");
168  }
169 
170  // some includes fro watchers
171  gSystem->MakeDirectory("./Out");
172 
173  AddInclude( Form("%s/DefaultWatchers/%s",WatchersPath.Data(),CAMPAIGN.Data()) );
174  AddInclude(Form("%s/Macros",WatchersPath.Data()));
175 
176  // depending on ancillary it set WatchersConfig.h
177  MFMDIR = gSystem->Getenv("MFMLIB"); VAMOSDIR = gSystem->Getenv("VAMOSLIB"); GRUDIR = gSystem->Getenv("GRULIB");
178 
179  std::ofstream fdefs("WatchersConfigNew.h",ios::out | ios::trunc);
180  if ( fdefs.is_open() ) {
181 
182  // AGAPRO Part
183  if ( AGAPRO.Contains("/") ) {
184  fdefs << "#define HAS_AGAPROCONFIG " << std::endl;
185  }
186 
187  // GANIL PART
188  fdefs << "// enable / disable GANIL " << std::endl;
189  if ( MFMDIR != "" && !gSystem->AccessPathName(Form("%s/lib/libMFM.so",MFMDIR.Data())) ) { // GANIL/MFM
190  fdefs << "#define HAS_GANIL " << std::endl; fdefs << "#define WITH_MFM " << std::endl; HAS_GANIL = true;
191 
192  tmp = MFMDIR; tmp+= "/include"; printf("{Conf} Add %s to the include path \n",tmp.Data());
193  tmp.Prepend(" .include ");
194  gROOT->ProcessLine(tmp.Data());
195 
196 
197  if ( VAMOSDIR != ""
198  && !gSystem->AccessPathName(Form("%s/lib/libVamos.so",VAMOSDIR.Data()))
199  && !gSystem->AccessPathName(Form("%s/lib/libGWVamos.so",VAMOSDIR.Data()))
200  // && !gSystem->AccessPathName(Form("%s/lib/libVamos.so",isganil_mfm.Data()))
201  ) {
202  fdefs << "#define HAS_VAMOS " << std::endl;
203 
204  tmp = VAMOSDIR; tmp+= "/include"; printf("{Conf} Add %s to the include path \n",tmp.Data());
205  tmp.Prepend(" .include ");
206  if(VAMOSDIR!=MFMDIR) gROOT->ProcessLine(tmp.Data());
207  }
208  else VAMOSDIR = "";
209 
210  if ( GRUDIR != "" ) {
211  fdefs << "#define HAS_GRU " << std::endl;
212  }
213  else GRUDIR = "";
214  }
215  else MFMDIR = "";
216  }
217  fdefs.close();
218 
219  std::ifstream fich2("WatchersConfig.h");
220  if(!fich2) system("mv WatchersConfigNew.h WatchersConfig.h");
221  else if(system("diff WatchersConfigNew.h WatchersConfig.h")) system("mv WatchersConfigNew.h WatchersConfig.h");
222  else system("rm WatchersConfigNew.h");
223 }
224 
225 // Watchers specific to AGATA
227 {
228  std::cout << DefaultW << " AGATA Default Watchers " << EndColor << std::endl;
229 
230  LoadClass(Form("%s/DefaultWatchers/%s/CanvasVisu.C",WatchersPath.Data(),CAMPAIGN.Data()));
231  LoadClass(Form("%s/DefaultWatchers/%s/ADFWatchers.C",WatchersPath.Data(),CAMPAIGN.Data()));
232  LoadClass(Form("%s/DefaultWatchers/%s/KeyWatchers.C",WatchersPath.Data(),CAMPAIGN.Data()));
233  LoadClass(Form("%s/DefaultWatchers/%s/WatcherClient.C",WatchersPath.Data(),CAMPAIGN.Data()));
234  LoadClass(Form("%s/DefaultWatchers/%s/MetaWatchers.C",WatchersPath.Data(),CAMPAIGN.Data()));
235  LoadClass(Form("%s/DefaultWatchers/%s/PSAWatchers.C",WatchersPath.Data(),CAMPAIGN.Data()));
236  LoadClass(Form("%s/DefaultWatchers/%s/TrackedWatchers.C",WatchersPath.Data(),CAMPAIGN.Data()));
237  LoadClass(Form("%s/DefaultWatchers/%s/EventPSAWatchers.C",WatchersPath.Data(),CAMPAIGN.Data()));
238  LoadClass(Form("%s/DefaultWatchers/%s/CrystalWatchers.C",WatchersPath.Data(),CAMPAIGN.Data()));
239  LoadClass(Form("%s/DefaultWatchers/%s/EventWatchers.C",WatchersPath.Data(),CAMPAIGN.Data()));
240 
241  // tree
242  LoadClass( Form("%s/DefaultWatchers/%s/ADTree.C",WatchersPath.Data(),CAMPAIGN.Data()) );
243 
244  std::cout << DefaultW << " AGATA Default Watchers DONE " << EndColor << std::endl;
245 }
246 
247 // Watchers specific to GANIL
249 {
250  std::cout << AncW << " Watchers for ancillaries " << EndColor << std::endl;
251 
252  if ( HAS_GANIL == false ) {
253  std::cout << AncW << " NO Watchers for ancillaries, install first MFM [MANDATORY] VAMOS / GRU ... to get some " << EndColor << std::endl;
254  return;
255  }
256  if ( MFMDIR != "" ) {
257  cout << "[Load] libMFM from " << MFMDIR << endl;
258  gSystem->Load( "libMFM.so" );
259 
260 // tmp = MFMDIR; tmp+= "/include"; printf("{Conf} Add %s to the include path \n",tmp.Data());
261 // tmp.Prepend(" .include ");
262 // gROOT->ProcessLine(tmp.Data());
263  }
264  if ( VAMOSDIR != "" ) {
265  cout << "[Load] libVamos.so and libGWVamos.so from " << VAMOSDIR << endl;
266  gSystem->Load( "libVamos.so" );
267  gSystem->Load( "libGWVamos.so" );
268 
269 // tmp = VAMOSDIR; tmp+= "/include"; printf("{Conf} Add %s to the include path \n",tmp.Data());
270 // tmp.Prepend(" .include ");
271 // gROOT->ProcessLine(tmp.Data());
272 
273  tmp = gSystem->Getenv("ANALYSIS_AGATA");
274  if ( !(tmp == "") ) {
275  printf("{Conf} ANALYSIS_AGATA found to be %s \n",tmp.Data());
276  }
277  else {
278  printf("{Conf} Set ANALYSIS_AGATA to ./ConfVAMOS \n"); gSystem->Setenv("ANALYSIS_AGATA","./ConfVAMOS");
279  }
280  }
281  if ( GRUDIR != "" ) {
282  cout << "- Load libGRU.so from " << GRUDIR.Data() << endl;
283  gSystem->Load( Form("%s/lib/libGRU.so",GRUDIR.Data()) );
284  tmp = GRUDIR; tmp+= "/include"; printf("- Add %s to the include path \n",tmp.Data());
285  tmp.Prepend(" .include ");
286  gROOT->ProcessLine(tmp.Data());
287  }
288 
289  // to be changed in DefaultGANIL
290  LoadClass(Form("%s/DefaultWatchers/%s/GANILWatchers.C",WatchersPath.Data(),CAMPAIGN.Data()));
291  std::cout << AncW << " Watchers for ancillaries DONE" << EndColor << std::endl;
292 }
293 
294 void CheckConf(TString what_conf)
295 {
296  if ( what_conf == "ADF.conf" ) {
297  //
298  TString adf_path = gSystem->Getenv("ADF_CONF_PATH");
299  //
300  if ( adf_path == "" ) { // the ADF_CONF_PATH is not set, try the current directory. If no ADF.conf file, load a default from server
301  Bool_t ok = false;
302  //
303  if ( !gSystem->AccessPathName("./ADF.conf") ) { // current directory
304  ok = true;
305  }
306  else {
307  // try and downlaod into a temporary directory
308  TString tmp_dir = gSystem->TempDirectory();
309  std::cout << WarningW << "Cannot find ADF.conf ... try and install a default one from internet, make sure it fullfils your needs " << EndColor << std::endl;
310  gSystem->Exec(Form("svn --quiet checkout svn+ssh://anonsvn@anonsvn.in2p3.fr/agata/conf/watchers/ %s",tmp_dir.Data()));
311  if ( gSystem->CopyFile(Form("%s/ADF.conf",tmp_dir.Data()),"./ADF.conf") == 0 )
312  ok = true;
313  }
314  if ( ok ) { // does not exist in the current directory
315  adf_path = gSystem->Getenv("PWD");
316 
317  }
318  }
319  if ( adf_path == "" ) {
320  std::cout << WarningW << " ADF_CONF_PATH not set !" << EndColor << std::endl;
321  }
322  else {
323  gSystem->Setenv("ADF_CONF_PATH",adf_path.Data());
324  printf("\n\t{Conf}\tADF_CONF_PATH has been set to %s \n\n",adf_path.Data());
325  }
326  }
327  if ( what_conf == "CrystalPositionLookUpTable.dat" ) {
328  //
329  Bool_t ok = false;
330  if ( !gSystem->AccessPathName("./CrystalPositionLookUpTable.dat") ) { // current directory
331  ok = true;
332  }
333  else {
334  // try and downlaod into a temporary directory
335  TString tmp_dir = gSystem->TempDirectory();
336  gSystem->Exec(Form("svn --quiet checkout svn+ssh://anonsvn@anonsvn.in2p3.fr/agata/conf/watchers/ %s",tmp_dir.Data()));
337  if ( gSystem->CopyFile(Form("%s/CrystalPositionsLookUpTableGANIL.dat",tmp_dir.Data()),"./CrystalPositionLookUpTable.dat") == 0 ) {
338  std::cout << WarningW << "CrystalPositionLookUpTable.dat was not there ... a default one from internet has been installed, make sure it fullfils your needs! " << EndColor << std::endl;;
339  ok = true;
340  }
341  }
342  if ( !ok ) {
343  std::cout << WarningW << "Mapping of AGATA Ge Crystal, CrystalPositionLookUpTable.dat, not found !" << EndColor << std::endl;
344  }
345  }
346 }
347 
349 {
350  // Gives some command that can be run
351  cout << endl << "|INFO| ... informations ... messages ... help ... for Online/Quasi Online Analysis |" << endl;
352  cout << "|INFO|" << endl;
353  cout << "|INFO|\tTo start stogs Watchers : " << endl;
354  cout << "|INFO|\t\t1 - Configure StogsWatcher.C" << endl;
355  cout << "|INFO|\t\t2 - Compile/Run the Watchers with : " << endl;
356  cout << "|INFO|\t\t.L StogsWatchers.C+" << endl;
357  cout << "|INFO|StogsWatchers() or StogsWatcher(new TFile(\"MySpectra.root\",\"UPDATE\"))" << endl;
358  cout << "|INFO|" << endl;
359 
360  // check whether or not ADF_CONF_PATH has been set !
361  CheckConf("ADF.conf");
362  CheckConf("CrystalPositionLookUpTable.dat");
363 
364  // start a ROOT TBrowser
365  TFolder *TaskFolder =
366  (TFolder*)gROOT->GetRootFolder()->FindObject("Tasks");
367  TBrowser *browser = new TBrowser("Browser",TaskFolder,"Welcome in the wonderful world of Gammaware watchers, have fun !!!");
368 
369  TFolder *SpectraViewerFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("SpectraViewer");
370  if (SpectraViewerFolder)
371  browser->BrowseObject(SpectraViewerFolder);
372  TFolder *GwWatchersFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("GwWatchers");
373  if(GwWatchersFolder)
374  browser->BrowseObject(GwWatchersFolder);
375 
376  if ( browser )
377  browser->Draw();
378 }
379 
380 
383 {
384  CleanDir(Form("%s/DefaultWatchers/%s",WatchersPath.Data(),CAMPAIGN.Data()));
385  CleanDir(".");
386  CleanDir(Form("%s/Macros",WatchersPath.Data()));
387  CleanDir(Form("%s/Macros/Visu",WatchersPath.Data()));
388 }
389 
391 void CleanDir(TString Dir)
392 {
393  gSystem->Exec(Form("rm -rf %s/*_C.so %s/*_C.d %s/*.o %s/*_cpp.so %s/*_cpp.d %s/*.pcm",
394  Dir.Data(),Dir.Data(),Dir.Data(),Dir.Data(),Dir.Data(),Dir.Data() ));
395 }
396 
397 
398 
399 
400 
Char_t EndColor[100]
void CleanDir(TString Dir)
clean up all created watchers
printf("******************************************************************** \n")
void CleanWatchers()
clean up all created watchers
TString macroPATH
void PreLoad()
Char_t WarningW[100]
void LoadWatchers_AGATA()
TString VAMOSDIR("")
TString GRUDIR("")
void EndLoadWatchers()
void CheckConf(TString what_conf)
void AddInclude(TString what_directory)
TString MFMDIR("")
Char_t DefaultW[100]
void LoadWatchers_ANCILLARIES()
ADF::LogMessage & endl(ADF::LogMessage &log)
void LoadClass(TString cpp_path)
functions defined in this macro
void BeginLoadWatchers()
Set Env and Load Gw libraries.
static const char * GetPath(const char *)
to get a particular GW environment variable
Definition: Env.cpp:47
void LoadStogsWatchers(const Char_t *comp_opt="g", const Char_t *path_to_agapro="")