Skip to content

Commit 2b3dfe9

Browse files
authored
Merge pull request #243 from JeffersonLab/nsj_getfiletime
modified for compatibility with JANA2
2 parents cc8f8dc + 76dda97 commit 2b3dfe9

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

get_file_time/get_file_time.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def getrunnumber(filename):
5454
dumpf=open(filename,'r')
5555

5656
line='start '
57-
while line[:4] != 'Run:' and len(line)>0:
57+
while not 'Run: ' in line:
5858
line=dumpf.readline()
5959
if not line:
6060
break
@@ -63,7 +63,7 @@ def getrunnumber(filename):
6363
print('Run number was not found in the file.')
6464
return 0
6565

66-
return line[4:len(line)-1] # exclude the newline
66+
return line.split()[-1]
6767

6868
dumpf.close()
6969

@@ -73,7 +73,7 @@ def getprestarttime(filename):
7373
dumpf=open(filename,'r')
7474

7575
line='start '
76-
while line[:18] != 'DCODAControlEvent:' and len(line)>0:
76+
while not 'DCODAControlEvent:' in line:
7777
line=dumpf.readline()
7878
if not line:
7979
break
@@ -85,9 +85,9 @@ def getprestarttime(filename):
8585
dumpf.readline() # event_type: unix_time: Nwords:
8686
dumpf.readline() #---------------------------------------------------------------
8787
line=dumpf.readline() # ffd2 1630144027 5
88-
89-
event_type=line.split()[0]
90-
unixtime=line.split()[1]
88+
items=line.split() # sort from the end in case the text (timestamp [info]) before the event-type changes
89+
event_type=items[-3]
90+
unixtime=items[-2]
9191

9292
# if event_type != 'ffd2' :
9393
# print event_type
@@ -105,7 +105,7 @@ def geteventtime(filename):
105105
dumpf=open(filename,'r')
106106

107107
line='start '
108-
while line[:13] != 'DCODAROCInfo:':
108+
while not 'DCODAROCInfo:' in line:
109109
line=dumpf.readline()
110110
if not line:
111111
break
@@ -118,7 +118,7 @@ def geteventtime(filename):
118118
dumpf.readline() #-----------------------------
119119
line=dumpf.readline() # 34 620160547174 0
120120

121-
timestamp=line.split()[1]
121+
timestamp=line.split()[-2]
122122

123123
return timestamp
124124

@@ -230,8 +230,9 @@ def geteventtime(filename):
230230
print('prestart '+dt_runstart.strftime("%Y-%m-%d %H:%M:%S"))
231231
print('start of file '+dt_thisfile.strftime("%Y-%m-%d %H:%M:%S"))
232232

233+
233234
if outf:
234-
outf.write(dt_thisfile.strftime("%Y-%m-%d %H:%M:%S")+'\n')
235+
outf.write(run+",'"+dt_thisfile.strftime("%Y-%m-%d %H:%M:%S")+"'\n")
235236
if usedrcdb:
236237
outf.write('RCDB\n')
237238
outf.close()

0 commit comments

Comments
 (0)