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