ATLAS Offline Software
Functions
grabPipeTemp Namespace Reference

Functions

def perdelta (start, end, delta)
 
def perdeltadown (start, end, delta)
 
def findFiles (searchFolderPath)
 
def checkDates (dataType, dataFolder)
 
def grabDataStave (dataType)
 
def main ()
 PROGRAM STARTS HERE #. More...
 

Function Documentation

◆ checkDates()

def grabPipeTemp.checkDates (   dataType,
  dataFolder 
)

Definition at line 74 of file grabPipeTemp.py.

74 def checkDates(dataType, dataFolder):
75 
76  # Placeholder declarations
77  fillerDate = datetime.datetime(2000, 1, 1, 1, 1, 1, 1)
78  tempDate = datetime.datetime(2000, 1, 1, 1, 1, 1, 1)
79  returnList = [fillerDate, fillerDate, fillerDate]
80 
81  startingDates = []
82  endDates = []
83 
84  # Check: what dates have I already downloaded?
85  # If no file containing previously used dates, create one with default values.
86  # "No any file found!" is what my motherboard says whilst booting my home PC, I found it funny and copied it over here
87  if not os.path.exists(dataFolder+dataType+".txt"):
88  print("No any file found! at " + dataFolder +
89  dataType + " Making default values")
90 
91  with open(dataFolder+dataType+".txt", 'w') as datesFile:
92  firstTempDate = datetime.datetime(2015, 1, 1, 1, 1, 1, 1)
93  lastTempDate = datetime.datetime(2015, 1, 1, 1, 1, 1)
94 
95  datesFile.write(dataType + " " + str(firstTempDate) + " " +
96  str(lastTempDate) + "\n")
97  startingDates.append(firstTempDate)
98  endDates.append(lastTempDate)
99 
100  # If dates file exists, read from it
101  else:
102  print("Found " + dataFolder+dataType+".txt")
103  with open(dataFolder+dataType+".txt", 'r') as datesFile:
104 
105  for dateLine in datesFile:
106  tempDatesLine = dateLine.split()
107  firstTemp = tempDatesLine[1].split('-')
108  lastTemp = tempDatesLine[3].split('-')
109 
110  firstTempTime = tempDatesLine[2].split(':')
111  lastTempTime = tempDatesLine[4].split(':')
112 
113  firstTempTimes = firstTempTime[2].split('.')
114  lastTempTimes = lastTempTime[2].split('.')
115 
116  if len(firstTempTimes) < 2:
117  firstTempTimes.append(0)
118  if len(lastTempTimes) < 2:
119  lastTempTimes.append(0)
120 
121  firstTempDate = datetime.datetime(
122  int(firstTemp[0]), int(firstTemp[1]), int(firstTemp[2]),
123  int(firstTempTime[0]), int(firstTempTime[1]),
124  int(firstTempTimes[0]), int(firstTempTimes[1]))
125  lastTempDate = datetime.datetime(
126  int(lastTemp[0]), int(lastTemp[1]), int(lastTemp[2]),
127  int(lastTempTime[0]), int(lastTempTimes[0]),
128  int(lastTempTimes[0]), int(lastTempTimes[1]))
129 
130  startingDates.append(firstTempDate)
131  endDates.append(lastTempDate)
132 
133  datesList = [startingDates, endDates]
134  # Return start and end dates for each sensor
135  return datesList
136 
137 # Function to save data of type dataType in dataFolder for all sensors, for specified dates. Only used to HV_IMeas
138 
139 

◆ findFiles()

def grabPipeTemp.findFiles (   searchFolderPath)

Definition at line 48 of file grabPipeTemp.py.

48 def findFiles(searchFolderPath):
49 
50  try:
51  os.chdir(searchFolderPath)
52  except IOError:
53  print('No entries in ' + searchFolderPath)
54  return -1
55 
56  todaysList = []
57 
58  # SOMEHOW, this searches the searchFolderPath and returns a list of contained files in well... files.
59  for src_dir, dirs, files in os.walk(searchFolderPath):
60 
61  # Parse through the files, appending the file name to a list of files.
62  for file_ in files:
63 
64  sortedFile = os.path.join(src_dir, file_)
65  todaysList.append(str(sortedFile))
66 
67  # Now we've got a list containing all files we want to add, sort it alphabetically and return them.
68  todaysList.sort()
69  return todaysList
70 
71 # Function to return required dates
72 
73 

◆ grabDataStave()

def grabPipeTemp.grabDataStave (   dataType)

Definition at line 140 of file grabPipeTemp.py.

140 def grabDataStave(dataType):
141 
142  # url is the line you're supposed to use. url2 is the line that works better.
143  url = 'http://atlas-ddv.cern.ch:8089/multidata/getDataSafely'
144  url2 = 'http://atlas-ddv.cern.ch:8089/multidata/downloadTxtData'
145 
146  # JENNET changed the output file path
147  defaultPath = os.path.expanduser(
148  '/eos/atlas/user/j/jdickins/Pixel/LeakageCurrent/')
149  # The data is saved to dataFolder / dataType / moduleGroup / startDate-endDate.txt
150  # This script will autogenerate folders for this.
151  dataFolder = defaultPath + "/IBLData/rawData/"
152 
153  # Check top level directory exists, then make folder for HV I, T, HV V, LV I and.. actually should get LV V
154  if not os.path.exists(dataFolder):
155  os.mkdir(dataFolder)
156  # For dataType in ['HV_IMeas', 'TModule','HV_VMeas','PP4LV']:
157  if not os.path.exists(dataFolder+dataType):
158  os.mkdir(dataFolder+dataType)
159 
160  [startDates, endDates] = checkDates(dataType, dataFolder)
161  currentDay = date.today()
162  firstDay = endDates[0].date()-timedelta(days=1)
163 
164 # firstDay = datetime.date(2018,3,7)
165 # currentDay = datetime.date(2018,3,10)
166  # Iterate through all data in below dates, with a time step of time delta. (So from 1/1/2016 - 15/5/2016, with one file per day).
167 
168  # Iterate through staves, modules and sides
169  sensorNumber = 0
170 
171  if firstDay+timedelta(days=1) < currentDay:
172  for s, e in perdelta(firstDay, currentDay, timedelta(days=1)):
173  if not os.path.exists(dataFolder+dataType+'/'):
174  os.mkdir(dataFolder+dataType+'/')
175 
176  if not os.path.exists(dataFolder+dataType+'Stave/'):
177  os.mkdir(dataFolder+dataType+'Stave/')
178 
179  saveFileName2 = dataFolder+dataType+'/' + \
180  s.strftime("%Y_%m_%d") + '-' + e.strftime("%Y_%m_%d") + '.txt'
181  if os.path.exists(saveFileName2):
182  os.remove(saveFileName2)
183 
184  with open(saveFileName2, 'w') as saveFile:
185  introubleCount = []
186  introubleMean = 0
187 
188  staveString = "stave"
189  staveLetter = "stave"
190  letterDict = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h',
191  9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n'}
192  for staveNumber in range(1, 15):
193  if staveNumber < 10:
194  staveString = "0" + str(staveNumber)
195  else:
196  staveString = str(staveNumber)
197  staveLetter = letterDict[staveNumber]
198  if staveNumber % 2 == 1:
199  staveLetter += '28'
200  else:
201  staveLetter += '30'
202 
203  # Generate save file name. I save in format YYYY/MM/DD, so it is in alphabetical order.
204  saveFileName = (
205  dataFolder+dataType+'Stave/'+s.strftime("%Y_%m_%d") +
206  '-' + e.strftime("%Y_%m_%d") + 'Stave' + staveString +
207  '.txt')
208  if os.path.exists(saveFileName):
209  os.remove(saveFileName)
210 
211  dataType2 = dataType + staveLetter
212 
213  # Create wget command
214  cmd = 'wget --post-data "queryInfo=atlas_pvssPIX, alias, LI_S' + staveString + '_A_' + dataType2 + ', ' + s.strftime("%d-%m-%Y") + ' 00:00, ' + e.strftime(
215  "%d-%m-%Y") + ' 00:01, , , , , ,no, , +2!atlas_pvssPIX, alias, LI_S' + staveString + '_C_' + dataType2 + ', ' + s.strftime("%d-%m-%Y") + ' 00:00, ' + e.strftime("%d-%m-%Y") + ' 00:01, , , , , ,no, , +2!" ' + url + ' --output-document=' + saveFileName
216 
217  # Execute wget command
218  os.system(cmd)
219 
220  if (os.path.getsize(saveFileName) < 300):
221  # i.e. if the file is small, download probably failed, try a different command
222 
223  sleepTime = random.randint(30, 62)
224  time.sleep(sleepTime)
225  os.remove(saveFileName)
226 
227  cmd = 'wget --post-data "queryInfo=atlas_pvssPIX, alias, LI_S' + staveString + '_A_' + dataType2 + ', ' + s.strftime("%d-%m-%Y") + ' 00:00, ' + e.strftime(
228  "%d-%m-%Y") + ' 00:01, , , , , ,no, , +2!atlas_pvssPIX, alias, LI_S' + staveString + '_C_' + dataType2 + ', ' + s.strftime("%d-%m-%Y") + ' 00:00, ' + e.strftime("%d-%m-%Y") + ' 00:01, , , , , ,no, , +2!" ' + url + ' --output-document=' + saveFileName
229 
230  # Execute wget command
231  os.system(cmd)
232 
233  if (0 < os.path.getsize(saveFileName) < 300):
234  # If this happens again, even url2 couldn't save us. You're gonna have to do stuff yourself
235 
236  os.remove(saveFileName)
237  print("bork bork at " + s.strftime("%Y_%m_%d") +
238  " please sign off yourself!")
239  break
240 
241  with open(saveFileName, 'r') as bloop:
242 
243  if (staveNumber != 1):
244  saveFile.write("!!!")
245 
246  introuble = 0
247 
248  for bloopLine in bloop:
249  saveFile.write(bloopLine)
250  introuble += 1
251 
252  introubleMean += introuble
253 
254  introubleCount.append(introuble)
255  sleepTime = random.randint(30, 62)
256  # Go to sleep so the DCS people don't yell at you
257  time.sleep(sleepTime)
258 
259  breakThatStick = False
260 
261  if introubleMean > 30:
262  for checker in range(0, 14):
263  if introubleCount[checker] < 2:
264  # If a sensor's data is less than 2 entries, whilst there are more than 30 entries for the day.
265  print("borkalork in stave " + str(checker+1))
266  breakThatStick = True
267 
268  if breakThatStick:
269  print("breaking now at " + s.strftime("%d-%m-%Y"))
270  break
271 
272  firstTempDate = min(datetime.datetime(
273  s.year, s.month, s.day, 0, 0, 0, 0), startDates[0])
274  startDates[0] = firstTempDate
275 
276  lastTempDate = max(datetime.datetime(
277  e.year, e.month, e.day, 0, 0, 0, 0), endDates[0])
278  endDates[0] = lastTempDate
279 
280  with open(dataFolder+dataType+".txt", 'w') as datesFile:
281  datesFile.write(dataType + " " + str(firstTempDate) + " " +
282  str(lastTempDate) + "\n")
283 
284  sleepTime = random.randint(10, 30)
285  time.sleep(sleepTime)
286 

◆ main()

def grabPipeTemp.main ( )

PROGRAM STARTS HERE #.

Definition at line 292 of file grabPipeTemp.py.

292 def main():
293 
294  # grabData('HV_VMeas')
295  # grabData('PP4LV')
296 
297  # grabData no longer works reliably for HV_IMeas, use grabStaveData instead
298  # Use this if grabData returns an error about very big DB request
299  # grabDataStave('HV_IMeas')
300  # grabDataStave('TModule')
301  grabDataStave('ENV_TT')
302 
303 

◆ perdelta()

def grabPipeTemp.perdelta (   start,
  end,
  delta 
)

Definition at line 30 of file grabPipeTemp.py.

30 def perdelta(start, end, delta):
31  curr = start
32  while curr < end:
33  yield curr, min(curr + delta, end)
34  curr += delta
35 
36 # Function to iterate through dates between end and start in steps of delta. ~ish
37 
38 

◆ perdeltadown()

def grabPipeTemp.perdeltadown (   start,
  end,
  delta 
)

Definition at line 39 of file grabPipeTemp.py.

39 def perdeltadown(start, end, delta):
40  curr = end
41  while curr > start:
42  yield max(curr - delta, start), curr
43  curr -= delta
44 
45 # Function to return list of all files in search folder path, sorted alphabetically
46 
47 
grabPipeTemp.perdeltadown
def perdeltadown(start, end, delta)
Definition: grabPipeTemp.py:39
grabPipeTemp.findFiles
def findFiles(searchFolderPath)
Definition: grabPipeTemp.py:48
max
#define max(a, b)
Definition: cfImp.cxx:41
grabPipeTemp.main
def main()
PROGRAM STARTS HERE #.
Definition: grabPipeTemp.py:292
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
grabPipeTemp.perdelta
def perdelta(start, end, delta)
Definition: grabPipeTemp.py:30
grabPipeTemp.checkDates
def checkDates(dataType, dataFolder)
Definition: grabPipeTemp.py:74
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
grabPipeTemp.grabDataStave
def grabDataStave(dataType)
Definition: grabPipeTemp.py:140
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
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
Trk::split
@ split
Definition: LayerMaterialProperties.h:38