File indexing completed on 2024-04-06 11:57:44
0001
0002
0003
0004
0005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaParPaths.h"
0006 #include <cstdlib>
0007
0008
0009
0010
0011
0012
0013
0014 ClassImp(TEcnaParPaths);
0015
0016
0017
0018 TEcnaParPaths::~TEcnaParPaths() {
0019
0020
0021
0022 }
0023
0024
0025
0026
0027
0028
0029 TEcnaParPaths::TEcnaParPaths() {
0030
0031
0032 Init();
0033 }
0034
0035 TEcnaParPaths::TEcnaParPaths(TEcnaObject *pObjectManager) {
0036
0037
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;
0045
0046 fTTBELL = '\007';
0047
0048
0049 fCnaCommand = (Int_t)0;
0050 fCnaError = (Int_t)0;
0051
0052 }
0053
0054 Bool_t TEcnaParPaths::GetPaths() {
0055
0056 Bool_t FileHere = kFALSE;
0057 Int_t NbFileHere = 0;
0058 if (GetPathForResultsRootFiles() == kTRUE) {
0059 NbFileHere++;
0060 }
0061 if (GetPathForResultsAsciiFiles() == kTRUE) {
0062 NbFileHere++;
0063 }
0064 if (GetPathForHistoryRunListFiles() == kTRUE) {
0065 NbFileHere++;
0066 }
0067
0068 GetCMSSWParameters();
0069
0070 if (NbFileHere == 3) {
0071 FileHere = kTRUE;
0072 }
0073 return FileHere;
0074 }
0075
0076
0077
0078
0079
0080
0081
0082
0083 Bool_t TEcnaParPaths::GetPathForResultsRootFiles() { return GetPathForResultsRootFiles(""); }
0084
0085 Bool_t TEcnaParPaths::GetPathForResultsRootFiles(const TString &argFileName) {
0086
0087
0088
0089
0090 Bool_t FileHere = kFALSE;
0091 Int_t MaxCar = fgMaxCar;
0092 fCfgResultsRootFilePath.Resize(MaxCar);
0093 fCfgResultsRootFilePath = "?";
0094
0095
0096
0097
0098 if (argFileName == "") {
0099 std::string cFileNameForCnaPaths = "ECNA/path_results_root";
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");
0104
0105 fFileForResultsRootFilePath = s_path_name;
0106 fFileForResultsRootFilePath.Append('/');
0107 fFileForResultsRootFilePath.Append(t_file_name);
0108 } else {
0109 fFileForResultsRootFilePath = argFileName.Data();
0110 }
0111
0112
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 }
0155
0156
0157
0158 Bool_t TEcnaParPaths::GetPathForResultsAsciiFiles() { return GetPathForResultsAsciiFiles(""); }
0159
0160 Bool_t TEcnaParPaths::GetPathForResultsAsciiFiles(const TString &argFileName) {
0161
0162
0163
0164
0165 Bool_t FileHere = kFALSE;
0166
0167 Int_t MaxCar = fgMaxCar;
0168 fCfgResultsAsciiFilePath.Resize(MaxCar);
0169 fCfgResultsAsciiFilePath = "?";
0170
0171
0172
0173
0174 if (argFileName == "") {
0175 std::string cFileNameForCnaPaths = "ECNA/path_results_ascii";
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");
0180
0181 fFileForResultsAsciiFilePath = s_path_name;
0182 fFileForResultsAsciiFilePath.Append('/');
0183 fFileForResultsAsciiFilePath.Append(t_file_name);
0184 } else {
0185 fFileForResultsAsciiFilePath = argFileName.Data();
0186 }
0187
0188
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 }
0230
0231
0232
0233 Bool_t TEcnaParPaths::GetPathForHistoryRunListFiles() { return GetPathForHistoryRunListFiles(""); }
0234
0235 Bool_t TEcnaParPaths::GetPathForHistoryRunListFiles(const TString &argFileName) {
0236
0237
0238
0239
0240 Bool_t FileHere = kFALSE;
0241
0242 Int_t MaxCar = fgMaxCar;
0243 fCfgHistoryRunListFilePath.Resize(MaxCar);
0244 fCfgHistoryRunListFilePath = "?";
0245
0246
0247
0248
0249 if (argFileName == "") {
0250 std::string cFileNameForCnaPaths = "ECNA/path_runlist_history_plots";
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");
0255
0256 fFileForHistoryRunListFilePath = s_path_name;
0257 fFileForHistoryRunListFilePath.Append('/');
0258 fFileForHistoryRunListFilePath.Append(t_file_name);
0259 } else {
0260 fFileForHistoryRunListFilePath = argFileName.Data();
0261 }
0262
0263
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 }
0306
0307
0308 void TEcnaParPaths::GetCMSSWParameters() {
0309
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
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
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
0342
0343 fCfgCMSSWSubsystem = "CalibCalorimetry";
0344
0345 }
0346
0347
0348
0349
0350
0351
0352 const TString &TEcnaParPaths::ResultsRootFilePath() const { return fCfgResultsRootFilePath; }
0353 const TString &TEcnaParPaths::ResultsAsciiFilePath() const { return fCfgResultsAsciiFilePath; }
0354 const TString &TEcnaParPaths::HistoryRunListFilePath() const { return fCfgHistoryRunListFilePath; }
0355 const TString &TEcnaParPaths::CMSSWBase() const { return fCfgCMSSWBase; }
0356 const TString &TEcnaParPaths::CMSSWSubsystem() const { return fCfgCMSSWSubsystem; }
0357 const TString &TEcnaParPaths::SCRAMArch() const { return fCfgSCRAMArch; }
0358
0359
0360 TString TEcnaParPaths::PathModulesData() {
0361
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('/');
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('/');
0372
0373 const Text_t *t_cmssw_subsystem = (const Text_t *)CMSSWSubsystem().Data();
0374 ModulesdataPath.Append(t_cmssw_subsystem);
0375 ModulesdataPath.Append('/');
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
0382
0383 return ModulesdataPath;
0384 }
0385
0386 TString TEcnaParPaths::PathTestScramArch() {
0387
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('/');
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('/');
0398
0399 const Text_t *t_cmssw_arch = (const Text_t *)SCRAMArch().Data();
0400 TestslcPath.Append(t_cmssw_arch);
0401 TestslcPath.Append('/');
0402
0403 return TestslcPath;
0404 }
0405
0406
0407
0408
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 }