CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TEcnaParPaths.cc
Go to the documentation of this file.
1 //----------Author's Name: B.Fabbro DSM/IRFU/SPP CEA-Saclay
2 //----------Copyright: Those valid for CEA sofware
3 //----------Modified: 24/03/2011
4 
6 #include <cstdlib>
7 using namespace std;
8 
9 //--------------------------------------
10 // TEcnaParPaths.cc
11 // Class creation: 19 May 2005
12 // Documentation: see TEcnaParPaths.h
13 //--------------------------------------
14 
15 ClassImp(TEcnaParPaths)
16 //______________________________________________________________________________
17 //
18 
20 {
21 //destructor
22 
23  // cout << "[Info Management] CLASS: TEcnaParPaths. DESTROY OBJECT: this = " << this << endl;
24 }
25 
26 //===================================================================
27 //
28 // Constructors
29 //
30 //===================================================================
32 {
33 // Constructor without argument
34  // cout << "[Info Management] CLASS: TEcnaParPaths. CREATE OBJECT: this = " << this << endl;
35  Init();
36 }
37 
39 {
40 // Constructor without argument
41  // cout << "[Info Management] CLASS: TEcnaParPaths. CREATE OBJECT: this = " << this << endl;
42  Init();
43  Long_t i_this = (Long_t)this;
44  pObjectManager->RegisterPointer("TEcnaParPaths", i_this);
45 }
46 
47 
49 {
50  fgMaxCar = (Int_t)512; // max number of characters in TStrings
51  fTTBELL = '\007';
52 
53  //................ Init CNA Command and error numbering
54  fCnaCommand = 0;
55  fCnaError = 0;
56 
57 }// end of Init()
58 
60 {
61  //............................... Get user's parameters from user's directory
62  Bool_t FileHere = kFALSE;
63  Int_t NbFileHere = 0;
64  if( GetPathForResultsRootFiles() == kTRUE ){NbFileHere++;} // Init fCfgResultsRootFilePath
65  if( GetPathForResultsAsciiFiles() == kTRUE ){NbFileHere++;} // Init fCfgResultsAsciiFilePath
66  if( GetPathForHistoryRunListFiles() == kTRUE ){NbFileHere++;} // Init fCfgHistoryRunListFilePath
67 
68  GetCMSSWParameters(); // Init fCfgCMSSWBase, fCfgCMSSWSubsystem, fCfgSCRAMArch <== done in TEcnaGui
69 
70  if( NbFileHere == 3 ){FileHere = kTRUE;}
71  return FileHere;
72 }
73 
74 //=======================================================================================
75 //
76 // M E T H O D S T O G E T T H E P A R A M E T E R S
77 //
78 // F R O M T H E U S E R ' S D I R E C T O R Y
79 //
80 //=======================================================================================
82 {
83  return GetPathForResultsRootFiles("");
84 }
85 
86 Bool_t TEcnaParPaths::GetPathForResultsRootFiles(const TString& argFileName)
87 {
88  // Init fCfgResultsRootFilePath and get it from the file named argFileName
89  // argFileName = complete name of the file (/afs/cern.ch/...)
90  // if string is empty, file name = "ECNA/path_results_root" (located in $HOME user's directory - default - )
91 
92  Bool_t FileHere = kFALSE;
93 
94  Int_t MaxCar = fgMaxCar;
95  fCfgResultsRootFilePath.Resize(MaxCar);
96  fCfgResultsRootFilePath = "?";
97 
98  //..... put the name of the ascii file (containing the paths for CNA treatements)
99  // in the string cFileNameForCnaPaths and in class attribute fFileForResultsRootFilePath
100 
101  if ( argFileName == "" )
102  {
103  string cFileNameForCnaPaths = "ECNA/path_results_root"; // config file name
104  TString s_file_name = cFileNameForCnaPaths.c_str();
105  const Text_t *t_file_name = (const Text_t *)s_file_name.Data();
106 
107  TString s_path_name = gSystem->Getenv("HOME"); // get user's home directory path
108 
109  fFileForResultsRootFilePath = s_path_name;
110  fFileForResultsRootFilePath.Append('/');
111  fFileForResultsRootFilePath.Append(t_file_name);
112  }
113  else
114  {
115  fFileForResultsRootFilePath = argFileName.Data();
116  }
117 
118  //........ Reading of the paths in the file named fFileForResultsRootFilePath.Data()
119  //
120  fFcin_rr.open(fFileForResultsRootFilePath.Data());
121  if(fFcin_rr.fail() == kFALSE)
122  {
123  fFcin_rr.clear();
124  string xResultsFileP;
125  fFcin_rr >> xResultsFileP;
126  fCfgResultsRootFilePath = xResultsFileP.c_str();
127  fFcin_rr.close();
128  FileHere = kTRUE;
129  }
130  else
131  {
132  fFcin_rr.clear();
133  fCnaError++;
134  cout << fTTBELL << endl
135  << " ***************************************************************************************** " << endl;
136  cout << " !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << endl << endl
137  << " " << fFileForResultsRootFilePath.Data() << ": file not found. " << endl << endl
138  << " Please create a subdirectory named ECNA in your HOME directory (if not already done)" << endl
139  << " and create a file named path_results_root in the subdirectory ECNA." << endl << endl
140  << " The file " << fFileForResultsRootFilePath.Data() << " is a configuration file" << endl
141  << " for ECNA and must contain one line with the following syntax:" << endl << endl
142  << " PATH_FOR_THE_RESULTS_ROOT_FILE (without slash at the end of line)" << endl
143  << " ================================"
144  << endl << endl
145  << " Example: $HOME/scratch0/ecna/results_root" << endl << endl
146  << " ***************************************************************************************** "
147  << fTTBELL << endl;
148 
149  fFcin_rr.close();
150  FileHere = kFALSE;
151  }
152 
153  return FileHere;
154 
155 } // ----------- (end of GetPathForResultsRootFiles) --------------------
156 
157 //================================================================================================
158 
160 {
161  return GetPathForResultsAsciiFiles("");
162 }
163 
164 Bool_t TEcnaParPaths::GetPathForResultsAsciiFiles(const TString& argFileName)
165 {
166  // Init fCfgResultsAsciiFilePath and get it from the file named argFileName
167  // argFileName = complete name of the file (/afs/cern.ch/...)
168  // if string is empty, file name = "ECNA/path_results_ascii" (located in $HOME user's directory - default - )
169 
170  Bool_t FileHere = kFALSE;
171 
172  Int_t MaxCar = fgMaxCar;
173  fCfgResultsAsciiFilePath.Resize(MaxCar);
174  fCfgResultsAsciiFilePath = "?";
175 
176  //..... put the name of the ascii file (containing the paths for CNA treatements)
177  // in the string cFileNameForCnaPaths and in class attribute fFileForResultsAsciiFilePath
178 
179  if ( argFileName == "" )
180  {
181  string cFileNameForCnaPaths = "ECNA/path_results_ascii"; // config file name
182  TString s_file_name = cFileNameForCnaPaths.c_str();
183  const Text_t *t_file_name = (const Text_t *)s_file_name.Data();
184 
185  TString s_path_name = gSystem->Getenv("HOME"); // get user's home directory path
186 
187  fFileForResultsAsciiFilePath = s_path_name;
188  fFileForResultsAsciiFilePath.Append('/');
189  fFileForResultsAsciiFilePath.Append(t_file_name);
190  }
191  else
192  {
193  fFileForResultsAsciiFilePath = argFileName.Data();
194  }
195 
196  //........ Reading of the paths in the file named fFileForResultsAsciiFilePath.Data()
197  //
198  fFcin_ra.open(fFileForResultsAsciiFilePath.Data());
199  if(fFcin_ra.fail() == kFALSE)
200  {
201  fFcin_ra.clear();
202  string xResultsFileP;
203  fFcin_ra >> xResultsFileP;
204  fCfgResultsAsciiFilePath = xResultsFileP.c_str();
205  fFcin_ra.close();
206  FileHere = kTRUE;
207  }
208  else
209  {
210  fFcin_ra.clear();
211  fCnaError++;
212  cout << fTTBELL << endl
213  << " ***************************************************************************************** " << endl;
214  cout << " !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << endl << endl
215  << " " << fFileForResultsAsciiFilePath.Data() << ": file not found. " << endl << endl
216  << " Please create a subdirectory named ECNA in your HOME directory (if not already done)" << endl
217  << " and create a file named path_results_ascii in the subdirectory ECNA." << endl << endl
218  << " The file " << fFileForResultsAsciiFilePath.Data() << " is a configuration file" << endl
219  << " for ECNA and must contain one line with the following syntax:" << endl << endl
220  << " PATH_FOR_THE_RESULTS_ASCII_FILE (without slash at the end of line)" << endl
221  << " ================================"
222  << endl << endl
223  << " Example: $HOME/scratch0/ecna/results_ascii" << endl << endl
224  << " ***************************************************************************************** "
225  << fTTBELL << endl;
226 
227  fFcin_ra.close();
228  FileHere = kFALSE;
229  }
230 
231  return FileHere;
232 
233 } // ----------- (end of GetPathForResultsAsciiFiles) --------------------
234 
235 //================================================================================================
236 
238 {
239  return GetPathForHistoryRunListFiles("");
240 }
241 
242 Bool_t TEcnaParPaths::GetPathForHistoryRunListFiles(const TString& argFileName)
243 {
244  // Init fCfgHistoryRunListFilePath and get it from the file named argFileName
245  // argFileName = complete name of the file (/afs/cern.ch/...)
246  // if string is empty, file name = "ECNA/path_runlist_history_plots" (located in $HOME user's directory - default - )
247 
248  Bool_t FileHere = kFALSE;
249 
250  Int_t MaxCar = fgMaxCar;
251  fCfgHistoryRunListFilePath.Resize(MaxCar);
252  fCfgHistoryRunListFilePath = "?";
253 
254  //..... put the name of the ascii file (containing the paths for CNA treatements)
255  // in the string cFileNameForCnaPaths and in class attribute fFileForHistoryRunListFilePath
256 
257  if ( argFileName == "" )
258  {
259  string cFileNameForCnaPaths = "ECNA/path_runlist_history_plots"; // config file name
260  TString s_file_name = cFileNameForCnaPaths.c_str();
261  const Text_t *t_file_name = (const Text_t *)s_file_name.Data();
262 
263  TString s_path_name = gSystem->Getenv("HOME"); // get user's home directory path
264 
265  fFileForHistoryRunListFilePath = s_path_name;
266  fFileForHistoryRunListFilePath.Append('/');
267  fFileForHistoryRunListFilePath.Append(t_file_name);
268  }
269  else
270  {
271  fFileForHistoryRunListFilePath = argFileName.Data();
272  }
273 
274  //........ Reading of the paths in the file named fFileForHistoryRunListFilePath.Data()
275  //
276  fFcin_lor.open(fFileForHistoryRunListFilePath.Data());
277  if(fFcin_lor.fail() == kFALSE)
278  {
279  fFcin_lor.clear();
280  string xHistoryRunListP;
281  fFcin_lor >> xHistoryRunListP;
282  fCfgHistoryRunListFilePath = xHistoryRunListP.c_str();
283  fFcin_lor.close();
284  FileHere = kTRUE;
285  }
286  else
287  {
288  fFcin_lor.clear();
289  fCnaError++;
290  cout << fTTBELL << endl
291  << " ******************************************************************************************************** " << endl;
292  cout << " !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << endl << endl
293  << " " << fFileForHistoryRunListFilePath.Data() << ": file not found. " << endl << endl
294  << " Please create a subdirectory named ECNA in your HOME directory (if not already done)" << endl
295  << " and create a file named path_runlist_history_plots in the subdirectory ECNA." << endl << endl
296  << " The file " << fFileForHistoryRunListFilePath.Data() << " is a configuration file" << endl
297  << " for ECNA and must contain one line with the following syntax:" << endl << endl
298  << " PATH_FOR_THE_LIST_OF_RUNS_FOR_HISTORY_PLOTS_FILE (without slash at the end of line)" << endl
299  << " ================================"
300  << endl << endl
301  << " Example: $HOME/scratch0/ecna/runlist_history_plots" << endl << endl
302  << " ******************************************************************************************************** "
303  << fTTBELL << endl;
304 
305  fFcin_lor.close();
306  FileHere = kFALSE;
307  }
308 
309  return FileHere;
310 
311 } // ----------- (end of GetPathForHistoryRunListFiles) --------------------
312 
313 //================================================================================================
315 {
316  // Init fCfgCMSSWBase, fCfgSCRAMArch and fCfgCMSSWSubsystem
317 
318  Int_t MaxCar = fgMaxCar;
319  fCfgCMSSWBase.Resize(MaxCar);
320  fCfgCMSSWBase = "?";
321 
322  fCfgSCRAMArch.Resize(MaxCar);
323  fCfgSCRAMArch = "?";
324 
325  fCfgCMSSWSubsystem.Resize(MaxCar);
326  fCfgCMSSWSubsystem = "?";
327 
328  //------------ CMSSW_BASE
329 
330  char* ch_cmssw_base = getenv("CMSSW_BASE");
331  if( ch_cmssw_base == 0 )
332  {
333  cout << "*TEcnaParPaths::GetCMSSWParameters()> CMSSW_BASE not defined."
334  << " Please, set up the environment (command: eval `scramv1 runtime -csh`)"
335  << fTTBELL << endl;
336  }
337  else
338  {
339  fCfgCMSSWBase = (TString)ch_cmssw_base;
340  }
341 
342  //------------ SCRAM_ARCH
343 
344  char* ch_scram_arch = getenv("SCRAM_ARCH");
345  if( ch_scram_arch == 0 )
346  {
347  cout << "*TEcnaParPaths::GetCMSSWParameters()> SCRAM_ARCH not defined."
348  << " Please, set up the environment (command: eval `scramv1 runtime -csh`)"
349  << fTTBELL << endl;
350  }
351  else
352  {
353  fCfgSCRAMArch = (TString)ch_scram_arch;
354  }
355 
356  //------------ SUBSYSTEM: CalibCalorimetry
357 
358  fCfgCMSSWSubsystem = "CalibCalorimetry";
359 
360 } // ----------- (end of GetCMSSWParameters) --------------------
361 
362 //=======================================================================================
363 //
364 // M E T H O D S T O R E T U R N T H E P A R A M E T E R S
365 //
366 //=======================================================================================
367 TString TEcnaParPaths::ResultsRootFilePath() {return fCfgResultsRootFilePath;}
368 TString TEcnaParPaths::ResultsAsciiFilePath() {return fCfgResultsAsciiFilePath;}
369 TString TEcnaParPaths::HistoryRunListFilePath(){return fCfgHistoryRunListFilePath;}
370 TString TEcnaParPaths::CMSSWBase() {return fCfgCMSSWBase;}
371 TString TEcnaParPaths::CMSSWSubsystem() {return fCfgCMSSWSubsystem;}
372 TString TEcnaParPaths::SCRAMArch() {return fCfgSCRAMArch;}
373 
374 //.....................................................................................
376 {
377  // ----- return the path of data subdirectory in package "Modules"
378  TString ModulesdataPath = "";
379 
380  const Text_t *t_cmssw_base = (const Text_t *)CMSSWBase().Data();
381  ModulesdataPath.Append(t_cmssw_base);
382  ModulesdataPath.Append('/'); // /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/
383 
384  TString s_src = "src";
385  const Text_t *t_src = (const Text_t *)s_src.Data();
386  ModulesdataPath.Append(t_src);
387  ModulesdataPath.Append('/'); // /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/src
388 
389  const Text_t *t_cmssw_subsystem = (const Text_t *)CMSSWSubsystem().Data();
390  ModulesdataPath.Append(t_cmssw_subsystem);
391  ModulesdataPath.Append('/'); // /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/src/CalibCalorimetry/
392 
393  TString s_package_data_path = "EcalCorrelatedNoiseAnalysisModules/data";
394  const Text_t *t_package_data_path = (const Text_t *)s_package_data_path.Data();
395  ModulesdataPath.Append(t_package_data_path);
396  ModulesdataPath.Append('/');
397  // /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/src/CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/data/
398 
399  return ModulesdataPath;
400 }
401 //.....................................................................................
403 {
404  // ----- return the path of test/slc... subdirectory in CMSSW_BASE
405  TString TestslcPath = "";
406 
407  const Text_t *t_cmssw_base = (const Text_t *)CMSSWBase().Data();
408  TestslcPath.Append(t_cmssw_base);
409  TestslcPath.Append('/'); // /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/
410 
411  TString s_test = "test";
412  const Text_t *t_test = (const Text_t *)s_test.Data();
413  TestslcPath.Append(t_test);
414  TestslcPath.Append('/'); // /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/test
415 
416  const Text_t *t_cmssw_arch = (const Text_t *)SCRAMArch().Data();
417  TestslcPath.Append(t_cmssw_arch);
418  TestslcPath.Append('/'); // /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/test/slc4_ia32_gcc345/
419 
420  return TestslcPath;
421 }
422 
423 //=======================================================================================
424 //
425 // A N C I L L A R Y M E T H O D S C O N C E R N I N G P A T H S
426 //
427 //=======================================================================================
428 void TEcnaParPaths::SetResultsRootFilePath(const TString& ImposedPath) {fCfgResultsRootFilePath = ImposedPath;}
429 void TEcnaParPaths::SetResultsAsciiFilePath(const TString& ImposedPath){fCfgResultsAsciiFilePath = ImposedPath;}
430 void TEcnaParPaths::SetHistoryRunListFilePath(const TString& ImposedPath){fCfgHistoryRunListFilePath = ImposedPath;}
431 
432 void TEcnaParPaths::TruncateResultsRootFilePath(const Int_t& n1, const Int_t& nbcar)
433 {fCfgResultsRootFilePath.Remove(n1,nbcar);}
434 
435 void TEcnaParPaths::TruncateResultsAsciiFilePath(const Int_t& n1, const Int_t& nbcar)
436 {fCfgResultsAsciiFilePath.Remove(n1,nbcar);}
437 
439 {TString sBegin = "?";
440  if( fCfgResultsRootFilePath.BeginsWith("$HOME") ){sBegin = "$HOME";}
441  return sBegin;}
442 
444 {TString sBegin = "?";
445  if( fCfgResultsAsciiFilePath.BeginsWith("$HOME") ){sBegin = "$HOME";}
446  return sBegin;}
447 
448 void TEcnaParPaths::AppendResultsRootFilePath(const Text_t * t_file_nohome)
449 {fCfgResultsRootFilePath.Append(t_file_nohome);}
450 
451 void TEcnaParPaths::AppendResultsAsciiFilePath(const Text_t * t_file_nohome)
452 {fCfgResultsAsciiFilePath.Append(t_file_nohome);}
void GetCMSSWParameters()
Bool_t GetPathForHistoryRunListFiles()
void SetHistoryRunListFilePath(const TString &)
TString CMSSWBase()
TString HistoryRunListFilePath()
TString BeginningOfResultsRootFilePath()
void AppendResultsAsciiFilePath(const Text_t *)
Bool_t RegisterPointer(const TString &, const Long_t &)
Definition: TEcnaObject.cc:103
TString SCRAMArch()
TString CMSSWSubsystem()
void SetResultsRootFilePath(const TString &)
TString BeginningOfResultsAsciiFilePath()
Bool_t GetPaths()
TString PathModulesData()
Bool_t GetPathForResultsRootFiles()
void TruncateResultsRootFilePath(const Int_t &, const Int_t &)
TString ResultsRootFilePath()
tuple cout
Definition: gather_cfg.py:121
void TruncateResultsAsciiFilePath(const Int_t &, const Int_t &)
void AppendResultsRootFilePath(const Text_t *)
Bool_t GetPathForResultsAsciiFiles()
TString ResultsAsciiFilePath()
void SetResultsAsciiFilePath(const TString &)
TString PathTestScramArch()