diff --git a/bin/tables/.DS_Store b/bin/tables/.DS_Store deleted file mode 100644 index a467707..0000000 Binary files a/bin/tables/.DS_Store and /dev/null differ diff --git a/src/app/crbeam/CMakeLists.txt b/src/app/crbeam/CMakeLists.txt index da056ce..09c7353 100644 --- a/src/app/crbeam/CMakeLists.txt +++ b/src/app/crbeam/CMakeLists.txt @@ -34,6 +34,6 @@ CRbeam.h ) add_link_options(-fopenmp) add_executable(CRbeam ${SOURCE_FILES}) -target_link_libraries(CRbeam mcray ${BOOST_SYS_LIBRARY} ${BOOST_FS_LIBRARY} ${C_LIBRARY} ${GSL_LIBRARY} ${GSLCBLAS_LIBRARY}) +target_link_libraries(CRbeam mcray ${BOOST_SYS_LIBRARY} ${BOOST_FS_LIBRARY} ${C_LIBRARY} ${GSL_LIBRARY} ${GSLCBLAS_LIBRARY} ${CMAKE_DL_LIBS}) diff --git a/src/app/crbeam/CRbeam.cpp b/src/app/crbeam/CRbeam.cpp index ca9ee67..444b257 100644 --- a/src/app/crbeam/CRbeam.cpp +++ b/src/app/crbeam/CRbeam.cpp @@ -68,7 +68,7 @@ using namespace cors::cmdline; */ int user_main(int argc, char** argv) { std::cout << "Number of available threads: " << omp_thread_count() << std::endl; - std::cout << "tables path: " << shared_tables_path() << std::endl; + std::cout << "Using tables path: " << tables_dir << std::endl; CRbeam prog(argc, argv); return prog.run(); diff --git a/src/lib/Background.cpp b/src/lib/Background.cpp index 6a85bcd..49c6d6b 100644 --- a/src/lib/Background.cpp +++ b/src/lib/Background.cpp @@ -107,7 +107,7 @@ void TableBackground::Init(std::string aDir, const char** aFileList, bool aIsLog { //the files should be ordered increasingly? //x scale should by monotonic with increasing order - aDir = TABLES_DIR + aDir; + aDir = tables_dir + aDir; double lastZ = -1; for(int iZ=0; aFileList[iZ]; iZ++) { @@ -162,7 +162,7 @@ MatrixBackground::MatrixBackground(std::string aName, std::string aTableFile, bo const size_t bufSize = 1048576;//1M fBuffer = new char[bufSize]; std::istream_iterator eos; - aTableFile = TABLES_DIR + aTableFile; + aTableFile = tables_dir + aTableFile; std::ifstream file(aTableFile.c_str()); if(!file.good()) diff --git a/src/lib/Deflection3D.cpp b/src/lib/Deflection3D.cpp index d24de77..a0dbfd2 100644 --- a/src/lib/Deflection3D.cpp +++ b/src/lib/Deflection3D.cpp @@ -247,6 +247,7 @@ namespace Interactions { double Bgauss = 10.; MonochromaticMF mf(r,lambdaMpc,Bgauss); mf.Print(lambdaMpc); + return 0; } int Deflection3D::UnitTest() { diff --git a/src/lib/GZK.cpp b/src/lib/GZK.cpp index 01116c9..9cee22e 100644 --- a/src/lib/GZK.cpp +++ b/src/lib/GZK.cpp @@ -51,7 +51,7 @@ GZK::GZK(BackgroundIntegral* aBackground, int aRandSeed):fBackground(aBackground Function* GZK::InitSigma(ParticleType aPrim) { - std::string tablesDir = TABLES_DIR "sophia2/"; + std::string tablesDir = tables_dir + "sophia2/"; Utils::TableReader reader(tablesDir+(aPrim==Proton?"p":"n"), 2); std::vector& s = reader.getColumn(0); std::vector& sigma = reader.getColumn(1); diff --git a/src/lib/MathUtils.cpp b/src/lib/MathUtils.cpp index 1ee7664..593403d 100644 --- a/src/lib/MathUtils.cpp +++ b/src/lib/MathUtils.cpp @@ -975,6 +975,7 @@ template bool MathUtils::SampleLogscaleDistribution(const Function& aDis //Sampler4 dil; NRSampler dil; dil.UnitTest(); + return 0; } double MathUtils::Integration_qag ( diff --git a/src/lib/Stecker16Background.cpp b/src/lib/Stecker16Background.cpp index 6f27e15..bc3a312 100644 --- a/src/lib/Stecker16Background.cpp +++ b/src/lib/Stecker16Background.cpp @@ -32,11 +32,11 @@ namespace Backgrounds { Stecker16LowerBackground::Stecker16LowerBackground() : - Stecker16Background(TABLES_DIR "stecker_ebl16/comoving_enerdens_lo.csv", "Stecker_16_lower") { + Stecker16Background(tables_dir + "stecker_ebl16/comoving_enerdens_lo.csv", "Stecker_16_lower") { } Stecker16UpperBackground::Stecker16UpperBackground() : - Stecker16Background(TABLES_DIR "stecker_ebl16/comoving_enerdens_up.csv", "Stecker_16_upper") + Stecker16Background(tables_dir + "stecker_ebl16/comoving_enerdens_up.csv", "Stecker_16_upper") { } @@ -55,6 +55,7 @@ int Stecker16Background::UnitTest() BackgroundUtils::UnitTest(backgrUpper); Stecker16LowerBackground backgrLower; BackgroundUtils::UnitTest(backgrLower); + return 0; } } \ No newline at end of file diff --git a/src/lib/SteckerEBL.cpp b/src/lib/SteckerEBL.cpp index 4064ead..fec7cf3 100644 --- a/src/lib/SteckerEBL.cpp +++ b/src/lib/SteckerEBL.cpp @@ -36,7 +36,7 @@ namespace Backgrounds { #define IRO_DATA_FILE "iro_stecker2005" Stecker2005EBL::Stecker2005EBL(): - CTableWithHeaderReader(TABLES_DIR IRO_DATA_FILE), + CTableWithHeaderReader((tables_dir + IRO_DATA_FILE).c_str()), m_accuracyE(0), m_accuracyZ(0), m_curE(0) diff --git a/src/lib/Utils.cpp b/src/lib/Utils.cpp index 22fa6f6..556707a 100644 --- a/src/lib/Utils.cpp +++ b/src/lib/Utils.cpp @@ -36,52 +36,34 @@ namespace fs = boost::filesystem; namespace Utils { - const char PathSeparator = -#ifdef _WIN32 - '\\'; -#else - '/'; -#endif + const char PathSeparator = DIR_DELIMITER_STR[0]; - - std::string shared_tables_path(){ + std::string default_tables_path(){ + // On conda env installations tables are stored in shared folder + // For standalone installations tables are stored in bin folder std::string tables_folder_name("tables"); fs::path prog_path = boost::dll::program_location(); + fs::path prog_name = prog_path.stem().string(); + fs::path prog_dir = prog_path.parent_path(); + fs::path shared_tables_dir = prog_dir.parent_path() / "shared" / prog_name / tables_folder_name; + fs::path exe_tables_dir = prog_dir / tables_folder_name; - // for some reason boost::filesystem::path.parent_path() and fs::canonical didn't work properly os my Mac OS so we do it manually + if(fs::is_directory(shared_tables_dir)) + return shared_tables_dir.string(); + if(fs::is_directory(exe_tables_dir)) + return exe_tables_dir.string(); - std::stringstream path(prog_path.string()); - std::string segment; - std::vector seglist; + // we don't check for existence of './tables' and + // don't throw exception here since on some platforms fs::is_directory doesn't work properly + std::cerr << "WARNING: Neither " << shared_tables_dir.string() << " nor \n" << exe_tables_dir.string() << + " was found.\n You can download latest tables from\n" << + "https://github.com/okolo/mcray/tree/main/bin/tables\n"; - while(std::getline(path, segment, PathSeparator)) - { - seglist.push_back(segment); - } - - if(seglist.size() >= 3){ - std::string app_name = seglist.back(); - seglist.pop_back(); - seglist.pop_back(); - seglist.push_back(std::string("shared")); - seglist.push_back(app_name); - seglist.push_back(tables_folder_name); - std::ostringstream os; - for(std::string& seg : seglist){ - os << seg << PathSeparator; - } - std::string table_dir = os.str(); - table_dir.pop_back(); - std::cout << "extracted path:" << table_dir << "\n\n"; - fs::path p = fs::path(table_dir); - if(fs::exists(fs::status(p))) - return table_dir; - else - std::cout << "type " << fs::status(p).type() << "\n\n"; - } - return tables_folder_name + PathSeparator; + return tables_folder_name; } + std::string tables_dir = default_tables_path() + DIR_DELIMITER_STR; + int omp_thread_count() { int n = 0; #pragma omp parallel reduction(+:n) diff --git a/src/lib/Utils.h b/src/lib/Utils.h index b9ba358..d9323fc 100644 --- a/src/lib/Utils.h +++ b/src/lib/Utils.h @@ -43,10 +43,18 @@ namespace Utils { -std::string shared_tables_path(); +std::string default_tables_path(); + + +#ifdef _WIN32 +#define DIR_DELIMITER_STR "\\" +#else #define DIR_DELIMITER_STR "/" -#define TABLES_DIR "tables" DIR_DELIMITER_STR +#endif + +extern std::string tables_dir; +//#define TABLES_DIR "tables" DIR_DELIMITER_STR class Exception {