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