Mu2e / otsdaq_mu2e

Mu2e customizations for otsdaq
Other
1 stars 5 forks source link

introducing an env var ARTDAQ_RUN_NUMBER #50

Open pavel1murat opened 9 months ago

pavel1murat commented 9 months ago

to allow encoding of run numbers into the log file names, I propose the following patch to artdaq_core/artdaq-core/Utilities/configureMessageFacility.cc

Modulo the line alignment, the patch introduces an env var ARTDAQ_RUN_NUMBER, and if that is defined, encodes it in the log file name. That will allow us to avoid using multiple log-related symlinks in the online environment

diff --git a/artdaq-core/Utilities/configureMessageFacility.cc b/artdaq-core/Utilities/configureMessageFacility.cc
index 59a793c..b1cd0e7 100644
--- a/artdaq-core/Utilities/configureMessageFacility.cc
+++ b/artdaq-core/Utilities/configureMessageFacility.cc
@@ -29,10 +29,15 @@ fhicl::ParameterSet make_pset(std::string const& config_str)
 std::string artdaq::generateMessageFacilityConfiguration(char const* progname, bool useConsole, bool printDebug, char const* fileExtraName)
 {
        std::string logPathProblem;
-       char* logRootString = getenv("ARTDAQ_LOG_ROOT");
-       char* logFhiclCode = getenv("ARTDAQ_LOG_FHICL");
+//-----------------------------------------------------------------------------
+// get environment variables
+//-----------------------------------------------------------------------------
+       char* logRootString         = getenv("ARTDAQ_LOG_ROOT");
+       char* logFhiclCode          = getenv("ARTDAQ_LOG_FHICL");
        char* artdaqMfextensionsDir = getenv("ARTDAQ_MFEXTENSIONS_DIR");
-       char* useMFExtensionsS = getenv("ARTDAQ_MFEXTENSIONS_ENABLED");
+       char* useMFExtensionsS      = getenv("ARTDAQ_MFEXTENSIONS_ENABLED");
+       char* run_number            = getenv("ARTDAQ_RUN_NUMBER");
+
        bool useMFExtensions = false;
        if (useMFExtensionsS != nullptr && !(strncmp(useMFExtensionsS, "0", 1) == 0))
        {
@@ -108,8 +113,18 @@ std::string artdaq::generateMessageFacilityConfiguration(char const* progname, b
        {
                ss << " file: {";
                ss << R"( type: "GenFile" threshold: "DEBUG" seperator: "-")";
-               ss << " pattern: \"" << progname << fileExtraName << "-%?H%t-%p.log"
-                  << "\"";
+    if (run_number == nullptr) {
+      ss << " pattern: \"" << progname << fileExtraName << "-%?H%t-%p.log" << "\"";
+    }
+    else {
+//-----------------------------------------------------------------------------
+// Mu2e case: run number is defined
+//-----------------------------------------------------------------------------
+      char c[10];
+      sprintf(c,"%06i",std::stoi(run_number));
+      ss << " pattern: \"" << progname << "-" << c << fileExtraName << "-%?H%t-%p.log" << "\"";
+    }
+
                ss << " timestamp_pattern: \"%Y%m%d%H%M%S\"";
                ss << " directory: \"" << logfileDir << "\"";
                ss << " append : false";