From 1d3ceac5e933bd0ef121fecf6a667793ac53ceac Mon Sep 17 00:00:00 2001
From: "FR@29iduser" <rodolakis@anl.gov>
Date: Tue, 20 Sep 2022 14:44:22 -0500
Subject: [PATCH] log_update fixed

---
 iexcode/instruments/Logfile.py           | 24 ++++++++++++------------
 iexcode/instruments/electron_analyzer.py |  3 +--
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/iexcode/instruments/Logfile.py b/iexcode/instruments/Logfile.py
index 63c6ef5..58dd961 100644
--- a/iexcode/instruments/Logfile.py
+++ b/iexcode/instruments/Logfile.py
@@ -25,14 +25,11 @@ def log_update(d=None):
     updates the log file with the last scan info
     d = dictionary of {header:[data,format]}
     """
-    try: 
-        if d == None:
-            d = iex.BL.mda.log.log_dictionary()
-    
-        iex.BL.mda.log.update(d)
+    #try: 
+    iex.BL.mda.log.update(d)
 
-    except:
-        print('No logfile written')
+    #except:
+    #    print('No logfile written')
 
 def log_name_set(file_name):
     try: 
@@ -193,13 +190,13 @@ class Logfile:
                 entry+=item+","
             f.write(entry[:-1] +'\n\n')  
     
-    def write_entry(self,data_list, format_list):
+    def write_entry(self, head_list, data_list, format_list):
         """
         writes an entry to the logfile
         """
         
         if not isfile(self.filepath):
-            self.write_header()
+            self.write_header(head_list)
 
         with open(self.filepath, "a+") as f:
             for i in range(len(format_list)):
@@ -209,19 +206,22 @@ class Logfile:
             pv_format="{0:"+format_list[last_entry]+"}\n"
             f.write(pv_format.format(data_list[last_entry]))
    
-    def update(self):
+    def update(self,d=None):
         """ 
         To be used for scanlog and scanEA functions.
         Update SaveFile_Header version number when changing the structure of the file (indexing).
 
         Previously: SaveFile
         """
-        header_list,data_list,format_list = self.log_entries()
+        if d == None:
+            d = iex.BL.mda.log.log_dictionary()
+
+        header_list,data_list,format_list = self.log_entries(d)
 
         if not isfile(self.filepath):
             self._intit_log(header_list)
         
-        self.write_entry(self,data_list, format_list)
+        self.write_entry(header_list,data_list,format_list)
 
 
 
diff --git a/iexcode/instruments/electron_analyzer.py b/iexcode/instruments/electron_analyzer.py
index 393f7a8..782174e 100644
--- a/iexcode/instruments/electron_analyzer.py
+++ b/iexcode/instruments/electron_analyzer.py
@@ -166,8 +166,7 @@ def EAlog_update():
     """
     d=EA_log_dictionary()
     try:
-        header_list,data_list,format_list = iex.BL.mda.log.log_entries(d)
-        iex.BL.mda.log.write_entry(data_list,format_list)    
+        log_update(d)  
     except:
         print("EAlog did not write to file, check for errors.")
 
-- 
GitLab