diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c995d191e..f1edaace7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -87,7 +87,7 @@ Build and Test: - cmake ${CI_PROJECT_DIR} -DTEST=ON -DREST_GARFIELD=OFF -DREST_G4=ON -DRESTLIB_DETECTOR=ON -DRESTLIB_RAW=ON -DRESTLIB_TRACK=ON - make -j2 - - ctest --verbose -O ${CI_PROJECT_DIR}/build/Testing/summary.txt + - ctest --output-on-failure -O ${CI_PROJECT_DIR}/build/Testing/summary.txt artifacts: name: "Testing" diff --git a/cmake/Testing.cmake b/cmake/Testing.cmake index 12a40b7fa..32c756b5d 100644 --- a/cmake/Testing.cmake +++ b/cmake/Testing.cmake @@ -9,13 +9,6 @@ if (TEST) add_compile_definitions(REST_TESTING_ENABLED) endif () -macro(ADD_TEST) - if (TEST) - message(STATUS "Adding tests at ${CMAKE_CURRENT_SOURCE_DIR}") - add_subdirectory(test) - endif () -endmacro() - macro(ADD_LIBRARY_TEST) if (TEST) message(STATUS "Adding tests at ${CMAKE_CURRENT_SOURCE_DIR}") @@ -31,13 +24,9 @@ macro(ADD_LIBRARY_TEST) enable_testing() - add_executable(${TESTING_EXECUTABLE}) - FILE(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test/src/*.cxx) - target_sources( - ${TESTING_EXECUTABLE} PUBLIC - ${SOURCES} - ) + + add_executable(${TESTING_EXECUTABLE} ${SOURCES}) target_link_libraries( ${TESTING_EXECUTABLE} PUBLIC @@ -49,7 +38,9 @@ macro(ADD_LIBRARY_TEST) include(GoogleTest) - gtest_discover_tests(${TESTING_EXECUTABLE}) - + gtest_add_tests( + TARGET ${TESTING_EXECUTABLE} + SOURCES ${SOURCES} + ) endif () endmacro() diff --git a/cmake/thisREST.cmake b/cmake/thisREST.cmake index 83f60c3dc..d96f0539e 100644 --- a/cmake/thisREST.cmake +++ b/cmake/thisREST.cmake @@ -15,7 +15,7 @@ string(REGEX REPLACE "\n$" "" GEANT4_PATH "${GEANT4_PATH}") set(thisGeant4 "${GEANT4_PATH}/bin/geant4.sh") if (${REST_G4} MATCHES "ON") - set(loadG4 "\# if geant4.sh script is found we load the same Geant4 version as used in compilation\n if [[ -f \"${thisGeant4}\" && ${thisGeant4} != /usr/* ]]; then + set(loadG4 "\# if geant4.sh script is found we load the same Geant4 version as used in compilation\n if [[ -f \\\"${thisGeant4}\\\" && ${thisGeant4} != /usr/* ]]; then source ${thisGeant4}\n fi\n") else () set(loadG4 "") diff --git a/pipeline/pandaxiii_MC/Xe136bb0n.rml b/pipeline/pandaxiii_MC/Xe136bb0n.rml index e7ec239a9..01abdab55 100644 --- a/pipeline/pandaxiii_MC/Xe136bb0n.rml +++ b/pipeline/pandaxiii_MC/Xe136bb0n.rml @@ -22,9 +22,9 @@ - - - + + + diff --git a/pipeline/pandaxiii_MC/geometry/Th232_SS_01.rml b/pipeline/pandaxiii_MC/geometry/Th232_SS_01.rml index c1deb8f5d..280c38e7f 100644 --- a/pipeline/pandaxiii_MC/geometry/Th232_SS_01.rml +++ b/pipeline/pandaxiii_MC/geometry/Th232_SS_01.rml @@ -26,8 +26,8 @@ - - + + diff --git a/source/framework/core/inc/TRestGDMLParser.h b/source/framework/core/inc/TRestGDMLParser.h index a09e8018e..ae7736ab0 100644 --- a/source/framework/core/inc/TRestGDMLParser.h +++ b/source/framework/core/inc/TRestGDMLParser.h @@ -7,49 +7,51 @@ #include "TRestMetadata.h" -/////////////////////////////////////////// // we must preprocess gdml file because of a bug in TGDMLParse::Value() in ROOT6 -// class TRestGDMLParser : public TRestMetadata { private: - TGeoManager* fGeo; + TGeoManager* fGeoManager{}; public: - TRestGDMLParser() {} - ~TRestGDMLParser() {} - std::string filestr = ""; - std::string path = ""; - std::string outPath = REST_USER_PATH + "/gdml/"; - std::string outfilename = ""; - std::string gdmlVersion = "0.0"; - std::map entityVersion; + TRestGDMLParser() = default; + ~TRestGDMLParser() = default; - std::string GetEntityVersion(std::string name); + std::string fFileString = ""; + std::string fPath = ""; + std::string fOutputGdmlDirectory = REST_USER_PATH.empty() ? "/tmp/gdml/" : REST_USER_PATH + "/gdml/"; + std::string fOutputGdmlFilename = ""; + std::string fGdmlVersion = "0.0"; + std::map fEntityVersionMap{}; - std::string GetGDMLVersion(); + std::string GetEntityVersion(const std::string& name) const; - std::string GetOutputGDMLFile(); + inline std::string GetGDMLVersion() const { return fGdmlVersion; } - void Load(std::string file); + inline std::string GetOutputGDMLFile() const { return fOutputGdmlFilename; } - TGeoManager* GetGeoManager(std::string gdmlFile) { - Load(gdmlFile); - fGeo = TGeoManager::Import(GetOutputGDMLFile().c_str()); - return fGeo; + void Load(const std::string& filename); + + inline TGeoManager* GetGeoManager(const std::string& gdmlFilename) { + Load(gdmlFilename); + fGeoManager = TGeoManager::Import(GetOutputGDMLFile().c_str()); + return fGeoManager; } - TGeoManager* CreateGeoM(); + TGeoManager* CreateGeoManager(); + [[deprecated("Use CreateGeoManager() instead.")]] inline TGeoManager* CreateGeoM() { + return CreateGeoManager(); + } - void InitFromConfigFile() {} + void InitFromConfigFile() override {} void PrintContent(); void ReplaceEntity(); - void ReplaceAttributeWithKeyWord(std::string keyword); + void ReplaceAttributeWithKeyWord(const std::string& keyword); - ClassDef(TRestGDMLParser, 1); + ClassDefOverride(TRestGDMLParser, 2); }; #endif diff --git a/source/framework/core/src/TRestGDMLParser.cxx b/source/framework/core/src/TRestGDMLParser.cxx index ef35686f4..2aab431df 100644 --- a/source/framework/core/src/TRestGDMLParser.cxx +++ b/source/framework/core/src/TRestGDMLParser.cxx @@ -1,57 +1,54 @@ #include "TRestGDMLParser.h" +#include + using namespace std; -string TRestGDMLParser::GetEntityVersion(string name) { - for (auto& i : entityVersion) { - if (i.first == name) { - return i.second; - break; +string TRestGDMLParser::GetEntityVersion(const string& name) const { + for (auto& [entityName, entityVersion] : fEntityVersionMap) { + if (entityName == name) { + return entityVersion; } } return "0.0"; } -string TRestGDMLParser::GetGDMLVersion() { return gdmlVersion; } - -string TRestGDMLParser::GetOutputGDMLFile() { return outfilename; } +void TRestGDMLParser::Load(const string& filename) { + const auto filenameAbsolute = TRestTools::ToAbsoluteName(filename); + if (TRestTools::fileExists(filenameAbsolute)) { + fConfigFileName = filenameAbsolute; + fPath = TRestTools::SeparatePathAndName(filenameAbsolute).first; -void TRestGDMLParser::Load(string file) { - file = TRestTools::ToAbsoluteName(file); - if (TRestTools::fileExists(file)) { - fConfigFileName = file; - path = TRestTools::SeparatePathAndName(file).first; - - std::ifstream t(file); + std::ifstream t(filenameAbsolute); std::string str((std::istreambuf_iterator(t)), std::istreambuf_iterator()); - filestr = str; + fFileString = str; t.close(); - int pp = filestr.find("##VERSION", 0); + int pp = fFileString.find("##VERSION", 0); if (pp != string::npos) { - int pp2 = filestr.find("##", pp + 4); - if (pp2 != string::npos) gdmlVersion = filestr.substr(pp + 9, pp2 - pp - 9); - gdmlVersion = ReplaceMathematicalExpressions(ReplaceConstants(ReplaceVariables(gdmlVersion))); + int pp2 = fFileString.find("##", pp + 4); + if (pp2 != string::npos) fGdmlVersion = fFileString.substr(pp + 9, pp2 - pp - 9); + fGdmlVersion = ReplaceMathematicalExpressions(ReplaceConstants(ReplaceVariables(fGdmlVersion))); } - filestr = ReplaceConstants(ReplaceVariables(filestr)); + fFileString = ReplaceConstants(ReplaceVariables(fFileString)); - cout << "GDML: initializating variables" << endl; - int pos = filestr.find("Import(outfilename.c_str()); + chdir(fOutputGdmlDirectory.c_str()); + auto geoManager = new TGeoManager(); + geoManager->Import(fOutputGdmlFilename.c_str()); chdir(originDirectory); - return geo2; + return geoManager; } return nullptr; } -void TRestGDMLParser::PrintContent() { cout << filestr << endl; } +void TRestGDMLParser::PrintContent() { cout << fFileString << endl; } void TRestGDMLParser::ReplaceEntity() { int pos = 0; - while ((pos = filestr.find("(t)), std::istreambuf_iterator()); - t.close(); + if ((pos5 = fFileString.find("&" + entityName + ";")) != -1) { + if (TRestTools::fileExists(entityFile)) { + std::ifstream entityFileRead(entityFile); + std::string str((std::istreambuf_iterator(entityFileRead)), + std::istreambuf_iterator()); + entityFileRead.close(); str = ReplaceConstants(ReplaceVariables(str)); - entityVersion[entityname] = ""; + fEntityVersionMap[entityName] = ""; int pp = str.find("##VERSION", 0); if (pp != string::npos) { int pp2 = str.find("##", pp + 4); if (pp2 != string::npos) { - entityVersion[entityname] = str.substr(pp + 9, pp2 - pp - 9); + fEntityVersionMap[entityName] = str.substr(pp + 9, pp2 - pp - 9); } } - // cout << "replacing entity..." << endl; - filestr.replace(pos5, entityname.length() + 2, str); + fFileString.replace(pos5, entityName.length() + 2, str); } else { - cout << "GDML ERROR! No matching reference file for entity: \"" << entityname << "\"" << endl; - cout << "file name: \"" << entityfile << "\"" << endl; - exit(0); + cout << "GDML ERROR! No matching reference file for entity: \"" << entityName << "\"" << endl; + cout << "file name: \"" << entityFile << "\"" << endl; + exit(1); } } else { - cout << "GDML: Warning! redundant entity: \"" << entityname << "\"" << endl; + cout << "TRestGDMLParser: Warning! redundant entity: \"" << entityName << "\"" << endl; } pos++; } } -void TRestGDMLParser::ReplaceAttributeWithKeyWord(string keyword) { +void TRestGDMLParser::ReplaceAttributeWithKeyWord(const string& keyword) { int n; - while ((n = filestr.find(keyword, 0)) != -1) { + while ((n = fFileString.find(keyword, 0)) != -1) { int pos1 = 0, pos2 = 0; for (int i = n; i >= 0; i--) { - if (filestr[i] == '"') { + if (fFileString[i] == '"') { pos1 = i + 1; break; } } - for (unsigned int i = n; i < filestr.size(); i++) { - if (filestr[i] == '"') { + for (unsigned int i = n; i < fFileString.size(); i++) { + if (fFileString[i] == '"') { pos2 = i; break; } } - string target = filestr.substr(pos1, pos2 - pos1); - // cout << target << endl; + string target = fFileString.substr(pos1, pos2 - pos1); string replace = ReplaceMathematicalExpressions(ReplaceConstants(ReplaceVariables(target))); - // cout << replace << endl; - // cout << target << " " << ReplaceConstants(ReplaceVariables(target) << " " - // << replace << endl; if (replace == target) { - cout << "Error! failed to replace mathematical expressions! check the " - "file!" - << endl; + cout << "Error! failed to replace mathematical expressions! check the file!" << endl; cout << replace << endl; - exit(0); + exit(1); } - filestr.replace(pos1, pos2 - pos1, replace); + fFileString.replace(pos1, pos2 - pos1, replace); } } diff --git a/source/framework/core/src/TRestMetadata.cxx b/source/framework/core/src/TRestMetadata.cxx index 95163f482..9a82722c9 100644 --- a/source/framework/core/src/TRestMetadata.cxx +++ b/source/framework/core/src/TRestMetadata.cxx @@ -113,18 +113,18 @@ /// If no arguments are provided, LoadConfigFromFile() will only call the Initialize() /// method. If given the rml file name, it will find out the needed rml sections. We /// can also directly give the xml sections to the method. Two xml sections are used -/// to startup the class: the section for the class and a global section. Additionaly +/// to startup the class: the section for the class and a global section. Additionally /// we can give a map object to the method to import additional variables. /// /// The "section for the class" is an xml section with the value of class name. -/// It is the main information souce for the class's startup. The "global" +/// It is the main information source for the class's startup. The "global" /// section is a special xml section in the rml file, containing global information /// which could be seen by all the class sections. /// /// With the xml sections given, LoadConfigFromFile() first merge them together. Then it /// calls LoadSectionMetadata(), which loads some universal parameters like /// name, title and verbose level. This method also preprocesses the config -/// sections, expanding the include/for decinition and replacing the variables. +/// sections, expanding the include/for definition and replacing the variables. /// After this, LoadConfigFromFile() calls the method InitFromConfigFile(). /// /// **InitFromConfigFile()** is a pure virtual method and every child classes have @@ -515,8 +515,8 @@ TRestMetadata::TRestMetadata(const char* cfgFileName) : endl(this) { /// \brief TRestMetadata default destructor /// TRestMetadata::~TRestMetadata() { - if (fElementGlobal) delete fElementGlobal; - if (fElement) delete fElement; + delete fElementGlobal; + delete fElement; } /////////////////////////////////////////////// @@ -564,7 +564,7 @@ Int_t TRestMetadata::LoadConfigFromFile(string cfgFileName, string sectionName) delete rootEle; return result; } else { - ferr << "Filename : " << fConfigFileName << endl; + ferr << "Filename: " << fConfigFileName << endl; ferr << "Config File does not exist. Right path/filename?" << endl; GetChar(); return -1; @@ -628,7 +628,7 @@ Int_t TRestMetadata::LoadConfigFromBuffer() { /////////////////////////////////////////////// /// \brief This method does some preparation of xml section. /// -/// Preparation includes: seting the name, title and verbose level of the +/// Preparation includes: setting the name, title and verbose level of the /// current class. Finding out and saving the env sections. /// /// By calling TRestMetadata::ReadElement(), is also expands for loops and @@ -1271,7 +1271,7 @@ void TRestMetadata::ExpandIncludeFile(TiXmlElement* e) { /// If still not found, it returns the default value. /// /// \param parName The name of the parameter from which we want to obtain the -/// value. \param defaultValue The default value if the paremeter is not found +/// value. \param defaultValue The default value if the parameter is not found /// /// \return A string of result string TRestMetadata::GetParameter(std::string parName, TString defaultValue) { @@ -1309,7 +1309,7 @@ string TRestMetadata::GetParameter(std::string parName, TString defaultValue) { /// /// \param parName The name of the parameter from which we want to obtain the /// value. \param e The target eml element where the program is to search the -/// parameter \param defaultValue The default value if the paremeter is not +/// parameter \param defaultValue The default value if the parameter is not /// found /// /// \return A string of result, with env and expressions replaced diff --git a/source/framework/test/src/FrameworkCore.cxx b/source/framework/test/src/FrameworkCore.cxx index 960663bba..dbce168e3 100644 --- a/source/framework/test/src/FrameworkCore.cxx +++ b/source/framework/test/src/FrameworkCore.cxx @@ -9,26 +9,26 @@ namespace fs = std::filesystem; using namespace std; -#define FILES_PATH fs::path(__FILE__).parent_path().parent_path() / "files" -#define BASIC_TRESTRUN_RML FILES_PATH / "TRestRunBasic.rml" -#define BASIC_TRESTMETADATA_RML FILES_PATH / "TRestMetadataTest.rml" +const auto filesPath = fs::path(__FILE__).parent_path().parent_path() / "files"; +const auto basicRunRml = filesPath / "TRestRunBasic.rml"; +const auto basicMetadataRml = filesPath / "TRestMetadataTest.rml"; TEST(FrameworkCore, TestFiles) { - cout << "FrameworkCore test files path: " << FILES_PATH << endl; + cout << "FrameworkCore test files path: " << filesPath << endl; // Check dir exists and is a directory - EXPECT_TRUE(fs::is_directory(FILES_PATH)); + EXPECT_TRUE(fs::is_directory(filesPath)); // Check it's not empty - EXPECT_TRUE(!fs::is_empty(FILES_PATH)); + EXPECT_TRUE(!fs::is_empty(filesPath)); // Check required files exist - EXPECT_TRUE(fs::exists(BASIC_TRESTRUN_RML)); - EXPECT_TRUE(fs::exists(BASIC_TRESTMETADATA_RML)); + EXPECT_TRUE(fs::exists(basicRunRml)); + EXPECT_TRUE(fs::exists(basicMetadataRml)); } TEST(FrameworkCore, TRestRun) { TRestRun run; - run.LoadConfigFromFile(BASIC_TRESTRUN_RML); + run.LoadConfigFromFile(basicRunRml); run.PrintAllMetadata(); @@ -50,7 +50,7 @@ TEST(FrameworkCore, TRestMetadata) { }; TRestMetadataTest restMetadataTest; - restMetadataTest.LoadConfigFromFile(BASIC_TRESTMETADATA_RML, "TRestMetadataTest"); + restMetadataTest.LoadConfigFromFile(basicMetadataRml, "TRestMetadataTest"); restMetadataTest.PrintMetadata(); diff --git a/source/framework/tools/src/TRestStringHelper.cxx b/source/framework/tools/src/TRestStringHelper.cxx index b8ea5b19a..cc973e90a 100644 --- a/source/framework/tools/src/TRestStringHelper.cxx +++ b/source/framework/tools/src/TRestStringHelper.cxx @@ -486,7 +486,7 @@ Float_t REST_StringHelper::StringToFloat(string in) { /// \brief Gets an integer from a string. /// Int_t REST_StringHelper::StringToInteger(string in) { - // If we find an hexadecimal number + // If we find a hexadecimal number if (in.find("0x") != std::string::npos) return (Int_t)std::stoul(in, nullptr, 16); return (Int_t)StringToDouble(in);