ATLAS Offline Software
hancool_histo_mod.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 import os
4 
5 # Needed to correct ROOT behavior; see below
6 CWD = os.getcwd()
7 # Importing gSystem may change the current directory to one of the
8 # command-line arguments; chdir to original directory to have
9 # predictable behavior
10 from ROOT import gSystem
11 
12 # Import the ROOT library for reading han results
13 gSystem.Load('libDataQualityUtils')
14 from ROOT import dqutils
15 
16 from DataQualityUtils.hancool_histo_algdef import (ExtractNEntries, ExtractAverage, ExtractNBins, ExtractMean, ExtractEMean, ExtractRMS, ExtractERMS, ExtractPol0, ExtractPol1, ExtractMeanG, ExtractRMSG, ExtractConstG, ExtractSideBands, ExtractTotInt, ExtractXMean, ExtractYMean, ExtractXRMS, ExtractYRMS, ExtractOnlyNBins)
17 # Mapping han<->COOL
18 from DataQualityUtils.hancool_histo_foldermap import folderMapHisto
19 
20 
21 os.chdir(CWD)
22 
23 # LumiBlock length (in minutes)
24 LBlength = 1.0
25 
26 # Mapping Status<->Code
27 codeMap = {
28  "Undefined": 0,
29  "Red": 1,
30  "Yellow": 2,
31  "Green": 3
32 }
33 
34 # Mapping different interval types
35 intervalType = {
36  0: "_minutes30_",
37  1: "_minutes10_",
38  2: "ERROR"
39 }
40 
41 # Generates LB from filename
42 
43 
44 def getLimits(name):
45  global low_limit
46  global hi_limit
47  if (name.find('minutes10_') > -1):
48  t = name.split('minutes10_')
49  digit = float(((t[len(t)-1]).split('_'))[0])
50  low_limit = int((digit-1.0)*10.0/LBlength+1)-1
51  hi_limit = int(digit*10.0/LBlength)
52  elif (name.find('minutes30_') > -1):
53  t = name.split('minutes30_')
54  digit = float(((t[len(t)-1]).split('_'))[0])
55  low_limit = int((digit-1.0)*30.0/LBlength+1)-1
56  hi_limit = int(digit*30.0/LBlength)
57  else:
58  low_limit = 0
59  hi_limit = 4294967295
60  return {"since": low_limit, "until": hi_limit}
61 
62 
63 # Looks up the result in the HanOutputFile
64 def stringGetResult(file, rootFolder):
65  rootFolder = file+":"+rootFolder
66  of = dqutils.HanOutputFile(file)
67  result = of.getStringName(rootFolder)
68  return result
69 
70 
71 def stringGetInfo(file, rootFolder):
72  rootFolder = file+":"+rootFolder
73  of = dqutils.HanOutputFile(file)
74  info = of.getInfo(rootFolder)
75  if (len(info) > 0):
76  return info
77  else:
78  return 'null result'
79 
80 
81 def ListHistoAssessments(xml, channel):
82  the_result_histo = "Undefined"
83  g = open(xml, 'r')
84  while True:
85  line = g.readline()
86  if not line:
87  break
88  if line.find('run') > -1:
89  gg = line.split(':')[1]
90  ww = gg.split(' ')
91  res = ''.join(ww)
92  if res.find(channel) > -1:
93  the_result_histo = res
94  g.close()
95  return the_result_histo
96 
97 
98 def AllHistograms(file):
99  of = dqutils.HanOutputFile(file)
100  resultstrH = of.stringAllHistograms()
101  return resultstrH
102 
103 
105  of = dqutils.HanOutputFile(file)
106  resultstr = of.stringAllDQAssessments()
107  return resultstr
108 
109 
111  of = dqutils.HanOutputFile(file)
112  resultstr = of.stringHistoAssessments()
113  g = open('Allhisto.list', 'w')
114  g.write(resultstr)
115  g.close()
116 
117 
118 def NameHisto_Splitting(channel):
119  t = channel.split('/')
120  N = int(len(t)-1)
121  histo_name = channel.split('/')[N]
122  return histo_name
123 
124 
125 def NamePath_Splitting(channel):
126  t = channel.split('/')
127  N = int(len(t)-1)
128  list_name = channel.split('/')[0:N]
129  path_name = '/'.join(list_name)
130  return path_name
131 
132 # -------------------------------------------------------------
133 # hancool_histo()
134 # -------------------------------------------------------------
135 
136 
137 def hancool_histo(inputFilePath="", input_run=-1, dbConnectionHisto="", dqmfOflHisto="", dbTagName=""):
138 
139  if (input_run == -1):
140  input_run = 52280
141 
142  if (len(inputFilePath) < 1):
143  inputFilePath = "/afs/cern.ch/user/a/atlasdqm/dqmdisk1/han_results/tier0/FDR2b/1/physics_Express/"
144  if (inputFilePath.rfind("/") != (len(inputFilePath)-1)):
145  inputFilePath += "/"
146  if (len(dbConnectionHisto) < 1):
147  dbConnectionHisto = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/w0/users/onofrio/DQMF_08112008/14.2.10/WorkArea/python/MyCOOL_histo_FDR2c.db;dbname=OFLP200"
148 
149  if (len(dqmfOflHisto) < 1):
150  dqmfOflHisto = "/GLOBAL/DETSTATUS/DQMFOFLH"
151  if (len(dbTagName) < 1):
152  dbTagName = "DetStatusDQMFOFLH-FDR2-02"
153 
154  # pdb.set_trace()
156  dbConnectionHisto, dqmfOflHisto, 0, 0, 0, 0)
157  path = inputFilePath
158  run = int(input_run)
159  filename = "run_"+str(run)+"_han.root"
160 
161  # filling OFLH DB for histos (global run)
162  for pair in folderMapHisto.items():
163  i = 0
164  number = 0
165  print(pair[0], pair[1])
166  # print("--------------------------------------")
167  histo_string = NameHisto_Splitting(pair[0])
168  path_string = NamePath_Splitting(pair[0])
169  # print("--------------------------------------")
170  while ((os.path.isfile(path+filename)) and (i < 2)):
171  while os.path.isfile(path+filename):
172  if (getLimits(filename)["until"] == 4294967295):
173  modH.setIOV(run, getLimits(filename)["since"],
174  run, getLimits(filename)["until"])
175  MakeHistoAssessmentsFile(path+filename)
176  xml = 'Allhisto.list'
177  the_result_histo = ListHistoAssessments(xml, pair[0])
178  print(the_result_histo)
179 
180  if (the_result_histo == "Undefined"):
181 
182  print(" This histogram DOES NOT have a corresponding channel in the DB! ")
183  print(" Info cannot be inserted ")
184 
185  else:
186  histo_nameonly = the_result_histo.split(
187  '/')[int(len(the_result_histo.split('/')))-1]
188  print(histo_nameonly)
189  resultH = stringGetResult(
190  path+filename, pair[0]+"_/Results/Status")
191  print(resultH)
192  algo = stringGetResult(
193  path+filename, pair[0]+"_/Config/name")
194  print(algo)
195  entries = ExtractNEntries(
196  path+filename, path_string, histo_string)
197  print(entries)
198  mean_rms = stringGetInfo(
199  path+filename, pair[0]+"_/Results")
200  print(mean_rms)
201 
202  par1 = '0'
203  par2 = '0'
204  par3 = '0'
205  par4 = '0'
206  par5 = '0'
207 
208  if (algo.find('Bins_Diff_FromAvg') > -1 and mean_rms.find('null') < 0):
209  par1 = ExtractAverage(mean_rms)
210  par2 = ExtractNBins(mean_rms)
211  elif (algo.find('GatherData') > -1 and mean_rms.find('null') < 0):
212  if (mean_rms.find('Error') > -1): # new GatherData
213  par1 = ExtractMean(mean_rms)
214  par2 = ExtractEMean(mean_rms)
215  par3 = ExtractRMS(mean_rms)
216  par4 = ExtractERMS(mean_rms)
217  else: # old GatherData
218  par1 = ExtractMean(mean_rms)
219  par2 = ExtractRMS(mean_rms)
220  elif (algo.find('Simple_pol1_Fit') > -1 and mean_rms.find('null') < 0):
221  par1 = ExtractPol0(mean_rms)
222  par2 = ExtractPol1(mean_rms)
223  elif (algo.find('Simple_gaus_Fit') > -1 and mean_rms.find('null') < 0):
224  par1 = ExtractMeanG(mean_rms)
225  par2 = ExtractRMSG(mean_rms)
226  par3 = ExtractConstG(mean_rms)
227  elif (algo.find('SideBand') > -1 and mean_rms.find('null') < 0):
228  par1 = ExtractSideBands(mean_rms)
229  par2 = ExtractTotInt(mean_rms)
230  elif (algo.find('CheckHisto_Mean') > -1 and mean_rms.find('null') < 0):
231  par1 = ExtractXMean(mean_rms)
232  par2 = ExtractYMean(mean_rms)
233  elif (algo.find('CheckHisto_RMS') > -1 and mean_rms.find('null') < 0):
234  par1 = ExtractXRMS(mean_rms)
235  par2 = ExtractYRMS(mean_rms)
236  elif (algo.find('Bin') > -1) and mean_rms.find('null') < 0 and ((algo.find('Threshold') > -1) or (algo.find('ContentComp') > -1)):
237  output = ExtractOnlyNBins(histo_nameonly, mean_rms)
238  par1 = output[0]
239  if (len(output) > 1):
240  par2 = output[1]
241  par3 = output[2]
242  par4 = output[3]
243  par5 = output[4]
244  else:
245  par2 = '0'
246  else:
247  par1 = '0'
248  par2 = '0'
249 # combined algorithms:
250  # CheckHisto_Mean&GatherData
251  if (algo.find('CheckHisto_Mean') > -1 and algo.find('GatherData') > -1 and mean_rms.find('null') < 0):
252  comb_mean_rms = mean_rms.split('XMean: ')
253  if (comb_mean_rms[0].find('Error') > -1): # new GatherData
254  par1 = ExtractMean(comb_mean_rms[0])
255  par2 = ExtractEMean(comb_mean_rms[0])
256  par3 = ExtractRMS(comb_mean_rms[0])
257  par4 = ExtractERMS(comb_mean_rms[0])
258  par5 = ExtractXMean(comb_mean_rms[1])
259  else: # old GatherData
260  par1 = ExtractMean(comb_mean_rms[0])
261  par2 = ExtractRMS(comb_mean_rms[0])
262  par3 = ExtractXMean(comb_mean_rms[1])
263  par4 = ExtractYMean(comb_mean_rms[1])
264  # BinContentComp&GatherData
265  if (algo.find('BinContentComp') > -1 and algo.find('GatherData') > -1 and mean_rms.find('null') < 0):
266  if (mean_rms.find('Error') > -1): # new GatherData
267  par1 = ExtractMean(mean_rms)
268  par2 = ExtractEMean(mean_rms)
269  par3 = ExtractOnlyNBins(
270  histo_nameonly, mean_rms)
271  par4 = ExtractRMS(mean_rms)
272  par5 = ExtractERMS(mean_rms)
273  else: # old GatherData
274  par1 = ExtractMean(mean_rms)
275  par2 = ExtractRMS(mean_rms)
276  par3 = ExtractOnlyNBins(
277  histo_nameonly, mean_rms)
278 
279  codeH = codeMap[resultH]
280 
281  try:
282  float(par1)
283  float(par2)
284  float(par3)
285  float(par4)
286  float(par5)
287  modH.insertH(pair[1], codeH, str(algo), int(entries), float(
288  par1), float(par2), float(par3), float(par4), float(par5), dbTagName)
289  print("----------- global: Insertion successfull! --------------------")
290  print(dbTagName)
291  except Exception:
292  modH.insertH(pair[1], codeH, str(algo), int(
293  entries), 0, 0, 0, 0, 0, dbTagName)
294  print('Could not upload parameters in DB, they are not numbers! Check the algorithm!')
295 
296  number = number+1
297  filename = "run_" + \
298  str(run)+intervalType[i]+str(number)+"_han.root"
299  number = 1
300  i = i+1
301  filename = "run_" + \
302  str(run)+intervalType[i]+str(number)+"_han.root"
303  filename = "run_"+str(run)+"_han.root"
304  print("--------------------------------------")
python.hancool_histo_algdef.ExtractEMean
def ExtractEMean(mean_rms)
Definition: hancool_histo_algdef.py:30
python.hancool_histo_algdef.ExtractYRMS
def ExtractYRMS(mean_rms)
Definition: hancool_histo_algdef.py:100
python.hancool_histo_mod.hancool_histo
def hancool_histo(inputFilePath="", input_run=-1, dbConnectionHisto="", dqmfOflHisto="", dbTagName="")
Definition: hancool_histo_mod.py:137
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
python.hancool_histo_algdef.ExtractERMS
def ExtractERMS(mean_rms)
Definition: hancool_histo_algdef.py:62
python.hancool_histo_algdef.ExtractYMean
def ExtractYMean(mean_rms)
Definition: hancool_histo_algdef.py:119
python.hancool_histo_algdef.ExtractXRMS
def ExtractXRMS(mean_rms)
Definition: hancool_histo_algdef.py:93
python.hancool_histo_algdef.ExtractMean
def ExtractMean(mean_rms)
Definition: hancool_histo_algdef.py:14
python.hancool_histo_mod.ListHistoAssessments
def ListHistoAssessments(xml, channel)
Definition: hancool_histo_mod.py:81
python.hancool_histo_algdef.ExtractRMSG
def ExtractRMSG(mean_rms)
Definition: hancool_histo_algdef.py:176
python.hancool_histo_algdef.ExtractAverage
def ExtractAverage(mean_rms)
Definition: hancool_histo_algdef.py:78
python.hancool_histo_algdef.ExtractNBins
def ExtractNBins(mean_rms)
Definition: hancool_histo_algdef.py:85
dqutils::HanOutputFile
Definition: HanOutputFile.h:32
python.hancool_histo_algdef.ExtractOnlyNBins
def ExtractOnlyNBins(histo_nameonly, mean_rms)
Definition: hancool_histo_algdef.py:185
python.hancool_histo_mod.MakeHistoAssessmentsFile
def MakeHistoAssessmentsFile(file)
Definition: hancool_histo_mod.py:110
python.hancool_histo_algdef.ExtractNEntries
def ExtractNEntries(file, rootFolder, histo_string)
Definition: hancool_histo_algdef.py:252
python.hancool_histo_algdef.ExtractRMS
def ExtractRMS(mean_rms)
Definition: hancool_histo_algdef.py:43
python.hancool_histo_mod.NamePath_Splitting
def NamePath_Splitting(channel)
Definition: hancool_histo_mod.py:125
python.hancool_histo_mod.getLimits
def getLimits(name)
Definition: hancool_histo_mod.py:44
python.hancool_histo_algdef.ExtractPol0
def ExtractPol0(mean_rms)
Definition: hancool_histo_algdef.py:146
python.hancool_histo_mod.AllHistograms
def AllHistograms(file)
Definition: hancool_histo_mod.py:98
python.hancool_histo_algdef.ExtractPol1
def ExtractPol1(mean_rms)
Definition: hancool_histo_algdef.py:153
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
python.hancool_histo_mod.NameHisto_Splitting
def NameHisto_Splitting(channel)
Definition: hancool_histo_mod.py:118
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.hancool_histo_algdef.ExtractMeanG
def ExtractMeanG(mean_rms)
Definition: hancool_histo_algdef.py:168
Trk::open
@ open
Definition: BinningType.h:40
python.hancool_histo_mod.stringGetInfo
def stringGetInfo(file, rootFolder)
Definition: hancool_histo_mod.py:71
python.hancool_histo_mod.stringGetResult
def stringGetResult(file, rootFolder)
Definition: hancool_histo_mod.py:64
python.hancool_histo_mod.AllDQAssessments
def AllDQAssessments(file)
Definition: hancool_histo_mod.py:104
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.hancool_histo_algdef.ExtractTotInt
def ExtractTotInt(mean_rms)
Definition: hancool_histo_algdef.py:138
dqutils::HistogramDataCOOL
Definition: HistogramDataCOOL.h:71
str
Definition: BTagTrackIpAccessor.cxx:11
python.hancool_histo_algdef.ExtractConstG
def ExtractConstG(mean_rms)
Definition: hancool_histo_algdef.py:161
python.hancool_histo_algdef.ExtractSideBands
def ExtractSideBands(mean_rms)
Definition: hancool_histo_algdef.py:131
python.hancool_histo_algdef.ExtractXMean
def ExtractXMean(mean_rms)
Definition: hancool_histo_algdef.py:108
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65