ATLAS Offline Software
Functions
python.output.AtlRunQuerySave Namespace Reference

Functions

def CreateResultDict (runlist)
 
def AddUpEvents (runlist)
 
def SaveResultTxt (runlist, header)
 
def SaveTypelessPickleResult (pdic, filename='atlrunquery.pickle')
 
def SaveResultAsJson (result, filename='atlrunquery.json')
 
def CreateDic (runlist, header)
 
def basic (v)
 
def CreateDictForPickling (dic)
 
def CreateSummary (dic)
 

Function Documentation

◆ AddUpEvents()

def python.output.AtlRunQuerySave.AddUpEvents (   runlist)

Definition at line 57 of file AtlRunQuerySave.py.

57 def AddUpEvents(runlist):
58  # Sum up total event numbers
59  for run in runlist:
60  try:
61  Run.totevents[0] += int(run.result["#Events"])
62  except ValueError:
63  Run.totevents[1] += 1
64 
65 
66 

◆ basic()

def python.output.AtlRunQuerySave.basic (   v)

Definition at line 166 of file AtlRunQuerySave.py.

166 def basic(v):
167  if hasattr(v,'pickled'):
168  return v.pickled()
169  return v
170 

◆ CreateDic()

def python.output.AtlRunQuerySave.CreateDic (   runlist,
  header 
)

Definition at line 145 of file AtlRunQuerySave.py.

145 def CreateDic(runlist, header):
146  # create keys for pickle dictionary
147  dic = {}
148  for r in runlist:
149  for k in header:
150  if k == 'Run':
151  scontent = {"runNr": r.runNr, "lastLB": r.lastlb, "dataPeriod": "tbd", "lhcRun": r.lhcRun}
152  elif k == 'Links':
153  scontent = ""
154  elif k == '#LB':
155  scontent = (r.lastlb, [(lbtime[0]-r.lbtimes[0][0])*1e-9 for lbtime in r.lbtimes] + [ (r.lbtimes[-1][1]-r.lbtimes[0][0])*1e-9 ] )
156  elif k == 'Start and endtime':
157  scontent = r.timestr('seconds')
158  elif k == 'Duration':
159  scontent = r.durationstr()
160  else:
161  scontent = r.data[k.ResultKey]
162  dic.setdefault(k,[]).append(scontent)
163  return dic
164 
165 

◆ CreateDictForPickling()

def python.output.AtlRunQuerySave.CreateDictForPickling (   dic)

Definition at line 171 of file AtlRunQuerySave.py.

171 def CreateDictForPickling(dic):
172  dic_basic = {'Run': [ r["runNr"] for r in dic[DataKey('Run')]]}
173 
174  for i,r in enumerate(dic_basic['Run']):
175  dic_basic[r] = dict([ ( k.pickled(), basic(v[i]) ) for k,v in dic.items()])
176 
177  return dic_basic
178 
179 
180 
181 
182 

◆ CreateResultDict()

def python.output.AtlRunQuerySave.CreateResultDict (   runlist)

Definition at line 22 of file AtlRunQuerySave.py.

22 def CreateResultDict( runlist ):
23 
24  if len(runlist)==0:
25  return {}, {}
26 
27  print("Creating results in path '%s'" % QC.datapath )
28 
29  # define the header
30  header = []
31  excludelist = []
32  if Run.showrunnr:
33  header += [DataKey(x) for x in ['Run', 'Links', '#LB']]
34  if Run.showtime:
35  header += [DataKey('Start and endtime')]
36  if Run.showduration:
37  header += [DataKey('Duration')]
38  header += [k for k in Run.ShowOrder if k not in excludelist]
39 
40  AddUpEvents(runlist)
41 
42  SaveResultTxt(runlist, header)
43 
44  dic = CreateDic(runlist, header)
45 
46  SaveResultAsJson(dic)
47 
48  summary = CreateSummary(dic)
49 
50  dic_basic = CreateDictForPickling(dic)
51 
52  SaveTypelessPickleResult(dic_basic)
53 
54  return dic, summary
55 
56 

◆ CreateSummary()

def python.output.AtlRunQuerySave.CreateSummary (   dic)

Definition at line 183 of file AtlRunQuerySave.py.

183 def CreateSummary(dic):
184  # create summary
185  dicsum = {}
186  for key, results in dic.items():
187  if key.ResultKey in ['SMK','HLT PSK','L1 PSK','TorCurrent','SolCurrent','BGS Key','#LB']:
188  continue
189  if key.Type==DataKey.DETECTOR:
190  continue
191  for r in results:
192  if key=='Run':
193  dicsum.setdefault(key,0)
194  dicsum[key] += 1
195  elif key.Type == DataKey.STREAM:
196  entry = r[0]
197  if entry is None or entry.value == 'n.a.':
198  continue
199  dicsum.setdefault(key,[0,0])
200  dicsum[key][0] += entry.value[0]
201  dicsum[key][1] += entry.value[1]
202  else:
203  try:
204  ir = int(r)
205  if key not in dicsum:
206  dicsum[key] = 0
207  dicsum[key] += ir
208  except (ValueError, TypeError):
209  pass
210  return dicsum

◆ SaveResultAsJson()

def python.output.AtlRunQuerySave.SaveResultAsJson (   result,
  filename = 'atlrunquery.json' 
)

Definition at line 104 of file AtlRunQuerySave.py.

104 def SaveResultAsJson( result, filename = 'atlrunquery.json'):
105  # write json output
106 
107  # ignoring a few large ones for now and one that is not working
108  # large ones should be stored better
109  ignoreForNow = [
110  # "lhc:fillnumber",
111  # "lhc:stablebeams",
112  "lhc:beamenergy", # large
113  "olc:lumi:0", # large
114  "olc:beam1intensity", # large
115  "olc:beam2intensity", # large
116  # "olc:beam1bunches",
117  # "olc:beam2bunches",
118  # "olc:collbunches",
119  "olc:bcidmask" # broken
120  ]
121 
122  runs = [r["runNr"] for r in result[DataKey("Run")]]
123  store = { runNr:{} for runNr in runs}
124 
125  for datakey in result:
126  key = datakey.pickled()
127  if key in ignoreForNow:
128  print("Not storing in json file: ", key)
129  continue
130 
131  for (runNr, x) in zip(runs, result[datakey]):
132  if isinstance(x, (DataEntry,DataEntryList)):
133  store[runNr][key] = x.json()
134  else:
135  store[runNr][key] = x
136 
137  with open( '%s/atlrunquery.json' % QC.datapath, 'w' ) as pf:
138  try:
139  import json
140  json.dump(store, pf)
141  except Exception as e:
142  print ('ERROR: could not create json file with results: "%r"' % e)
143 
144 

◆ SaveResultTxt()

def python.output.AtlRunQuerySave.SaveResultTxt (   runlist,
  header 
)

Definition at line 67 of file AtlRunQuerySave.py.

67 def SaveResultTxt(runlist, header):
68  # write header to text file
69  f = open( '%s/QueryResult.txt' % QC.datapath, 'w' )
70  print ("data keys:", ', '.join([h.ResultKey for h in header]), file=f)
71  print ('number of runs: %i' % len(runlist), file=f)
72 
73  # now get the values for each run and write to file
74  for r in runlist:
75  line = []
76  if Run.showrunnr:
77  line += ["%i" % r.runNr, "", "%i" % r.lastlb]
78  if Run.showtime:
79  line += ["%s" % r.timestr('seconds')]
80  if Run.showduration:
81  line += ["%s" % r.durationstr()]
82  for k in Run.ShowOrder:
83  line += [r.data[k.ResultKey]]
84  for head,item in zip(header,line):
85  if isinstance(item,tuple):
86  item = '|'.join([str(x) for x in item])
87  print ('%40s: %s' % (head.ResultKey, item), file=f)
88  print ('\n', file=f)
89  f.close()
90 
91 
92 
93 

◆ SaveTypelessPickleResult()

def python.output.AtlRunQuerySave.SaveTypelessPickleResult (   pdic,
  filename = 'atlrunquery.pickle' 
)

Definition at line 94 of file AtlRunQuerySave.py.

94 def SaveTypelessPickleResult(pdic, filename = 'atlrunquery.pickle'):
95  # write pickle output
96  pf = open( '%s/atlrunquery.pickle' % QC.datapath, 'wb' )
97  try:
98  pickle.dump(pdic, pf)
99  except Exception as e:
100  print ('ERROR: could not pickle results dictionary: "%r"' % e)
101  sys.exit(1)
102  pf.close()
103 
python.output.AtlRunQuerySave.CreateDic
def CreateDic(runlist, header)
Definition: AtlRunQuerySave.py:145
python.output.AtlRunQuerySave.CreateResultDict
def CreateResultDict(runlist)
Definition: AtlRunQuerySave.py:22
python.output.AtlRunQuerySave.AddUpEvents
def AddUpEvents(runlist)
Definition: AtlRunQuerySave.py:57
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.output.AtlRunQuerySave.SaveTypelessPickleResult
def SaveTypelessPickleResult(pdic, filename='atlrunquery.pickle')
Definition: AtlRunQuerySave.py:94
python.output.AtlRunQuerySave.SaveResultAsJson
def SaveResultAsJson(result, filename='atlrunquery.json')
Definition: AtlRunQuerySave.py:104
python.output.AtlRunQuerySave.SaveResultTxt
def SaveResultTxt(runlist, header)
Definition: AtlRunQuerySave.py:67
python.output.AtlRunQuerySave.CreateSummary
def CreateSummary(dic)
Definition: AtlRunQuerySave.py:183
python.output.AtlRunQuerySave.CreateDictForPickling
def CreateDictForPickling(dic)
Definition: AtlRunQuerySave.py:171
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
str
Definition: BTagTrackIpAccessor.cxx:11
python.output.AtlRunQuerySave.basic
def basic(v)
Definition: AtlRunQuerySave.py:166