diff --git a/.gitignore b/.gitignore index c1f48a5e5e5de31a2375f485c3b80d6b911cf853..7259943d695a724b5f580be73fa50c0176596ae0 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ ROOTfiles raw raw.copiedtotape cache +logs # Symbolic links -hcana \ No newline at end of file +hcana diff --git a/SCRIPTS/PRODUCTION/replay_shms.cxx b/SCRIPTS/PRODUCTION/replay_shms.cxx index 756a663191f700f178b6f915c70032e20c955b41..cef4c7781216579c959bf4e4c03091ccb195aba4 100644 --- a/SCRIPTS/PRODUCTION/replay_shms.cxx +++ b/SCRIPTS/PRODUCTION/replay_shms.cxx @@ -37,7 +37,7 @@ using namespace std; #include "THcTrigDet.h" std::string coda_file_pattern(bool do_coin) { - return fmt::format("{}_all_{{:05d}}.dat", do_coin? "coin", "shms"); + return fmt::format("{}_all_{{:05d}}.dat", do_coin ? "coin" : "shms"); } std::string output_file_pattern(string_view path, string_view content, string_view extension, bool do_coin, bool do_all) { @@ -45,8 +45,8 @@ std::string output_file_pattern(string_view path, string_view content, string_vi do_all ? "all_" : "", extension); } -void replay_shms(Int_t RunNumber = 7160, Int_t MaxEvent = 0, string_view mode = "shms", - const bool do_all = false) { +int replay_shms(Int_t RunNumber = 7160, Int_t MaxEvent = -1, Int_t FirstEvent = 0, + const bool do_coin = false, const bool do_all = false) { // =========================================================================== // Setup logging spdlog::set_level(spdlog::level::warn); @@ -68,11 +68,6 @@ void replay_shms(Int_t RunNumber = 7160, Int_t MaxEvent = 0, string_view mode = return -1; } } - if (mode != "shms" && mode != "SHMS" && mode != "coin" && mode != "COIN") { - cerr << "Invalid mode `" << mode << "`, has to be either `coin` or `shms`\n"; - return -1; - } - const bool do_coin = (mode == "coin" || mode == "COIN"); // =========================================================================== // Create file name patterns. @@ -252,7 +247,7 @@ void replay_shms(Int_t RunNumber = 7160, Int_t MaxEvent = 0, string_view mode = // File to record accounting information for cuts analyzer->SetSummaryFile(fmt::format(output_file_pattern("REPORT_OUTPUT/PRODUCTION", "summary", "report", do_coin, do_all), - Run Number, MaxEvent) + RunNumber, MaxEvent) .c_str()); // Start the actual analysis. analyzer->Process(run); @@ -261,8 +256,10 @@ void replay_shms(Int_t RunNumber = 7160, Int_t MaxEvent = 0, string_view mode = "TEMPLATES/SHMS/PRODUCTION/pstackana_production.template", fmt::format(output_file_pattern("REPORT_OUTPUT/PRODUCTION", "replay_production", "report", do_coin, do_all), - Run Number, MaxEvent) + RunNumber, MaxEvent) .c_str()); delete analyzer; + + return 0; } diff --git a/SCRIPTS/replay_shms.sh b/SCRIPTS/replay_shms.sh index a0c4ad452d99e5cdec87e16fab031453d5584fc8..fa73801d724a3f08e32062c1073f7a41d3c454a8 100755 --- a/SCRIPTS/replay_shms.sh +++ b/SCRIPTS/replay_shms.sh @@ -12,6 +12,16 @@ function print_the_help { exit } +function io_error { + echo ERROR: cannot create or write to directory $1 + exit -1 +} +function ensure_directory { + echo "Ensuring $1 exists and is writable" + [[ -d "$1" ]] || mkdir -p $1 + touch $1/.write_check || io_error $1 +} + function yes_or_no { while true; do read -p "$* [y/n]: " yn @@ -63,7 +73,7 @@ do shift # past argument ;; -c|--coin) - DO_COIN="true" + shift # past argument ;; *) # unknown option @@ -97,5 +107,16 @@ fi # exit #fi -hcana -b -q \ - "SCRIPTS/SHMS/replay_shms.cxx+(${run_number},${n_events},${min_event},${DO_COIN},${DO_ALL})" +## NOTE: if you change anything here, make sure you make corresponding changes +## in the replay script +REPLAY_ARGS="${run_number},${n_events},${min_event},${DO_COIN},${DO_ALL}" +REPLAY_CMD="SCRIPTS/PRODUCTION/replay_shms.cxx+(${REPLAY_ARGS})" +REPORT_DIR="REPORT_OUTPUT/PRODUCTION" +LOGDIR="logs" +ROOTDIR="ROOTfiles" + +ensure_directory ${REPORT_DIR} +ensure_directory ${LOGDIR} +ensure_directory ${ROOTDIR} + +hcana -b -q "${REPLAY_CMD}"