Gitlab@AEI Hannover will go down for maintenance on 2020-09-21 at 4:00 UTC. The service will be unavailable for up to 24 hours. If you have questions about this please contact

Commit 0e9d656b authored by David Keitel's avatar David Keitel

Writer: clean up logic in check_cached_data_okay_to_use()

 -make clearer when and why we test the .cff file
 -also improve logging output in this function
  and in check_if_cff_file_needs_rewritting()
 -test_makefakedata_usecached: add a call to make_cff()
  in 2nd run as an extra check
parent fcf6c307
......@@ -259,46 +259,51 @@ transientTau = {:10.0f}\n"""
def check_cached_data_okay_to_use(self, cl_mfd):
""" Check if cached data exists and, if it does, if it can be used """
getmtime = os.path.getmtime
need_new = "Will create new SFT file.""Checking if cached data good to reuse...")
if os.path.isfile(self.sftfilepath) is False:"No SFT file matching {} found".format(self.sftfilepath))"No SFT file matching {} found. {}".format(self.sftfilepath, need_new))
return False
else:"Matching SFT file found")
if getmtime(self.sftfilepath) < getmtime(self.config_file_name):
"The config file {} has been modified since the sft file {} "
+ "was created"
).format(self.config_file_name, self.sftfilepath)
return False"OK: Matching SFT file found.")
if "injectionSources" in cl_mfd:
if os.path.isfile(self.config_file_name):
if os.path.getmtime(self.sftfilepath) < os.path.getmtime(self.config_file_name):
"The config file {} has been modified since the SFT file {} "
+ "was created. {}"
).format(self.config_file_name, self.sftfilepath, need_new)
return False
"OK: The config file {} is older than the SFT file {}".format(
self.config_file_name, self.sftfilepath)
# NOTE: at this point we assume it's safe to re-use, since
# check_if_cff_file_needs_rewritting()
# should have already been called before
raise RuntimeError("Commandline requires file '{}' but it is missing.".format(self.config_file_name))
"The config file {} is older than the sft file {}".format(
self.config_file_name, self.sftfilepath
)"Checking contents of cff file") # FIXME: check doesn't seem to exist...?
#if not XXX:"Contents unmatched")
#return False"Checking commandline against existing SFT header")"Checking new commandline against existing SFT header...")
cl_dump = "lalapps_SFTdumpheader {} | head -n 20".format(self.sftfilepath)
output = helper_functions.run_commandline(cl_dump)
header_lines_lalapps = [line for line in output.split("\n") if "lalapps" in line]
if len(header_lines_lalapps)==0:"Could not obtain comparison commandline from old SFT header")"Could not obtain comparison commandline from old SFT header. "+need_new)
return False
cl_old = header_lines_lalapps[0]
if helper_functions.match_commandlines(cl_old,cl_mfd):"Commandline matched with old SFT header, use old sft file")
return True
else:"Commandlines unmatched, create new sft file")
if not helper_functions.match_commandlines(cl_old,cl_mfd):"Commandlines unmatched. "+need_new)
return False
else:"OK: Commandline matched with old SFT header.")"Looks like cached data matches current options, will re-use it!")
return True
def check_if_cff_file_needs_rewritting(self, content):
""" Check if the .cff file has changed
......@@ -306,24 +311,25 @@ transientTau = {:10.0f}\n"""
Returns True if the file should be overwritten - where possible avoid
overwriting to allow cached data to be used
""""Checking if we can re-use injection config file...")
if os.path.isfile(self.config_file_name) is False:"No config file {} found".format(self.config_file_name))"No config file {} found.".format(self.config_file_name))
return True
else:"Config file {} already exists".format(self.config_file_name))"Config file {} already exists.".format(self.config_file_name))
with open(self.config_file_name, "r") as f:
file_content =
if file_content == content:
"File contents match, no update of {} required".format(
"File contents match, no update of {} required.".format(
return False
"File contents unmatched, updating {}".format(self.config_file_name)
"File contents unmatched, updating {}.".format(self.config_file_name)
return True
......@@ -80,12 +80,16 @@ class Writer(Test):
Writer = pyfstat.Writer(self.label, outdir=self.outdir, duration=3600)
if os.path.isfile(Writer.sftfilepath):
# first run: make everything from scratch
time_first = os.path.getmtime(Writer.sftfilepath)
# second run: should re-use .cff and .sft
time_second = os.path.getmtime(Writer.sftfilepath)
self.assertTrue(time_first == time_second)
# third run: touch the .cff to force regeneration
time.sleep(1) # make sure timestamp is actually different!
os.system("touch {}".format(Writer.config_file_name))
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