From 00b12f0dcee2679a6d9429c24e087bcf4acf668d Mon Sep 17 00:00:00 2001
From: lex <fabian.simon.lex@cern.ch>
Date: Tue, 4 Apr 2023 18:43:10 +0200
Subject: [PATCH] Changed name of conf file to include hash instead of run
 number

---
 jobsub/jobsub.py | 14 ++++----------
 jobsub/misc.py   |  2 +-
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/jobsub/jobsub.py b/jobsub/jobsub.py
index 767065308..2a595ea41 100755
--- a/jobsub/jobsub.py
+++ b/jobsub/jobsub.py
@@ -20,6 +20,7 @@ import sys
 import logging
 import misc
 import time, multiprocessing
+import hashlib
 
 def runCorryvreckanLocally(filename, jobtask, silent):
     """ Runs Corryvreckan and stores log of output """
@@ -181,7 +182,6 @@ def main(argv=None):
     parser.add_argument("-j", "--cores", metavar='N', type=int, default=1, help="Number of cores used for the local job submission")
     parser.add_argument("--zfill", metavar='N', type=int, help="Fill run number with zeros up to the defined number of digits")
     parser.add_argument("runs", help="The runs to be analyzed; can be a list of single runs and/or a range, e.g. 1056-1060.", nargs='*')
-    parser.add_argument("--short-names", action="store_true", default=False, help="Save config and log files with the run number as their abbreviated name")
     args = parser.parse_args(argv)
 
     # Try to import the colorer module
@@ -338,20 +338,14 @@ def main(argv=None):
         
         # ----------------------------------------------------------------
         # Job submission based on selected method - local/condor
-        run_iteration = 0
         for suffix, steering_string in zip(suffixes, steering_strings):
             try:
                 #submission_settings.append((args, misc.createSteeringFile(log, args, steering_string, suffix), parameters))
-                if args.short_names:
-                    suffix = f"{runnr}_{run_iteration}" 
-                    steering_filename = misc.createSteeringFile(log, args, steering_string, suffix)
-                else: 
-                    steering_filename = misc.createSteeringFile(log, args, steering_string, suffix)
+                suffix_hash = string = hashlib.shake_128(suffix.encode()).hexdigest(16)
+                steering_filename = misc.createSteeringFile(log, args, steering_string, suffix_hash)
                 results.append(submitJobs(log, pool, args, steering_filename, parameters))
             except Exception as e:
-                log.error(f"Could not create submission file with suffix {suffix} due to {e}")
-            run_iteration +=1
-            
+                log.error(f"Could not create submission file with suffix {suffix_hash} due to {e}")            
 
         # Return to old directory:
         if args.subdir:
diff --git a/jobsub/misc.py b/jobsub/misc.py
index 35c083e1e..f1c5c9b19 100644
--- a/jobsub/misc.py
+++ b/jobsub/misc.py
@@ -122,7 +122,7 @@ def createSteeringFile(log, args, steering_string, suffix):
     # Get "jobtask" as basename of the configuration file:
     jobtask = os.path.splitext(os.path.basename(args.conf_file))[0]
     # Write the steering file:
-    filename = jobtask + "_run" + suffix
+    filename = jobtask + "_" + suffix
     log.info("filename = " + filename)
     steering_file = open(filename+".conf", "w")
 
-- 
GitLab