ATLAS Offline Software
Loading...
Searching...
No Matches
lumiFormat.py
Go to the documentation of this file.
1#Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3import os
4import datetime, time
5
6# Function to iterate through dates between start and end in steps of delta. ~ish
7def perdelta(start, end, delta):
8 curr = start
9 while curr < end:
10 yield curr, min(curr + delta, end)
11 curr += delta
12
13# Function to return required dates
14def checkDates(datesFileName):
15 #placeholder declarations
16 tempRun = 0
17
18 startingDates=[]
19 endDates=[]
20
21 #if no file containing previously used dates, create one with default values.
22 #"No any file found!" is what my motherboard says whilst booting my home PC, I found it funny and copied it over here
23 if not os.path.exists(datesFileName):
24 print("No any file found! at " + datesFileName + ". Making default values")
25
26 with open(datesFileName,'w') as datesFile:
27 firstTempDate = datetime.datetime(2015,4,2,1,1,1,1)
28 lastTempDate = datetime.datetime(2015,4,2,1,1,1)
29
30 datesFile.write(str(tempRun) + " " + str(firstTempDate) + " " + str(lastTempDate) +"\n")
31 startingDates.append(firstTempDate)
32 endDates.append(lastTempDate)
33
34 #if dates file exists, read from it
35 else:
36 print("Found " + datesFileName)
37 with open(datesFileName,'r') as datesFile:
38
39 for dateLine in datesFile:
40 tempDatesLine = dateLine.split()
41 firstTemp = tempDatesLine[1].split('-')
42 lastTemp = tempDatesLine[3].split('-')
43
44 firstTempTime = tempDatesLine[2].split(':')
45 lastTempTime = tempDatesLine[4].split(':')
46
47 firstTempTimes = firstTempTime[2].split('.')
48 lastTempTimes = lastTempTime[2].split('.')
49
50 if len(firstTempTimes)<2:
51 firstTempTimes.append(0)
52 if len(lastTempTimes)<2:
53 lastTempTimes.append(0)
54
55 firstTempDate = datetime.datetime(int(firstTemp[0]), int(firstTemp[1]), int(firstTemp[2]), int(firstTempTime[0]),int(firstTempTime[1]), int(firstTempTimes[0]), int(firstTempTimes[1]))
56 lastTempDate = datetime.datetime(int(lastTemp[0]), int(lastTemp[1]), int(lastTemp[2]), int(lastTempTime[0]), int(lastTempTimes[0]),int(lastTempTimes[0]), int(lastTempTimes[1]))
57
58 startingDates.append(firstTempDate)
59 endDates.append(lastTempDate)
60
61 datesList=[startingDates,endDates]
62 return datesList
63
64outPath = "/eos/atlas/user/j/jdickins/Pixel/LeakageCurrent/IBLData/processedData/Lumi/"
65outputName = outPath + "/runData.txt"
66outputSummary = outPath + "/runs.txt"
67
68inPath = "/eos/atlas/user/j/jdickins/Pixel/LeakageCurrent/IBLData/rawData/Lumi/"
69
70[startDates,endDates] = checkDates(outputSummary)
71
72currentDay = datetime.date(2018,11,7)
73firstDay = startDates[0].date()
74
75with open(outputName,'a+') as fout:
76
77 if firstDay + datetime.timedelta(days=1)<currentDay:
78 for s, e in perdelta( firstDay, currentDay, datetime.timedelta(days=1)):
79
80 s_str = str(s).replace('-','_')
81 e_str = str(e).replace('-','_')
82 print(s_str)
83 filename = inPath + s_str + "-" + e_str + ".txt"
84 with open(filename,"r") as fin:
85 i = -1
86 for line in fin:
87 i = i+1
88 if i < 3:
89 continue
90
91 array=line.rstrip().split()
92
93 startDateTime=array[0].split('/UTC')[0].split('[')[1]
94 startDate = startDateTime.split('-')
95 startTime = startDateTime.split(':')
96 start = datetime.datetime(int(startDate[0]),int(startDate[1]),int(startDate[2].split(':')[0]),int(startTime[1]),int(startTime[2]),int(startTime[3]))
97
98 endDateTime=array[1].split('/UTC')[0]
99 endDate = startDateTime.split('-')
100 endTime = startDateTime.split(':')
101 end = datetime.datetime(int(endDate[0]),int(endDate[1]),int(endDate[2].split(':')[0]),int(endTime[1]),int(endTime[2]),int(endTime[3]))
102
103 [run,lb] = array[2].split('/')
104 fill = int(array[3])
105 length = float(array[6])
106 lumi = float(array[10])
107 intlumi = length*lumi
108
109 # Match Nick's output format
110 fout.write(str(run) + " " + str(fill) + " " + str(lb) + " " +
111 str(time.mktime(start.timetuple())) + " " + str(length) + " " +
112 str(0) + " " + str(0) + " " + str(lumi) + " " + str(intlumi) +
113 "\n")
114
115
116with open(outputSummary,'w') as summaryFile:
117 summaryFile.write(str(run) + " " + str(startDates[0]) + " " + str(end) +"\n")
void print(char *figname, TCanvas *c1)
#define min(a, b)
Definition cfImp.cxx:40
std::string date()
sadly, includes a return at the end
Definition hcg.cxx:58
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
perdelta(start, end, delta)
Definition lumiFormat.py:7
checkDates(datesFileName)
Definition lumiFormat.py:14