diff --git a/sim/transport/generators/CMakeLists.txt b/sim/transport/generators/CMakeLists.txt index 556e0de5d1977668a544324565ae217d5705e84d..14b472370000e9e45757d8da8eaa64e94a3b5f00 100644 --- a/sim/transport/generators/CMakeLists.txt +++ b/sim/transport/generators/CMakeLists.txt @@ -30,6 +30,7 @@ pluto/PValues.cxx # ---- Include directories ------------------------------- set(INCLUDE_DIRECTORIES ${CBMDATA_DIR} +${CBMBASE_DIR}/utils ${CBMROOT_SOURCE_DIR}/sim ${CBMROOT_SOURCE_DIR}/sim/transport ${CBMROOT_SOURCE_DIR}/sim/transport/base diff --git a/sim/transport/generators/CbmPlutoGenerator.cxx b/sim/transport/generators/CbmPlutoGenerator.cxx index 1e3559a46595f02d2b877608078886fe786744b6..1960220a27134fd8b39effcbf560ae80eb080eb9 100644 --- a/sim/transport/generators/CbmPlutoGenerator.cxx +++ b/sim/transport/generators/CbmPlutoGenerator.cxx @@ -4,6 +4,8 @@ // ------------------------------------------------------------------------- #include "CbmPlutoGenerator.h" +#include "CbmFileUtils.h" + #include "FairLogger.h" #include "FairPrimaryGenerator.h" // for FairPrimaryGenerator @@ -49,7 +51,7 @@ CbmPlutoGenerator::CbmPlutoGenerator(const Char_t* fileName) , fPDGmanual(0) { fInputChain = new TChain("data"); - if (CheckFileExist(fileName)) { + if (Cbm::File::IsRootFile(fileName)) { fInputChain->Add(fileName); fInputChain->SetBranchAddress("Particles", &fParticles); LOG(info) << "CbmPlutoGenerator: Add file " << fileName @@ -71,8 +73,8 @@ CbmPlutoGenerator::CbmPlutoGenerator(std::vector<std::string> fileNames) , fParticles(new TClonesArray("PParticle", 100)) , fPDGmanual(0) { fInputChain = new TChain("data"); - for (auto& name : fileNames) { - if (CheckFileExist(name)) { + for (const auto& name : fileNames) { + if (Cbm::File::IsRootFile(name)) { fInputChain->Add(name.c_str()); LOG(info) << "CbmPlutoGenerator: Add file " << name << " to input chain"; } else { @@ -189,65 +191,4 @@ void CbmPlutoGenerator::CloseInput() { } // ------------------------------------------------------------------------ -Bool_t CbmPlutoGenerator::CheckFileExist(std::string filename) { - - // In case the filename contains a hash (e.g. multi.zip#file.root) assume that the hash - // separates the name of a zipfile (multi.zip) which contains the real root file - // (file.root). Split the filename at the # in the name of the zipfile and - // the name of the contained root file. - std::string checkFilename {""}; - std::string membername {""}; - std::size_t found = filename.find("#"); - if (found != std::string::npos) { - checkFilename = filename.substr(0, found); - membername = filename.substr(found + 1); - } else { - checkFilename = filename; - } - - Bool_t wasfound = kFALSE; - - // Check if the file exist - // In case of a root file contained in a zip archive check if the zip file - // exist - struct stat buffer; - if (stat(checkFilename.c_str(), &buffer) == 0) { - wasfound = kTRUE; - } else { - wasfound = kFALSE; - LOG(error) << "Input File " << checkFilename << " not found"; - } - - // In case of a zip archive check if the archive contains the root file - if (membername.compare("") != 0) { - TFile* fzip = TFile::Open(checkFilename.c_str()); - if (fzip->IsOpen()) { - TArchiveFile* archive = fzip->GetArchive(); - if (archive) { - TObjArray* members = archive->GetMembers(); - if (members->FindObject(membername.c_str()) == 0) { - LOG(error) << "File " << membername << " not found in zipfile " - << checkFilename; - wasfound = kFALSE; - } else { - LOG(info) << "File " << membername << " found in zipfile " - << checkFilename; - wasfound = kTRUE; - } - } else { - LOG(error) << "Zipfile " << checkFilename - << " does not contain an archive"; - wasfound = kFALSE; - } - fzip->Close(); - delete fzip; - } else { - LOG(error) << "Could not open zipfile " << checkFilename; - wasfound = kFALSE; - } - } - - return wasfound; -} - ClassImp(CbmPlutoGenerator) diff --git a/sim/transport/generators/CbmPlutoGenerator.h b/sim/transport/generators/CbmPlutoGenerator.h index 0589e45f030988c589a691122f51a034742c8fd1..d5f6a7cd8e4594c2d4e324b3a0d472f8a858d992 100644 --- a/sim/transport/generators/CbmPlutoGenerator.h +++ b/sim/transport/generators/CbmPlutoGenerator.h @@ -77,9 +77,6 @@ private: ** input file properly. Called from destructor and from ReadEvent. **/ void CloseInput(); - /** Check if file exists. Break fatal when it doesn't exist **/ - Bool_t CheckFileExist(std::string filename); - ClassDef(CbmPlutoGenerator, 4); }; diff --git a/sim/transport/steer/CMakeLists.txt b/sim/transport/steer/CMakeLists.txt index 253c1a2907170d0741b16d6967fe02b58cd2b98a..375b40e617e1003f3a1220ccc95de52cf75db82a 100644 --- a/sim/transport/steer/CMakeLists.txt +++ b/sim/transport/steer/CMakeLists.txt @@ -33,7 +33,7 @@ ${CBMROOT_SOURCE_DIR}/sim/transport/generators ${CBMROOT_SOURCE_DIR}/sim/transport/steer ${CBMROOT_SOURCE_DIR}/sim/transport/geosetup ${CBMDATA_DIR} -${CBMROOT_SOURCE_DIR}/generators/unigen +${CBMBASE_DIR}/utils ) set(SYSTEM_INCLUDE_DIRECTORIES diff --git a/sim/transport/steer/CbmTransport.cxx b/sim/transport/steer/CbmTransport.cxx index e56866d543a125d7a6eda7a6a047a483f8015624..9943a72c0bd11ca357c135eef02a0b969e6e9df3 100644 --- a/sim/transport/steer/CbmTransport.cxx +++ b/sim/transport/steer/CbmTransport.cxx @@ -37,6 +37,7 @@ #include "CbmEventGenerator.h" #include "CbmFieldMap.h" #include "CbmFieldPar.h" +#include "CbmFileUtils.h" #include "CbmPlutoGenerator.h" #include "CbmSetup.h" #include "CbmStack.h" @@ -104,9 +105,16 @@ void CbmTransport::AddInput(const char* fileName, ECbmGenerator genType) { FairGenerator* generator = NULL; - if (gSystem->AccessPathName(fileName)) { - LOG(fatal) << GetName() << ": Input file " << fileName << " not found!"; - return; + if (genType == kUrqmd) { + if (gSystem->AccessPathName(fileName)) { + LOG(fatal) << GetName() << ": Input file " << fileName << " not found!"; + return; + } + } else { + if (!Cbm::File::IsRootFile(fileName)) { + LOG(fatal) << GetName() << ": Input file " << fileName << " not found!"; + return; + } } switch (genType) {