CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/src/TEcnaParPaths.cc

Go to the documentation of this file.
00001 //----------Author's Name: B.Fabbro DSM/IRFU/SPP CEA-Saclay
00002 //----------Copyright: Those valid for CEA sofware
00003 //----------Modified: 24/03/2011
00004 
00005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaParPaths.h"
00006 #include <cstdlib>
00007 
00008 //--------------------------------------
00009 //  TEcnaParPaths.cc
00010 //  Class creation: 19 May 2005
00011 //  Documentation: see TEcnaParPaths.h
00012 //--------------------------------------
00013 
00014 ClassImp(TEcnaParPaths)
00015 //______________________________________________________________________________
00016 //
00017 
00018   TEcnaParPaths::~TEcnaParPaths()
00019 {
00020 //destructor
00021 
00022  // cout << "[Info Management] CLASS: TEcnaParPaths.      DESTROY OBJECT: this = " << this << endl;
00023 }
00024 
00025 //===================================================================
00026 //
00027 //                   Constructors
00028 //
00029 //===================================================================
00030 TEcnaParPaths::TEcnaParPaths()
00031 {
00032 // Constructor without argument
00033  // cout << "[Info Management] CLASS: TEcnaParPaths.      CREATE OBJECT: this = " << this << endl;
00034   Init();
00035 }
00036 
00037 TEcnaParPaths::TEcnaParPaths(TEcnaObject* pObjectManager)
00038 {
00039 // Constructor without argument
00040  // cout << "[Info Management] CLASS: TEcnaParPaths.      CREATE OBJECT: this = " << this << endl;
00041   Init();
00042   Long_t i_this = (Long_t)this;
00043   pObjectManager->RegisterPointer("TEcnaParPaths", i_this);
00044 }
00045 
00046 
00047 void  TEcnaParPaths::Init()
00048 {
00049   fgMaxCar = (Int_t)512;              // max number of characters in TStrings
00050   fTTBELL = '\007';
00051 
00052   //................ Init CNA Command and error numbering
00053   fCnaCommand = 0;
00054   fCnaError   = 0;
00055 
00056 }// end of Init()
00057 
00058 Bool_t TEcnaParPaths::GetPaths()
00059 {
00060   //............................... Get user's parameters from user's directory
00061   Bool_t FileHere = kFALSE;
00062   Int_t  NbFileHere = 0;
00063   if( GetPathForResultsRootFiles()    == kTRUE ){NbFileHere++;} //  Init fCfgResultsRootFilePath
00064   if( GetPathForResultsAsciiFiles()   == kTRUE ){NbFileHere++;} //  Init fCfgResultsAsciiFilePath
00065   if( GetPathForHistoryRunListFiles() == kTRUE ){NbFileHere++;} //  Init fCfgHistoryRunListFilePath
00066 
00067   GetCMSSWParameters(); //  Init fCfgCMSSWBase, fCfgCMSSWSubsystem, fCfgSCRAMArch <== done in TEcnaGui
00068 
00069   if( NbFileHere == 3 ){FileHere = kTRUE;}
00070   return FileHere;
00071 }
00072 
00073 //=======================================================================================
00074 //
00075 //     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 
00076 //
00077 //     F R O M    T H E    U S E R ' S    D I R E C T O R Y 
00078 //
00079 //=======================================================================================
00080 Bool_t TEcnaParPaths::GetPathForResultsRootFiles()
00081 {
00082   return GetPathForResultsRootFiles("");
00083 }
00084 
00085 Bool_t TEcnaParPaths::GetPathForResultsRootFiles(const TString argFileName)
00086 {
00087   // Init fCfgResultsRootFilePath and get it from the file named argFileName
00088   // argFileName = complete name of the file (/afs/cern.ch/...)
00089   // if string is empty, file name = "ECNA/path_results_root" (located in $HOME user's directory - default - )
00090 
00091   Bool_t FileHere = kFALSE;
00092 
00093   Int_t MaxCar = fgMaxCar;
00094   fCfgResultsRootFilePath.Resize(MaxCar);
00095   fCfgResultsRootFilePath = "?";
00096 
00097   //..... put the name of the ascii file (containing the paths for CNA treatements)
00098   //      in the string cFileNameForCnaPaths and in class attribute fFileForResultsRootFilePath
00099 
00100   if ( argFileName == "" )
00101     {
00102       string cFileNameForCnaPaths = "ECNA/path_results_root";     // config file name
00103       TString s_file_name = cFileNameForCnaPaths.c_str();
00104       const Text_t *t_file_name = (const Text_t *)s_file_name.Data();
00105       
00106       TString s_path_name = gSystem->Getenv("HOME");       // get user's home directory path
00107       
00108       fFileForResultsRootFilePath = s_path_name;
00109       fFileForResultsRootFilePath.Append('/');
00110       fFileForResultsRootFilePath.Append(t_file_name);
00111     }
00112   else
00113     {
00114       fFileForResultsRootFilePath = argFileName.Data();
00115     }
00116 
00117   //........ Reading of the paths in the file named fFileForResultsRootFilePath.Data()
00118   //
00119   fFcin_rr.open(fFileForResultsRootFilePath.Data());
00120   if(fFcin_rr.fail() == kFALSE)
00121     {
00122       fFcin_rr.clear();
00123       string xResultsFileP;
00124       fFcin_rr >> xResultsFileP;
00125       fCfgResultsRootFilePath = xResultsFileP.c_str();
00126       fFcin_rr.close();
00127       FileHere = kTRUE;
00128     }
00129   else
00130     {
00131       fFcin_rr.clear();
00132       fCnaError++;
00133       cout << fTTBELL << endl
00134            << " ***************************************************************************************** " << endl;
00135       cout << "   !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << endl << endl
00136            << "     " << fFileForResultsRootFilePath.Data() << ": file not found. " << endl << endl
00137            << "     Please create a subdirectory named ECNA in your HOME directory (if not already done)" << endl
00138            << "     and create a file named path_results_root in the subdirectory ECNA." << endl << endl
00139            << "     The file " << fFileForResultsRootFilePath.Data() << " is a configuration file" << endl
00140            << "     for ECNA and must contain one line with the following syntax:" << endl << endl
00141            << "        PATH_FOR_THE_RESULTS_ROOT_FILE (without slash at the end of line)" << endl
00142            << "                                        ================================"
00143            << endl << endl
00144            << "     Example: $HOME/scratch0/ecna/results_root" << endl << endl
00145            << " ***************************************************************************************** "
00146            << fTTBELL << endl;
00147 
00148       fFcin_rr.close();
00149       FileHere = kFALSE;
00150     }
00151 
00152   return FileHere;
00153 
00154 } // ----------- (end of GetPathForResultsRootFiles) --------------------
00155 
00156 //================================================================================================
00157 
00158 Bool_t TEcnaParPaths::GetPathForResultsAsciiFiles()
00159 {
00160   return GetPathForResultsAsciiFiles("");
00161 }
00162 
00163 Bool_t TEcnaParPaths::GetPathForResultsAsciiFiles(const TString argFileName)
00164 {
00165   // Init fCfgResultsAsciiFilePath and get it from the file named argFileName
00166   // argFileName = complete name of the file (/afs/cern.ch/...)
00167   // if string is empty, file name = "ECNA/path_results_ascii" (located in $HOME user's directory - default - )
00168 
00169   Bool_t FileHere = kFALSE;
00170 
00171   Int_t MaxCar = fgMaxCar;
00172   fCfgResultsAsciiFilePath.Resize(MaxCar);
00173   fCfgResultsAsciiFilePath = "?";
00174 
00175   //..... put the name of the ascii file (containing the paths for CNA treatements)
00176   //      in the string cFileNameForCnaPaths and in class attribute fFileForResultsAsciiFilePath
00177 
00178   if ( argFileName == "" )
00179     {
00180       string cFileNameForCnaPaths = "ECNA/path_results_ascii";     // config file name
00181       TString s_file_name = cFileNameForCnaPaths.c_str();
00182       const Text_t *t_file_name = (const Text_t *)s_file_name.Data();
00183       
00184       TString s_path_name = gSystem->Getenv("HOME");       // get user's home directory path
00185       
00186       fFileForResultsAsciiFilePath = s_path_name;
00187       fFileForResultsAsciiFilePath.Append('/');
00188       fFileForResultsAsciiFilePath.Append(t_file_name);
00189     }
00190   else
00191     {
00192       fFileForResultsAsciiFilePath = argFileName.Data();
00193     }
00194 
00195   //........ Reading of the paths in the file named fFileForResultsAsciiFilePath.Data()
00196   //
00197   fFcin_ra.open(fFileForResultsAsciiFilePath.Data());
00198   if(fFcin_ra.fail() == kFALSE)
00199     {
00200       fFcin_ra.clear();
00201       string xResultsFileP;
00202       fFcin_ra >> xResultsFileP;
00203       fCfgResultsAsciiFilePath = xResultsFileP.c_str();
00204       fFcin_ra.close();
00205       FileHere = kTRUE;
00206     }
00207   else
00208     {
00209       fFcin_ra.clear();
00210       fCnaError++;
00211       cout << fTTBELL << endl
00212            << " ***************************************************************************************** " << endl;
00213       cout << "   !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << endl << endl
00214            << "     " << fFileForResultsAsciiFilePath.Data() << ": file not found. " << endl << endl
00215            << "     Please create a subdirectory named ECNA in your HOME directory (if not already done)" << endl
00216            << "     and create a file named path_results_ascii in the subdirectory ECNA." << endl << endl
00217            << "     The file " << fFileForResultsAsciiFilePath.Data() << " is a configuration file" << endl
00218            << "     for ECNA and must contain one line with the following syntax:" << endl << endl
00219            << "        PATH_FOR_THE_RESULTS_ASCII_FILE (without slash at the end of line)" << endl
00220            << "                                         ================================"
00221            << endl << endl
00222            << "     Example: $HOME/scratch0/ecna/results_ascii" << endl << endl
00223            << " ***************************************************************************************** "
00224            << fTTBELL << endl;
00225 
00226       fFcin_ra.close();
00227       FileHere = kFALSE;
00228     }
00229 
00230   return FileHere;
00231 
00232 } // ----------- (end of GetPathForResultsAsciiFiles) --------------------
00233 
00234 //================================================================================================
00235 
00236 Bool_t TEcnaParPaths::GetPathForHistoryRunListFiles()
00237 {
00238   return GetPathForHistoryRunListFiles("");
00239 }
00240 
00241 Bool_t TEcnaParPaths::GetPathForHistoryRunListFiles(const TString argFileName)
00242 {
00243   // Init fCfgHistoryRunListFilePath and get it from the file named argFileName
00244   // argFileName = complete name of the file (/afs/cern.ch/...)
00245   // if string is empty, file name = "ECNA/path_runlist_history_plots" (located in $HOME user's directory - default - )
00246 
00247   Bool_t FileHere = kFALSE;
00248 
00249   Int_t MaxCar = fgMaxCar;
00250   fCfgHistoryRunListFilePath.Resize(MaxCar);
00251   fCfgHistoryRunListFilePath          = "?";
00252 
00253   //..... put the name of the ascii file (containing the paths for CNA treatements)
00254   //      in the string cFileNameForCnaPaths and in class attribute fFileForHistoryRunListFilePath
00255 
00256   if ( argFileName == "" )
00257     {
00258       string cFileNameForCnaPaths = "ECNA/path_runlist_history_plots";     // config file name
00259       TString s_file_name = cFileNameForCnaPaths.c_str();
00260       const Text_t *t_file_name = (const Text_t *)s_file_name.Data();
00261       
00262       TString s_path_name = gSystem->Getenv("HOME");       // get user's home directory path
00263       
00264       fFileForHistoryRunListFilePath = s_path_name;
00265       fFileForHistoryRunListFilePath.Append('/');
00266       fFileForHistoryRunListFilePath.Append(t_file_name);
00267     }
00268   else
00269     {
00270       fFileForHistoryRunListFilePath = argFileName.Data();
00271     }
00272 
00273   //........ Reading of the paths in the file named fFileForHistoryRunListFilePath.Data()
00274   //
00275   fFcin_lor.open(fFileForHistoryRunListFilePath.Data());
00276   if(fFcin_lor.fail() == kFALSE)
00277     {
00278       fFcin_lor.clear();
00279       string xHistoryRunListP;
00280       fFcin_lor >> xHistoryRunListP;
00281       fCfgHistoryRunListFilePath = xHistoryRunListP.c_str();
00282       fFcin_lor.close();
00283       FileHere = kTRUE;
00284     }
00285   else
00286     {
00287       fFcin_lor.clear();
00288       fCnaError++;
00289       cout << fTTBELL << endl
00290            << " ******************************************************************************************************** " << endl;
00291       cout << "   !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << endl << endl
00292            << "     " << fFileForHistoryRunListFilePath.Data() << ": file not found. " << endl << endl
00293            << "     Please create a subdirectory named ECNA in your HOME directory (if not already done)" << endl
00294            << "     and create a file named path_runlist_history_plots in the subdirectory ECNA." << endl << endl
00295            << "     The file " << fFileForHistoryRunListFilePath.Data() << " is a configuration file" << endl
00296            << "     for ECNA and must contain one line with the following syntax:" << endl << endl
00297            << "        PATH_FOR_THE_LIST_OF_RUNS_FOR_HISTORY_PLOTS_FILE (without slash at the end of line)" << endl
00298            << "                                                          ================================"
00299            << endl << endl
00300            << "     Example: $HOME/scratch0/ecna/runlist_history_plots" << endl << endl
00301            << " ******************************************************************************************************** "
00302            << fTTBELL << endl;
00303 
00304       fFcin_lor.close();
00305       FileHere = kFALSE;
00306     }
00307 
00308   return FileHere;
00309 
00310 } // ----------- (end of GetPathForHistoryRunListFiles) --------------------
00311 
00312 //================================================================================================
00313 void TEcnaParPaths::GetCMSSWParameters()
00314 {
00315   // Init fCfgCMSSWBase, fCfgSCRAMArch and fCfgCMSSWSubsystem
00316 
00317   Int_t MaxCar = fgMaxCar;
00318   fCfgCMSSWBase.Resize(MaxCar);
00319   fCfgCMSSWBase = "?";
00320 
00321   fCfgSCRAMArch.Resize(MaxCar);
00322   fCfgSCRAMArch = "?";
00323 
00324   fCfgCMSSWSubsystem.Resize(MaxCar);
00325   fCfgCMSSWSubsystem = "?";
00326 
00327   //------------ CMSSW_BASE
00328 
00329   char* ch_cmssw_base = getenv("CMSSW_BASE");
00330   if( ch_cmssw_base == 0 )
00331     {
00332       cout << "*TEcnaParPaths::GetCMSSWParameters()> CMSSW_BASE not defined."
00333            << " Please, set up the environment (command: eval `scramv1 runtime -csh`)"
00334            << fTTBELL << endl; 
00335     }
00336   else
00337     {
00338       fCfgCMSSWBase = (TString)ch_cmssw_base;
00339     }
00340   
00341   //------------ SCRAM_ARCH
00342 
00343   char* ch_scram_arch = getenv("SCRAM_ARCH");
00344   if( ch_scram_arch == 0 )
00345     {
00346       cout << "*TEcnaParPaths::GetCMSSWParameters()> SCRAM_ARCH not defined."
00347            << " Please, set up the environment (command: eval `scramv1 runtime -csh`)"
00348            << fTTBELL << endl; 
00349     }
00350   else
00351     {
00352       fCfgSCRAMArch = (TString)ch_scram_arch;
00353     }
00354       
00355   //------------ SUBSYSTEM: CalibCalorimetry
00356 
00357   fCfgCMSSWSubsystem = "CalibCalorimetry";
00358 
00359 } // ----------- (end of GetCMSSWParameters) --------------------
00360 
00361 //=======================================================================================
00362 //
00363 //        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 
00364 //
00365 //=======================================================================================
00366 TString TEcnaParPaths::ResultsRootFilePath()   {return fCfgResultsRootFilePath;}
00367 TString TEcnaParPaths::ResultsAsciiFilePath()  {return fCfgResultsAsciiFilePath;}
00368 TString TEcnaParPaths::HistoryRunListFilePath(){return fCfgHistoryRunListFilePath;}
00369 TString TEcnaParPaths::CMSSWBase()             {return fCfgCMSSWBase;}
00370 TString TEcnaParPaths::CMSSWSubsystem()        {return fCfgCMSSWSubsystem;}
00371 TString TEcnaParPaths::SCRAMArch()             {return fCfgSCRAMArch;}
00372 
00373 //.....................................................................................
00374 TString TEcnaParPaths::PathModulesData()
00375 {
00376   // ----- return the path of data subdirectory in package "Modules"
00377   TString ModulesdataPath = "";
00378 
00379   const Text_t *t_cmssw_base = (const Text_t *)CMSSWBase().Data();
00380   ModulesdataPath.Append(t_cmssw_base);
00381   ModulesdataPath.Append('/');               //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/
00382 
00383   TString s_src = "src";
00384   const Text_t *t_src = (const Text_t *)s_src.Data();
00385   ModulesdataPath.Append(t_src);
00386   ModulesdataPath.Append('/');               //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/src
00387       
00388   const Text_t *t_cmssw_subsystem = (const Text_t *)CMSSWSubsystem().Data();
00389   ModulesdataPath.Append(t_cmssw_subsystem);
00390   ModulesdataPath.Append('/');               //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/src/CalibCalorimetry/
00391 
00392   TString s_package_data_path = "EcalCorrelatedNoiseAnalysisModules/data";
00393   const Text_t *t_package_data_path = (const Text_t *)s_package_data_path.Data();
00394   ModulesdataPath.Append(t_package_data_path);
00395   ModulesdataPath.Append('/');
00396   // /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/src/CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/data/
00397 
00398   return ModulesdataPath;
00399 }
00400 //.....................................................................................
00401 TString TEcnaParPaths::PathTestScramArch()
00402 {
00403   // ----- return the path of test/slc... subdirectory in CMSSW_BASE
00404   TString TestslcPath = "";
00405       
00406   const Text_t *t_cmssw_base = (const Text_t *)CMSSWBase().Data();
00407   TestslcPath.Append(t_cmssw_base);
00408   TestslcPath.Append('/');               //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/
00409 
00410   TString s_test = "test";
00411   const Text_t *t_test = (const Text_t *)s_test.Data();
00412   TestslcPath.Append(t_test);
00413   TestslcPath.Append('/');               //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/test
00414       
00415   const Text_t *t_cmssw_arch = (const Text_t *)SCRAMArch().Data();
00416   TestslcPath.Append(t_cmssw_arch);
00417   TestslcPath.Append('/');               //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/test/slc4_ia32_gcc345/
00418 
00419   return TestslcPath;
00420 }
00421 
00422 //=======================================================================================
00423 //
00424 //       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 
00425 //
00426 //=======================================================================================
00427 void  TEcnaParPaths::SetResultsRootFilePath(const TString ImposedPath) {fCfgResultsRootFilePath  = ImposedPath;}
00428 void  TEcnaParPaths::SetResultsAsciiFilePath(const TString ImposedPath){fCfgResultsAsciiFilePath = ImposedPath;}
00429 void  TEcnaParPaths::SetHistoryRunListFilePath(const TString ImposedPath){fCfgHistoryRunListFilePath = ImposedPath;}
00430 
00431 void  TEcnaParPaths::TruncateResultsRootFilePath(const Int_t& n1, const Int_t& nbcar) 
00432 {fCfgResultsRootFilePath.Remove(n1,nbcar);}
00433 
00434 void  TEcnaParPaths::TruncateResultsAsciiFilePath(const Int_t& n1, const Int_t& nbcar) 
00435 {fCfgResultsAsciiFilePath.Remove(n1,nbcar);}
00436 
00437 TString TEcnaParPaths::BeginningOfResultsRootFilePath()
00438 {TString sBegin = "?";
00439  if( fCfgResultsRootFilePath.BeginsWith("$HOME") ){sBegin = "$HOME";}
00440  return sBegin;}
00441 
00442 TString TEcnaParPaths::BeginningOfResultsAsciiFilePath()
00443 {TString sBegin = "?";
00444  if( fCfgResultsAsciiFilePath.BeginsWith("$HOME") ){sBegin = "$HOME";}
00445  return sBegin;}
00446 
00447 void TEcnaParPaths::AppendResultsRootFilePath(const Text_t * t_file_nohome)
00448 {fCfgResultsRootFilePath.Append(t_file_nohome);}
00449 
00450 void TEcnaParPaths::AppendResultsAsciiFilePath(const Text_t * t_file_nohome)
00451 {fCfgResultsAsciiFilePath.Append(t_file_nohome);}