CMS 3D CMS Logo

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: 30/01/2014
4 
6 #include <cstdlib>
7 
8 //--------------------------------------
9 // TEcnaParPaths.cc
10 // Class creation: 19 May 2005
11 // Documentation: see TEcnaParPaths.h
12 //--------------------------------------
13 
15 //______________________________________________________________________________
16 //
17 
19 {
20 //destructor
21 
22  // std::cout << "[Info Management] CLASS: TEcnaParPaths. DESTROY OBJECT: this = " << this << std::endl;
23 }
24 
25 //===================================================================
26 //
27 // Constructors
28 //
29 //===================================================================
31 {
32 // Constructor without argument
33  // std::cout << "[Info Management] CLASS: TEcnaParPaths. CREATE OBJECT: this = " << this << std::endl;
34  Init();
35 }
36 
38 {
39 // Constructor without argument
40  // std::cout << "[Info Management] CLASS: TEcnaParPaths. CREATE OBJECT: this = " << this << std::endl;
41  Init();
42  Long_t i_this = (Long_t)this;
43  pObjectManager->RegisterPointer("TEcnaParPaths", i_this);
44 }
45 
46 
48 {
49  fgMaxCar = (Int_t)512; // max number of characters in TStrings
50 
51  fTTBELL = '\007';
52 
53  //................ Init CNA Command and error numbering
54  fCnaCommand = (Int_t)0;
55  fCnaError = (Int_t)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  Int_t MaxCar = fgMaxCar;
94  fCfgResultsRootFilePath.Resize(MaxCar);
96 
97  //..... put the name of the ascii file (containing the paths for CNA treatements)
98  // in the string cFileNameForCnaPaths and in class attribute fFileForResultsRootFilePath
99 
100  if ( argFileName == "" )
101  {
102  std::string cFileNameForCnaPaths = "ECNA/path_results_root"; // config file name
103  TString s_file_name = cFileNameForCnaPaths.c_str();
104  const Text_t *t_file_name = (const Text_t *)s_file_name.Data();
105 
106  TString s_path_name = gSystem->Getenv("HOME"); // get user's home directory path
107 
108  fFileForResultsRootFilePath = s_path_name;
109  fFileForResultsRootFilePath.Append('/');
110  fFileForResultsRootFilePath.Append(t_file_name);
111  }
112  else
113  {
114  fFileForResultsRootFilePath = argFileName.Data();
115  }
116 
117  //........ Reading of the paths in the file named fFileForResultsRootFilePath.Data()
118  //
120 
121  if(fFcin_rr.fail() == kFALSE)
122  {
123  fFcin_rr.clear();
124  std::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  std::cout << fTTBELL << std::endl
135  << " ***************************************************************************************** " << std::endl;
136  std::cout << " !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << std::endl << std::endl
137  << " " << fFileForResultsRootFilePath.Data() << ": file not found. " << std::endl << std::endl
138  << " Please create a subdirectory named ECNA in your HOME directory (if not already done)" << std::endl
139  << " and create a file named path_results_root in the subdirectory ECNA." << std::endl << std::endl
140  << " The file " << fFileForResultsRootFilePath.Data() << " is a configuration file" << std::endl
141  << " for ECNA and must contain one line with the following syntax:" << std::endl << std::endl
142  << " PATH_FOR_THE_RESULTS_ROOT_FILE (without slash at the end of line)" << std::endl
143  << " ================================"
144  << std::endl << std::endl
145  << " Example: $HOME/scratch0/ecna/results_root" << std::endl << std::endl
146  << " ***************************************************************************************** "
147  << fTTBELL << std::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);
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  std::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  //
199  if(fFcin_ra.fail() == kFALSE)
200  {
201  fFcin_ra.clear();
202  std::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  std::cout << fTTBELL << std::endl
213  << " ***************************************************************************************** " << std::endl;
214  std::cout << " !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << std::endl << std::endl
215  << " " << fFileForResultsAsciiFilePath.Data() << ": file not found. " << std::endl << std::endl
216  << " Please create a subdirectory named ECNA in your HOME directory (if not already done)" << std::endl
217  << " and create a file named path_results_ascii in the subdirectory ECNA." << std::endl << std::endl
218  << " The file " << fFileForResultsAsciiFilePath.Data() << " is a configuration file" << std::endl
219  << " for ECNA and must contain one line with the following syntax:" << std::endl << std::endl
220  << " PATH_FOR_THE_RESULTS_ASCII_FILE (without slash at the end of line)" << std::endl
221  << " ================================"
222  << std::endl << std::endl
223  << " Example: $HOME/scratch0/ecna/results_ascii" << std::endl << std::endl
224  << " ***************************************************************************************** "
225  << fTTBELL << std::endl;
226 
227  fFcin_ra.close();
228  FileHere = kFALSE;
229  }
230 
231  return FileHere;
232 
233 } // ----------- (end of GetPathForResultsAsciiFiles) --------------------
234 
235 //================================================================================================
236 
238 {
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);
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  std::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  //
277  if(fFcin_lor.fail() == kFALSE)
278  {
279  fFcin_lor.clear();
280  std::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  std::cout << fTTBELL << std::endl
291  << " ******************************************************************************************************** " << std::endl;
292  std::cout << " !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << std::endl << std::endl
293  << " " << fFileForHistoryRunListFilePath.Data() << ": file not found. " << std::endl << std::endl
294  << " Please create a subdirectory named ECNA in your HOME directory (if not already done)" << std::endl
295  << " and create a file named path_runlist_history_plots in the subdirectory ECNA." << std::endl << std::endl
296  << " The file " << fFileForHistoryRunListFilePath.Data() << " is a configuration file" << std::endl
297  << " for ECNA and must contain one line with the following syntax:" << std::endl << std::endl
298  << " PATH_FOR_THE_LIST_OF_RUNS_FOR_HISTORY_PLOTS_FILE (without slash at the end of line)" << std::endl
299  << " ================================"
300  << std::endl << std::endl
301  << " Example: $HOME/scratch0/ecna/runlist_history_plots" << std::endl << std::endl
302  << " ******************************************************************************************************** "
303  << fTTBELL << std::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 == nullptr )
332  {
333  std::cout << "*TEcnaParPaths::GetCMSSWParameters()> CMSSW_BASE not defined."
334  << " Please, set up the environment (command: eval `scramv1 runtime -csh`)"
335  << fTTBELL << std::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 == nullptr )
346  {
347  std::cout << "*TEcnaParPaths::GetCMSSWParameters()> SCRAM_ARCH not defined."
348  << " Please, set up the environment (command: eval `scramv1 runtime -csh`)"
349  << fTTBELL << std::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 //=======================================================================================
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()
~TEcnaParPaths() override
std::ifstream fFcin_rr
Definition: TEcnaParPaths.h:39
Bool_t GetPathForHistoryRunListFiles()
TString fCfgSCRAMArch
Definition: TEcnaParPaths.h:56
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:105
TString fCfgResultsAsciiFilePath
Definition: TEcnaParPaths.h:48
TString SCRAMArch()
TString fCfgResultsRootFilePath
Definition: TEcnaParPaths.h:45
TString CMSSWSubsystem()
void SetResultsRootFilePath(const TString &)
ClassImp(TEcnaParPaths)
TString BeginningOfResultsAsciiFilePath()
Bool_t GetPaths()
TString PathModulesData()
Bool_t GetPathForResultsRootFiles()
TString fCfgHistoryRunListFilePath
Definition: TEcnaParPaths.h:51
TString fFileForHistoryRunListFilePath
Definition: TEcnaParPaths.h:52
TString fFileForResultsAsciiFilePath
Definition: TEcnaParPaths.h:49
void TruncateResultsRootFilePath(const Int_t &, const Int_t &)
TString fCfgCMSSWSubsystem
Definition: TEcnaParPaths.h:55
TString ResultsRootFilePath()
TString fCfgCMSSWBase
Definition: TEcnaParPaths.h:54
std::ifstream fFcin_lor
Definition: TEcnaParPaths.h:41
TString fTTBELL
Definition: TEcnaParPaths.h:35
void TruncateResultsAsciiFilePath(const Int_t &, const Int_t &)
void AppendResultsRootFilePath(const Text_t *)
Bool_t GetPathForResultsAsciiFiles()
std::ifstream fFcin_ra
Definition: TEcnaParPaths.h:40
TString ResultsAsciiFilePath()
TString fFileForResultsRootFilePath
Definition: TEcnaParPaths.h:46
void SetResultsAsciiFilePath(const TString &)
TString PathTestScramArch()