ATLAS Offline Software
scripts/runInfo.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
4 
5 import sys
6 import time
7 import urllib2,re
8 from PyCool import cool, coral
9 
10 from CoolRunQuery.utils.AtlRunQueryLookup import InitDetectorMaskDecoder
11 
12 print 'Please use the runInfo script from python/runInfo.py!'
13 sys.exit(-1)
14 
15 coolCherryPyRoot='http://coolcherrypy.cern.ch:8080/cooldb/ATLAS_COOLPROD/ATLAS_COOLONL_TDAQ/COMP200/TDAQ/RunCtrl/EOR_Params/timespan/'
16 
17 def sinceUntilStr(runNum):
18  since = ( runNum << 32 )
19  until = ( (runNum+1) << 32 )-1
20  return str(since)+'-'+str(until)
21 
22 
24  httpHeaders={'Accept':'text/xml'}
25  textData=None
26  request=urllib2.Request(url,textData, httpHeaders)
27  u=urllib2.urlopen(request)
28  xmlDocString = u.read()
29  return xmlDocString
30 
31 #never know which xml library is available, so we'll use regex instead
32 def extractValue(xmlString, valueName):
33  regex='<value name="'+valueName+'">(.+)</value>'
34  m=re.search(regex,xmlString)
35  try:
36  return m.group(1)
37  except AttributeError:
38  return None
39 
40 def extractChannelIov(xmlString):
41  regex='<channel .+ since="(\d+)" until="(\d+)"'
42  m=re.search(regex,xmlString)
43  try:
44  return long(m.group(1)), long(m.group(2))
45  except AttributeError:
46  return None
47 
48 
49 def main( runNum=None ):
50  if runNum == None:
51  print 'ERROR no runNumber given'
52  sys.exit(-1)
53  url=coolCherryPyRoot+sinceUntilStr(runNum)+"/channels/0"
54  print 'runInfo from scripts folder'
55  #e.g. : http://coolcherrypy.cern.ch:8080/cooldb/ATLAS_COOLPROD/ATLAS_COOLONL_TDAQ/COMP200/TDAQ/RunCtrl/EOR_Params/timespan/732227499458560-732231794425855/channels/0
56 
57  xmlString = channelValueQuery(url)
58  RunNumber = extractValue(xmlString,'RunNumber')
59  iovstart,iovend = extractChannelIov(xmlString)
60  nLB = iovend - ( iovstart + 1 )
61  ProjectTag = extractValue(xmlString,'FilenameTag' )
62  DetectorMask = extractValue(xmlString,'DetectorMask' )
63 
64  ts1 = long(extractValue(xmlString,"SORTime"))/1000000000L
65  ts2 = long(extractValue(xmlString,"EORTime"))/1000000000L
66  #--- Detector mask
67  mask=long(DetectorMask)
68  dName, NotInAll, vetoedbits = InitDetectorMaskDecoder()
69  res=''
70  signatures={"SCT BA":"SCTBA,", "SCT BC": "SCTBC,", "SCT EA":"SCTEA,", "SCT EC":"SCTEC,"}
71  for i in range(64):
72  if ( mask & (1 << i) ) :
73  for k,v in signatures.iteritems():
74  if k in dName[i] :
75  res += v
76  res = res[:-1] #chop off that last comma
77  if not res: #if res is empty...make it 'NONE'
78  res = 'NONE'
79 
80  #print RunNumber, ProjectTag, ts1, ts2, nLB, res
81  fw = open( 'runInfo.txt', 'w' )
82  fw.write( str(RunNumber) + ' ' + str(ProjectTag) + ' ' + str(ts1) + ' ' + str(ts2) + ' ' + str(nLB) + ' ' + res )
83  fw.close()
84 
85 if __name__ == "__main__":
86  try:
87  runNumber = int( sys.argv[1] )
88  except:
89  print "The run number could not be converted to int"
90  sys.exit(-1)
91 
92  main(runNum = runNumber)
runInfo.main
def main(runNum=None, projectName='')
Definition: python/runInfo.py:10
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
runInfo.extractValue
def extractValue(xmlString, valueName)
Definition: scripts/runInfo.py:32
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
runInfo.extractChannelIov
def extractChannelIov(xmlString)
Definition: scripts/runInfo.py:40
runInfo.channelValueQuery
def channelValueQuery(url)
Definition: scripts/runInfo.py:23
runInfo.sinceUntilStr
def sinceUntilStr(runNum)
Definition: scripts/runInfo.py:17
Trk::open
@ open
Definition: BinningType.h:40
python.utils.AtlRunQueryLookup.InitDetectorMaskDecoder
def InitDetectorMaskDecoder(lhcRun)
Definition: AtlRunQueryLookup.py:171
str
Definition: BTagTrackIpAccessor.cxx:11