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