Commit fcf6c307 authored by David Keitel's avatar David Keitel

Writer.check_cached_data_okay_to_use(): fix comparing new commandline against old SFT header

 -this used to require exact string match, but SFT header
  can for some reason have the CLAs reordered
  (e.g. when ephemerides are involved)
 -introduce new helper function match_commandlines()
  and do proper unordered set comparison
 -also comment out log info about cff content checking,
  which wasn't actually implemented!
parent 69c31083
......@@ -369,3 +369,16 @@ def twoFDMoffThreshold(
return twoFDMoffthreshold_below_threshold
else:
return 10 ** (prefactor * np.log10(twoFon - offset))
def match_commandlines(cl1, cl2, be_strict_about_full_executable_path=False):
""" Check if two commandlines match element-by-element, regardless of order """
cl1s = cl1.split(" ")
cl2s = cl2.split(" ")
# first item will be the executable name
# by default be generous here and do not worry about full paths
if not be_strict_about_full_executable_path:
cl1s[0] = os.path.basename(cl1s[0])
cl2s[0] = os.path.basename(cl2s[0])
unmatched = np.setxor1d(cl1s,cl2s)
return len(unmatched)==0
......@@ -281,15 +281,23 @@ transientTau = {:10.0f}\n"""
self.config_file_name, self.sftfilepath
)
)
logging.info("Checking contents of cff file")
#logging.info("Checking contents of cff file") # FIXME: check doesn't seem to exist...?
#if not XXX:
#logging.info("Contents unmatched")
#return False
logging.info("Checking commandline against existing SFT header")
cl_dump = "lalapps_SFTdumpheader {} | head -n 20".format(self.sftfilepath)
output = helper_functions.run_commandline(cl_dump)
found = [True for line in output.split("\n") if line[-len(cl_mfd) :] == cl_mfd]
if any(found):
logging.info("Contents matched, use old sft file")
header_lines_lalapps = [line for line in output.split("\n") if "lalapps" in line]
if len(header_lines_lalapps)==0:
logging.info("Could not obtain comparison commandline from old SFT header")
return False
cl_old = header_lines_lalapps[0]
if helper_functions.match_commandlines(cl_old,cl_mfd):
logging.info("Commandline matched with old SFT header, use old sft file")
return True
else:
logging.info("Contents unmatched, create new sft file")
logging.info("Commandlines unmatched, create new sft file")
return False
def check_if_cff_file_needs_rewritting(self, content):
......@@ -358,8 +366,8 @@ transientTau = {:10.0f}\n"""
cl_mfd.append('--ephemSun="{}"'.format(sun_ephem))
cl_mfd = " ".join(cl_mfd)
if self.check_cached_data_okay_to_use(cl_mfd) is False:
check_ok = self.check_cached_data_okay_to_use(cl_mfd)
if check_ok is False:
helper_functions.run_commandline(cl_mfd)
def predict_fstat(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment