Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:41

0001 //----------Author's Name: B.Fabbro DSM/IRFU/SPP CEA-Saclay
0002 //----------Copyright: Those valid for CEA sofware
0003 //----------Modified: 30/01/2014
0004 
0005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaParPaths.h"
0006 #include <cstdlib>
0007 
0008 //--------------------------------------
0009 //  TEcnaParPaths.cc
0010 //  Class creation: 19 May 2005
0011 //  Documentation: see TEcnaParPaths.h
0012 //--------------------------------------
0013 
0014 ClassImp(TEcnaParPaths);
0015 //______________________________________________________________________________
0016 //
0017 
0018 TEcnaParPaths::~TEcnaParPaths() {
0019   //destructor
0020 
0021   // std::cout << "[Info Management] CLASS: TEcnaParPaths.      DESTROY OBJECT: this = " << this << std::endl;
0022 }
0023 
0024 //===================================================================
0025 //
0026 //                   Constructors
0027 //
0028 //===================================================================
0029 TEcnaParPaths::TEcnaParPaths() {
0030   // Constructor without argument
0031   // std::cout << "[Info Management] CLASS: TEcnaParPaths.      CREATE OBJECT: this = " << this << std::endl;
0032   Init();
0033 }
0034 
0035 TEcnaParPaths::TEcnaParPaths(TEcnaObject *pObjectManager) {
0036   // Constructor without argument
0037   // std::cout << "[Info Management] CLASS: TEcnaParPaths.      CREATE OBJECT: this = " << this << std::endl;
0038   Init();
0039   Long_t i_this = (Long_t)this;
0040   pObjectManager->RegisterPointer("TEcnaParPaths", i_this);
0041 }
0042 
0043 void TEcnaParPaths::Init() {
0044   fgMaxCar = (Int_t)512;  // max number of characters in TStrings
0045 
0046   fTTBELL = '\007';
0047 
0048   //................ Init CNA Command and error numbering
0049   fCnaCommand = (Int_t)0;
0050   fCnaError = (Int_t)0;
0051 
0052 }  // end of Init()
0053 
0054 Bool_t TEcnaParPaths::GetPaths() {
0055   //............................... Get user's parameters from user's directory
0056   Bool_t FileHere = kFALSE;
0057   Int_t NbFileHere = 0;
0058   if (GetPathForResultsRootFiles() == kTRUE) {
0059     NbFileHere++;
0060   }  //  Init fCfgResultsRootFilePath
0061   if (GetPathForResultsAsciiFiles() == kTRUE) {
0062     NbFileHere++;
0063   }  //  Init fCfgResultsAsciiFilePath
0064   if (GetPathForHistoryRunListFiles() == kTRUE) {
0065     NbFileHere++;
0066   }  //  Init fCfgHistoryRunListFilePath
0067 
0068   GetCMSSWParameters();  //  Init fCfgCMSSWBase, fCfgCMSSWSubsystem, fCfgSCRAMArch <== done in TEcnaGui
0069 
0070   if (NbFileHere == 3) {
0071     FileHere = kTRUE;
0072   }
0073   return FileHere;
0074 }
0075 
0076 //=======================================================================================
0077 //
0078 //     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
0079 //
0080 //     F R O M    T H E    U S E R ' S    D I R E C T O R Y
0081 //
0082 //=======================================================================================
0083 Bool_t TEcnaParPaths::GetPathForResultsRootFiles() { return GetPathForResultsRootFiles(""); }
0084 
0085 Bool_t TEcnaParPaths::GetPathForResultsRootFiles(const TString &argFileName) {
0086   // Init fCfgResultsRootFilePath and get it from the file named argFileName
0087   // argFileName = complete name of the file (/afs/cern.ch/...)
0088   // if string is empty, file name = "ECNA/path_results_root" (located in $HOME user's directory - default - )
0089 
0090   Bool_t FileHere = kFALSE;
0091   Int_t MaxCar = fgMaxCar;
0092   fCfgResultsRootFilePath.Resize(MaxCar);
0093   fCfgResultsRootFilePath = "?";
0094 
0095   //..... put the name of the ascii file (containing the paths for CNA treatements)
0096   //      in the string cFileNameForCnaPaths and in class attribute fFileForResultsRootFilePath
0097 
0098   if (argFileName == "") {
0099     std::string cFileNameForCnaPaths = "ECNA/path_results_root";  // config file name
0100     TString s_file_name = cFileNameForCnaPaths.c_str();
0101     const Text_t *t_file_name = (const Text_t *)s_file_name.Data();
0102 
0103     TString s_path_name = gSystem->Getenv("HOME");  // get user's home directory path
0104 
0105     fFileForResultsRootFilePath = s_path_name;
0106     fFileForResultsRootFilePath.Append('/');
0107     fFileForResultsRootFilePath.Append(t_file_name);
0108   } else {
0109     fFileForResultsRootFilePath = argFileName.Data();
0110   }
0111 
0112   //........ Reading of the paths in the file named fFileForResultsRootFilePath.Data()
0113   //
0114   fFcin_rr.open(fFileForResultsRootFilePath.Data());
0115 
0116   if (fFcin_rr.fail() == kFALSE) {
0117     fFcin_rr.clear();
0118     std::string xResultsFileP;
0119     fFcin_rr >> xResultsFileP;
0120     fCfgResultsRootFilePath = xResultsFileP.c_str();
0121     fFcin_rr.close();
0122     FileHere = kTRUE;
0123   } else {
0124     fFcin_rr.clear();
0125     fCnaError++;
0126     std::cout << fTTBELL << std::endl
0127               << " ***************************************************************************************** "
0128               << std::endl;
0129     std::cout << "   !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << std::endl
0130               << std::endl
0131               << "     " << fFileForResultsRootFilePath.Data() << ": file not found. " << std::endl
0132               << std::endl
0133               << "     Please create a subdirectory named ECNA in your HOME directory (if not already done)"
0134               << std::endl
0135               << "     and create a file named path_results_root in the subdirectory ECNA." << std::endl
0136               << std::endl
0137               << "     The file " << fFileForResultsRootFilePath.Data() << " is a configuration file" << std::endl
0138               << "     for ECNA and must contain one line with the following syntax:" << std::endl
0139               << std::endl
0140               << "        PATH_FOR_THE_RESULTS_ROOT_FILE (without slash at the end of line)" << std::endl
0141               << "                                        ================================" << std::endl
0142               << std::endl
0143               << "     Example: $HOME/scratch0/ecna/results_root" << std::endl
0144               << std::endl
0145               << " ***************************************************************************************** "
0146               << fTTBELL << std::endl;
0147 
0148     fFcin_rr.close();
0149     FileHere = kFALSE;
0150   }
0151 
0152   return FileHere;
0153 
0154 }  // ----------- (end of GetPathForResultsRootFiles) --------------------
0155 
0156 //================================================================================================
0157 
0158 Bool_t TEcnaParPaths::GetPathForResultsAsciiFiles() { return GetPathForResultsAsciiFiles(""); }
0159 
0160 Bool_t TEcnaParPaths::GetPathForResultsAsciiFiles(const TString &argFileName) {
0161   // Init fCfgResultsAsciiFilePath and get it from the file named argFileName
0162   // argFileName = complete name of the file (/afs/cern.ch/...)
0163   // if string is empty, file name = "ECNA/path_results_ascii" (located in $HOME user's directory - default - )
0164 
0165   Bool_t FileHere = kFALSE;
0166 
0167   Int_t MaxCar = fgMaxCar;
0168   fCfgResultsAsciiFilePath.Resize(MaxCar);
0169   fCfgResultsAsciiFilePath = "?";
0170 
0171   //..... put the name of the ascii file (containing the paths for CNA treatements)
0172   //      in the string cFileNameForCnaPaths and in class attribute fFileForResultsAsciiFilePath
0173 
0174   if (argFileName == "") {
0175     std::string cFileNameForCnaPaths = "ECNA/path_results_ascii";  // config file name
0176     TString s_file_name = cFileNameForCnaPaths.c_str();
0177     const Text_t *t_file_name = (const Text_t *)s_file_name.Data();
0178 
0179     TString s_path_name = gSystem->Getenv("HOME");  // get user's home directory path
0180 
0181     fFileForResultsAsciiFilePath = s_path_name;
0182     fFileForResultsAsciiFilePath.Append('/');
0183     fFileForResultsAsciiFilePath.Append(t_file_name);
0184   } else {
0185     fFileForResultsAsciiFilePath = argFileName.Data();
0186   }
0187 
0188   //........ Reading of the paths in the file named fFileForResultsAsciiFilePath.Data()
0189   //
0190   fFcin_ra.open(fFileForResultsAsciiFilePath.Data());
0191   if (fFcin_ra.fail() == kFALSE) {
0192     fFcin_ra.clear();
0193     std::string xResultsFileP;
0194     fFcin_ra >> xResultsFileP;
0195     fCfgResultsAsciiFilePath = xResultsFileP.c_str();
0196     fFcin_ra.close();
0197     FileHere = kTRUE;
0198   } else {
0199     fFcin_ra.clear();
0200     fCnaError++;
0201     std::cout << fTTBELL << std::endl
0202               << " ***************************************************************************************** "
0203               << std::endl;
0204     std::cout << "   !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << std::endl
0205               << std::endl
0206               << "     " << fFileForResultsAsciiFilePath.Data() << ": file not found. " << std::endl
0207               << std::endl
0208               << "     Please create a subdirectory named ECNA in your HOME directory (if not already done)"
0209               << std::endl
0210               << "     and create a file named path_results_ascii in the subdirectory ECNA." << std::endl
0211               << std::endl
0212               << "     The file " << fFileForResultsAsciiFilePath.Data() << " is a configuration file" << std::endl
0213               << "     for ECNA and must contain one line with the following syntax:" << std::endl
0214               << std::endl
0215               << "        PATH_FOR_THE_RESULTS_ASCII_FILE (without slash at the end of line)" << std::endl
0216               << "                                         ================================" << std::endl
0217               << std::endl
0218               << "     Example: $HOME/scratch0/ecna/results_ascii" << std::endl
0219               << std::endl
0220               << " ***************************************************************************************** "
0221               << fTTBELL << std::endl;
0222 
0223     fFcin_ra.close();
0224     FileHere = kFALSE;
0225   }
0226 
0227   return FileHere;
0228 
0229 }  // ----------- (end of GetPathForResultsAsciiFiles) --------------------
0230 
0231 //================================================================================================
0232 
0233 Bool_t TEcnaParPaths::GetPathForHistoryRunListFiles() { return GetPathForHistoryRunListFiles(""); }
0234 
0235 Bool_t TEcnaParPaths::GetPathForHistoryRunListFiles(const TString &argFileName) {
0236   // Init fCfgHistoryRunListFilePath and get it from the file named argFileName
0237   // argFileName = complete name of the file (/afs/cern.ch/...)
0238   // if string is empty, file name = "ECNA/path_runlist_history_plots" (located in $HOME user's directory - default - )
0239 
0240   Bool_t FileHere = kFALSE;
0241 
0242   Int_t MaxCar = fgMaxCar;
0243   fCfgHistoryRunListFilePath.Resize(MaxCar);
0244   fCfgHistoryRunListFilePath = "?";
0245 
0246   //..... put the name of the ascii file (containing the paths for CNA treatements)
0247   //      in the string cFileNameForCnaPaths and in class attribute fFileForHistoryRunListFilePath
0248 
0249   if (argFileName == "") {
0250     std::string cFileNameForCnaPaths = "ECNA/path_runlist_history_plots";  // config file name
0251     TString s_file_name = cFileNameForCnaPaths.c_str();
0252     const Text_t *t_file_name = (const Text_t *)s_file_name.Data();
0253 
0254     TString s_path_name = gSystem->Getenv("HOME");  // get user's home directory path
0255 
0256     fFileForHistoryRunListFilePath = s_path_name;
0257     fFileForHistoryRunListFilePath.Append('/');
0258     fFileForHistoryRunListFilePath.Append(t_file_name);
0259   } else {
0260     fFileForHistoryRunListFilePath = argFileName.Data();
0261   }
0262 
0263   //........ Reading of the paths in the file named fFileForHistoryRunListFilePath.Data()
0264   //
0265   fFcin_lor.open(fFileForHistoryRunListFilePath.Data());
0266   if (fFcin_lor.fail() == kFALSE) {
0267     fFcin_lor.clear();
0268     std::string xHistoryRunListP;
0269     fFcin_lor >> xHistoryRunListP;
0270     fCfgHistoryRunListFilePath = xHistoryRunListP.c_str();
0271     fFcin_lor.close();
0272     FileHere = kTRUE;
0273   } else {
0274     fFcin_lor.clear();
0275     fCnaError++;
0276     std::cout
0277         << fTTBELL << std::endl
0278         << " ******************************************************************************************************** "
0279         << std::endl;
0280     std::cout
0281         << "   !CNA(TEcnaParPaths) (" << fCnaError << ") *** ERROR *** " << std::endl
0282         << std::endl
0283         << "     " << fFileForHistoryRunListFilePath.Data() << ": file not found. " << std::endl
0284         << std::endl
0285         << "     Please create a subdirectory named ECNA in your HOME directory (if not already done)" << std::endl
0286         << "     and create a file named path_runlist_history_plots in the subdirectory ECNA." << std::endl
0287         << std::endl
0288         << "     The file " << fFileForHistoryRunListFilePath.Data() << " is a configuration file" << std::endl
0289         << "     for ECNA and must contain one line with the following syntax:" << std::endl
0290         << std::endl
0291         << "        PATH_FOR_THE_LIST_OF_RUNS_FOR_HISTORY_PLOTS_FILE (without slash at the end of line)" << std::endl
0292         << "                                                          ================================" << std::endl
0293         << std::endl
0294         << "     Example: $HOME/scratch0/ecna/runlist_history_plots" << std::endl
0295         << std::endl
0296         << " ******************************************************************************************************** "
0297         << fTTBELL << std::endl;
0298 
0299     fFcin_lor.close();
0300     FileHere = kFALSE;
0301   }
0302 
0303   return FileHere;
0304 
0305 }  // ----------- (end of GetPathForHistoryRunListFiles) --------------------
0306 
0307 //================================================================================================
0308 void TEcnaParPaths::GetCMSSWParameters() {
0309   // Init fCfgCMSSWBase, fCfgSCRAMArch and fCfgCMSSWSubsystem
0310 
0311   Int_t MaxCar = fgMaxCar;
0312   fCfgCMSSWBase.Resize(MaxCar);
0313   fCfgCMSSWBase = "?";
0314 
0315   fCfgSCRAMArch.Resize(MaxCar);
0316   fCfgSCRAMArch = "?";
0317 
0318   fCfgCMSSWSubsystem.Resize(MaxCar);
0319   fCfgCMSSWSubsystem = "?";
0320 
0321   //------------ CMSSW_BASE
0322 
0323   char *ch_cmssw_base = std::getenv("CMSSW_BASE");
0324   if (ch_cmssw_base == nullptr) {
0325     std::cout << "*TEcnaParPaths::GetCMSSWParameters()> CMSSW_BASE not defined."
0326               << " Please, set up the environment (command: eval `scramv1 runtime -csh`)" << fTTBELL << std::endl;
0327   } else {
0328     fCfgCMSSWBase = (TString)ch_cmssw_base;
0329   }
0330 
0331   //------------ SCRAM_ARCH
0332 
0333   char *ch_scram_arch = std::getenv("SCRAM_ARCH");
0334   if (ch_scram_arch == nullptr) {
0335     std::cout << "*TEcnaParPaths::GetCMSSWParameters()> SCRAM_ARCH not defined."
0336               << " Please, set up the environment (command: eval `scramv1 runtime -csh`)" << fTTBELL << std::endl;
0337   } else {
0338     fCfgSCRAMArch = (TString)ch_scram_arch;
0339   }
0340 
0341   //------------ SUBSYSTEM: CalibCalorimetry
0342 
0343   fCfgCMSSWSubsystem = "CalibCalorimetry";
0344 
0345 }  // ----------- (end of GetCMSSWParameters) --------------------
0346 
0347 //=======================================================================================
0348 //
0349 //        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
0350 //
0351 //=======================================================================================
0352 TString TEcnaParPaths::ResultsRootFilePath() { return fCfgResultsRootFilePath; }
0353 TString TEcnaParPaths::ResultsAsciiFilePath() { return fCfgResultsAsciiFilePath; }
0354 TString TEcnaParPaths::HistoryRunListFilePath() { return fCfgHistoryRunListFilePath; }
0355 TString TEcnaParPaths::CMSSWBase() { return fCfgCMSSWBase; }
0356 TString TEcnaParPaths::CMSSWSubsystem() { return fCfgCMSSWSubsystem; }
0357 TString TEcnaParPaths::SCRAMArch() { return fCfgSCRAMArch; }
0358 
0359 //.....................................................................................
0360 TString TEcnaParPaths::PathModulesData() {
0361   // ----- return the path of data subdirectory in package "Modules"
0362   TString ModulesdataPath = "";
0363 
0364   const Text_t *t_cmssw_base = (const Text_t *)CMSSWBase().Data();
0365   ModulesdataPath.Append(t_cmssw_base);
0366   ModulesdataPath.Append('/');  //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/
0367 
0368   TString s_src = "src";
0369   const Text_t *t_src = (const Text_t *)s_src.Data();
0370   ModulesdataPath.Append(t_src);
0371   ModulesdataPath.Append('/');  //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/src
0372 
0373   const Text_t *t_cmssw_subsystem = (const Text_t *)CMSSWSubsystem().Data();
0374   ModulesdataPath.Append(t_cmssw_subsystem);
0375   ModulesdataPath.Append('/');  //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/src/CalibCalorimetry/
0376 
0377   TString s_package_data_path = "EcalCorrelatedNoiseAnalysisModules/data";
0378   const Text_t *t_package_data_path = (const Text_t *)s_package_data_path.Data();
0379   ModulesdataPath.Append(t_package_data_path);
0380   ModulesdataPath.Append('/');
0381   // /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/src/CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/data/
0382 
0383   return ModulesdataPath;
0384 }
0385 //.....................................................................................
0386 TString TEcnaParPaths::PathTestScramArch() {
0387   // ----- return the path of test/slc... subdirectory in CMSSW_BASE
0388   TString TestslcPath = "";
0389 
0390   const Text_t *t_cmssw_base = (const Text_t *)CMSSWBase().Data();
0391   TestslcPath.Append(t_cmssw_base);
0392   TestslcPath.Append('/');  //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/
0393 
0394   TString s_test = "test";
0395   const Text_t *t_test = (const Text_t *)s_test.Data();
0396   TestslcPath.Append(t_test);
0397   TestslcPath.Append('/');  //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/test
0398 
0399   const Text_t *t_cmssw_arch = (const Text_t *)SCRAMArch().Data();
0400   TestslcPath.Append(t_cmssw_arch);
0401   TestslcPath.Append('/');  //  /afs/cern.ch/user/U/USERNAME/cmssw/CMSSW_X_Y_Z/test/slc4_ia32_gcc345/
0402 
0403   return TestslcPath;
0404 }
0405 
0406 //=======================================================================================
0407 //
0408 //       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
0409 //
0410 //=======================================================================================
0411 void TEcnaParPaths::SetResultsRootFilePath(const TString &ImposedPath) { fCfgResultsRootFilePath = ImposedPath; }
0412 void TEcnaParPaths::SetResultsAsciiFilePath(const TString &ImposedPath) { fCfgResultsAsciiFilePath = ImposedPath; }
0413 void TEcnaParPaths::SetHistoryRunListFilePath(const TString &ImposedPath) { fCfgHistoryRunListFilePath = ImposedPath; }
0414 
0415 void TEcnaParPaths::TruncateResultsRootFilePath(const Int_t &n1, const Int_t &nbcar) {
0416   fCfgResultsRootFilePath.Remove(n1, nbcar);
0417 }
0418 
0419 void TEcnaParPaths::TruncateResultsAsciiFilePath(const Int_t &n1, const Int_t &nbcar) {
0420   fCfgResultsAsciiFilePath.Remove(n1, nbcar);
0421 }
0422 
0423 TString TEcnaParPaths::BeginningOfResultsRootFilePath() {
0424   TString sBegin = "?";
0425   if (fCfgResultsRootFilePath.BeginsWith("$HOME")) {
0426     sBegin = "$HOME";
0427   }
0428   return sBegin;
0429 }
0430 
0431 TString TEcnaParPaths::BeginningOfResultsAsciiFilePath() {
0432   TString sBegin = "?";
0433   if (fCfgResultsAsciiFilePath.BeginsWith("$HOME")) {
0434     sBegin = "$HOME";
0435   }
0436   return sBegin;
0437 }
0438 
0439 void TEcnaParPaths::AppendResultsRootFilePath(const Text_t *t_file_nohome) {
0440   fCfgResultsRootFilePath.Append(t_file_nohome);
0441 }
0442 
0443 void TEcnaParPaths::AppendResultsAsciiFilePath(const Text_t *t_file_nohome) {
0444   fCfgResultsAsciiFilePath.Append(t_file_nohome);
0445 }