14from DQConfMakerBase.DQElements
import DQReference, DQRegion, DQAlgorithm
54 returns True if we should kill this node
55 False if we should not
57 params = dqregion.getDQParameters()
60 subregions = dqregion.getSubRegions()
61 if subregions
is None:
64 subregions = subregions[:]
70 dqregion.delRelation(
'DQRegions', sr)
71 subregions = dqregion.getSubRegions()
72 if subregions
is None:
74 if len(subregions) + len(params) == 0:
89def process(infname, confname, reffile=None):
90 f = ROOT.TFile(infname,
'READ')
92 print(
'ERROR: cannot open %s' % infname)
95 top_level = DQRegion(id=
'topRegion',algorithm=worst)
96 print(
'Building tree...')
97 recurse(f, top_level, f.GetPath(), reffile)
98 print(
'Pruning dead branches...')
102 sublevel = top_level.getSubRegions()[:]
104 top_level.delRelation(
'DQRegions', x)
106 print(
'Writing output')
107 writeHanConfiguration( filename = confname , roots = sublevel)
111 import shutil, os, sys, contextlib
113 han_is_found = (ROOT.gSystem.Load(
'libDataQualityInterfaces') == 0)
115 print(
'ERROR: unable to load offline DQMF; unable to proceed')
117 bname = os.path.basename(fname)
125 prebuilt_hcfg =
False
127 @contextlib.contextmanager
130 td = tempfile.mkdtemp()
134 with tmpdir()
as hantmpdir:
136 print(
'====> Processing file %s' % (fname))
137 print(
'====> Generating han configuration file')
138 hantmpinput = os.path.join(hantmpdir, bname)
139 shutil.copyfile(fname, hantmpinput)
140 haninput = hantmpinput
141 hanconfig = os.path.join(hantmpdir,
'han.config')
142 rv =
process(hantmpinput, hanconfig, options.reffile)
145 print(
'No histograms to display; exiting with code 0')
148 print(
'====> Compiling han configuration')
149 hanhcfg = os.path.join(hantmpdir,
'han.hcfg')
151 ROOT.dqi.HanConfig().AssembleAndSave( hanconfig, hanhcfg )
153 print(
'====> Executing han')
155 memlimit = resource.getrlimit(resource.RLIMIT_AS)
156 resource.setrlimit(resource.RLIMIT_AS, (memlimit[1], memlimit[1]))
157 hanoutput = haninput.rpartition(
'.')[0] +
'_han.root'
159 rv = ROOT.dqi.HanApp().Analyze( hanhcfg, haninput, hanoutput,
'' )
162 raise Exception(
'failure in han')
163 hantargetdir = os.path.join(options.webdir, str(options.iteration),
164 options.dispname,
'run_%s' % run)
165 print(
'====> Copying to', hantargetdir)
166 hantargetfile = os.path.join(hantargetdir,
'run_%s_han.root' % run)
167 if not os.access(hantargetdir, os.W_OK):
169 os.makedirs(hantargetdir)
170 except Exception
as e:
171 print(
'Unable to create %s for some reason: %s' % (hantargetdir, e))
172 raise Exception(
'Error during execute')
173 shutil.copy2(hanoutput, hantargetfile)
174 print(
'====> Cleaning up')
175 except Exception
as e:
177 if 'canonical format' not in str(e):
181 if not prebuilt_hcfg:
182 os.unlink(hantmpinput)