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