5 The SCT 24h Calibration Loop.
6 This transformation will run the SCT 24 hours calibration loop.
7 Mandatory values as to be given for the input ntuples
8 as well as the output HitMaps and output stream file.
14 from PyJobTransforms.trfArgs
import addAthenaArguments
15 from PyJobTransforms.trfDecorators
import stdTrfExceptionHandler, sigUsrStackTrace
22 import PyJobTransforms.trfExceptions
as trfExceptions
25 from ROOT
import TFile
27 dsDict={
'input': [] ,
'output' : []}
36 """Returns dataset and logical file name for files of type ds##file or ds#dsfile."""
41 if isinstance(file,dict):
46 SvcClass=file.get(
'svcclass',
'')
48 NumberOfEvents+=file[
'events']
50 if file.find(
'##')!=-1:
51 ds=file.split(
'##')[0]
52 name=file.replace(
'##',
'')
53 elif file.find(
'#')!=-1:
55 name=file.split(
'#')[1]
57 if file.find(
'/')!=-1:
58 fileparts=file.split(
'/')
59 ds=fileparts[len(fileparts)-1]
64 if '/eos/atlas/' in name:
65 name=
'root://eosatlas.cern.ch/'+name
67 dsDict[
'input'].
append({
'file' : name,
'dataset' : ds})
71 RunNumber=
int(ds.split(
'.')[1])
72 longStream=ds.split(
'.')[0]
74 Stream=longStream.split(
'_')[1]
79 """Converts list of files of type ds#filename into a list of filenames, meanwhile
80 setting ds value. If check is true it also checks the existence of the files."""
83 if not isinstance(filelist,list):
86 for i,ifile
in enumerate(filelist):
90 if filename.find(
'/castor',0,8) != -1:
92 elif not fileutil.exists(filename):
93 found = fileutil.exists_suffix_number(filename +
'.')
96 errMsg = filename+
' not found'
97 raise trfExceptions.TransformValidationException(trfExit.nameToCode(
'TRF_INPUT_FILE_VALIDATION_FAIL'), errMsg)
108 if os.path.exists(
'/afs/cern.ch/work/s/sctcalib/lastRun'):
109 f =
open(
'/afs/cern.ch/work/s/sctcalib/lastRun',
'w')
110 f.write(
str(RunNumber)+
' ')
113 @stdTrfExceptionHandler
117 msg.info(
"This is %s", sys.argv[0])
119 trf.parseCmdLineArgs(sys.argv[1:])
122 trf.parseCmdLineArgs(sys.argv[1:])
127 msg.info(
"%s stopped at %s, trf exit code %d", sys.argv[0], time.asctime(), trf.exitCode)
128 sys.exit(trf.exitCode)
144 parser.defineArgGroup(
'Calibration',
'Specific options related to the calibration configuration')
146 parser.add_argument(
'--input',
147 help =
'List of CSV input files',group=
'Calibration')
148 parser.add_argument(
'--prefix', type=trfArgClasses.argFactory(trfArgClasses.argString, runarg=
True),
149 help =
'Prefix for output files',group=
'Calibration')
150 parser.add_argument(
'--part', type=trfArgClasses.argFactory(trfArgClasses.argList, runarg=
True),
151 help =
'List of calibration algorithms to be run',group=
'Calibration')
152 parser.add_argument(
'--doRunSelector', type=trfArgClasses.argFactory(trfArgClasses.argBool, runarg=
True),
153 help =
'Specifies if runSelector.py is executed',group=
'Calibration')
154 parser.add_argument(
'--doRunInfo', type=trfArgClasses.argFactory(trfArgClasses.argBool, runarg=
True),
155 help =
'Specifies if runInfo.py is executed',group=
'Calibration')
156 parser.add_argument(
'--splitHitMap', type=trfArgClasses.argFactory(trfArgClasses.argInt,runarg=
True),
157 help =
'Split task or not',group=
'Calibration')
158 parser.add_argument(
'--forceRefRunNumber', type=trfArgClasses.argFactory(trfArgClasses.argBool, runarg=
True),
159 help =
'Force reference run to current run number when checking information uploaded to COOL for previous runs',group=
'Calibration')
163 if 'part' not in dict:
164 checkPart = [
'doNoisyStrip']
166 checkPart = dict[
'part']._value
168 if 'splitHitMap' not in dict:
171 checkSplit = dict[
'splitHitMap']._value
173 if 'prefix' not in dict:
176 checkPrefix=dict[
'prefix']._value
179 if checkPrefix !=
'':
183 if 'doHV' not in checkPart
and checkSplit != 1:
184 parser.add_argument(
'--outputCOOL', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
185 help =
'COOL DB',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'mycool.db'],runarg=
True))
188 if 'doNoisyStrip' in checkPart
and checkSplit == 1:
190 parser.add_argument(
'--outputHITMapFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
191 help =
'HitMap output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTHitMaps.root'],runarg=
True))
192 parser.add_argument(
'--outputLBFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
193 help =
'LB output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTLB.root'],runarg=
True))
195 if 'doNoisyStrip' in checkPart
and checkSplit != 1:
197 parser.add_argument(
'--outputHITMapFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
198 help =
'HitMap output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTHitMaps.root'],runarg=
True))
199 parser.add_argument(
'--outputLBFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
200 help =
'LB output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTLB.root'],runarg=
True))
201 parser.add_argument(
'--outputBSSummaryFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
202 help =
'Bad Strips summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'BadStripsSummaryFile.xml'],runarg=
True))
203 parser.add_argument(
'--outputBSAllFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
204 help =
'Bad Strips All file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'BadStripsAllFile.xml'],runarg=
True))
205 parser.add_argument(
'--outputBSNewFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
206 help =
'Bad Strips New file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'BadStripsNewFile.xml'],runarg=
True))
208 if 'doHV' in checkPart:
209 parser.add_argument(
'--outputBadModulesFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
210 help =
'Bad Modules file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'BadModulesFile.xml'],runarg=
True))
213 if 'doDeadChip' in checkPart
and checkSplit == 1:
214 parser.add_argument(
'--outputHITMapFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
215 help =
'HitMap output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTHitMaps.root'],runarg=
True))
216 parser.add_argument(
'--outputBSErrorsFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
217 help =
'BS Errors file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTBSErrors.root'],runarg=
True))
219 if 'doDeadChip' in checkPart
and checkSplit != 1:
220 parser.add_argument(
'--outputHITMapFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
221 help =
'HitMap output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTHitMaps.root'],runarg=
True))
222 parser.add_argument(
'--outputBSErrorsFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
223 help =
'BS Errors file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTBSErrors.root'],runarg=
True))
224 parser.add_argument(
'--outputDeadChipFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
225 help =
'Dead Chip file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'DeadChipsFile.xml'],runarg=
True))
226 parser.add_argument(
'--outputDeadSummaryFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
227 help =
'Dead Chip Summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'DeadSummaryFile.xml'],runarg=
True))
230 if 'doDeadStrip' in checkPart
and checkSplit == 1:
231 parser.add_argument(
'--outputHITMapFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
232 help =
'HitMap output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTHitMaps.root'],runarg=
True))
233 parser.add_argument(
'--outputBSErrorsFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
234 help =
'BS Errors file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTBSErrors.root'],runarg=
True))
236 if 'doDeadStrip' in checkPart
and checkSplit != 1:
237 parser.add_argument(
'--outputHITMapFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
238 help =
'HitMap output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTHitMaps.root'],runarg=
True))
239 parser.add_argument(
'--outputBSErrorsFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
240 help =
'BS Errors file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTBSErrors.root'],runarg=
True))
241 parser.add_argument(
'--outputDeadStripFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
242 help =
'Dead Strip file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'DeadStripsFile.xml'],runarg=
True))
243 parser.add_argument(
'--outputDeadSummaryFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
244 help =
'Dead Strip Summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'DeadSummaryFile.xml'],runarg=
True))
247 if 'doQuietChip' in checkPart
and checkSplit == 1:
248 parser.add_argument(
'--outputHITMapFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
249 help =
'HitMap output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTHitMaps.root'],runarg=
True))
250 parser.add_argument(
'--outputBSErrorsFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
251 help =
'BS Errors file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTBSErrors.root'],runarg=
True))
253 if 'doQuietChip' in checkPart
and checkSplit != 1:
254 parser.add_argument(
'--outputHITMapFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
255 help =
'HitMap output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTHitMaps.root'],runarg=
True))
256 parser.add_argument(
'--outputBSErrorsFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
257 help =
'BS Errors file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTBSErrors.root'],runarg=
True))
258 parser.add_argument(
'--outputDeadChipFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
259 help =
'Dead Chip file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'QuietChipsFile.xml'],runarg=
True))
260 parser.add_argument(
'--outputDeadSummaryFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
261 help =
'Dead Chip Summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'QuietSummaryFile.xml'],runarg=
True))
264 if 'doQuietStrip' in checkPart
and checkSplit == 1:
265 parser.add_argument(
'--outputHITMapFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
266 help =
'HitMap output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTHitMaps.root'],runarg=
True))
267 parser.add_argument(
'--outputBSErrorsFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
268 help =
'BS Errors file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTBSErrors.root'],runarg=
True))
270 if 'doQuietStrip' in checkPart
and checkSplit != 1:
271 parser.add_argument(
'--outputHITMapFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
272 help =
'HitMap output file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTHitMaps.root'],runarg=
True))
273 parser.add_argument(
'--outputBSErrorsFile', type=trfArgClasses.argFactory(trfArgClasses.argNTUPFile, runarg=
True,io=
'output'),
274 help =
'BS Errors file',group=
'Calibration',default=trfArgClasses.argNTUPFile([checkPrefix+
'SCTBSErrors.root'],runarg=
True))
275 parser.add_argument(
'--outputDeadStripFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
276 help =
'Dead Strip file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'QuietStripsFile.xml'],runarg=
True))
277 parser.add_argument(
'--outputDeadSummaryFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
278 help =
'Dead Strip Summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'QuietSummaryFile.xml'],runarg=
True))
281 if 'doNoiseOccupancy' in checkPart:
282 parser.add_argument(
'--outputNOFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
283 help =
'Noise Occupancy file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'NoiseOccupancyFile.xml'],runarg=
True))
284 parser.add_argument(
'--outputNOSummaryFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
285 help =
'Noise Occupancy Summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'NoiseOccupancySummaryFile.xml'],runarg=
True))
288 if 'doLorentzAngle' in checkPart:
289 parser.add_argument(
'--outputLAFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
290 help =
'Lorentz Angle file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'LorentzAngleFile.xml'],runarg=
True))
291 parser.add_argument(
'--outputLASummaryFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
292 help =
'Lorentz Angle Summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'LorentzAngleSummaryFile.xml'],runarg=
True))
295 if 'doRawOccupancy' in checkPart:
296 parser.add_argument(
'--outputROSummaryFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
297 help =
'Raw Occupancy Summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'RawOccupancySummaryFile.xml'],runarg=
True))
300 if 'doEfficiency' in checkPart:
301 parser.add_argument(
'--outputEffModuleFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
302 help =
'Efficiency file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'EfficiencyModuleSummary.xml'],runarg=
True))
303 parser.add_argument(
'--outputEffSummaryFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
304 help =
'Efficiency Summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'EfficiencySummaryFile.xml'],runarg=
True))
307 if 'doBSErrorDB' in checkPart:
308 parser.add_argument(
'--outputBSModuleFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
309 help =
'BS Errors Summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'BSErrorModuleSummary.xml'],runarg=
True))
310 parser.add_argument(
'--outputBSSummaryFile', type=trfArgClasses.argFactory(trfArgClasses.argFile, runarg=
True,io=
'output'),
311 help =
'BS Errors Summary file',group=
'Calibration',default=trfArgClasses.argFile([checkPrefix+
'BSErrorSummaryFile.xml'],runarg=
True))
315 athenaExecutor.__init__(self,
317 skeletonCA=
'SCT_CalibAlgs.SCTCalib_Skeleton')
321 """ Execute runInfo, set environment and check inputtype"""
323 runArgs=self.conf._argdict
327 for i
in range(0,len(dsDict[
'input'])):
328 namelist.append(dsDict[
'input'][i][
'file'])
330 self.conf.addToArgdict(
'inputNames', trfArgClasses.argList(namelist))
332 nName=namelist[0].
count(
'/')
333 fileName=namelist[0].
split(
'/')[nName]
334 projectName=
str(fileName.split(
'.')[0])
339 if 'doRunInfo' not in runArgs:
340 self.conf.addToArgdict(
'doRunInfo', trfArgClasses.argBool(
False))
342 if runArgs[
'doRunInfo']._value:
343 import SCT_CalibAlgs.runInfo
as runInfo
345 print (
"RunNumber for the runInfo = ",
str(RunNumber),
" ", Stream)
348 if 'splitHitMap' not in runArgs:
349 self.conf.addToArgdict(
'splitHitMap', trfArgClasses.argInt(0))
350 if 'doRunSelector' not in runArgs:
351 self.conf.addToArgdict(
'doRunSelector', trfArgClasses.argBool(
False))
354 if 'EventNumber' not in runArgs:
355 self.conf.addToArgdict(
'EventNumber', trfArgClasses.argInt(0))
358 if SvcClass !=
'' and SvcClass
is not None:
359 os.environ[
'STAGE_SVCCLASS']=SvcClass
362 inputtype=dsDict[
'input'][0][
'dataset'].
split(
'.')[4]
363 print (
"Input type = ", inputtype)
364 self.conf.addToArgdict(
'InputType', trfArgClasses.argString(inputtype))
367 if 'part' not in runArgs:
368 self.conf.addToArgdict(
'part', trfArgClasses.argString(
'doNoisyStrip'))
370 part=runArgs[
'part']._value
373 if ipart
not in [
'doNoisyStrip',
'doNoiseOccupancy',
'doDeadChip',
'doDeadStrip',
'doQuietChip',
'doQuietStrip',
'doHV',
'doBSErrorDB',
'doRawOccupancy',
'doEfficiency',
'doLorentzAngle',
'doNoisyLB']:
374 self.
_errMsg =
'Argument part=%s does not match any of the possible candidates' % ipart
375 raise trfExceptions.TransformValidationException(trfExit.nameToCode(
'TRF_ARG_ERRO'), self.
_errMsg)
378 if 'prefix' not in runArgs:
379 self.conf.addToArgdict(
'prefix', trfArgClasses.argString(
''))
381 prefix=runArgs[
'prefix']._value
387 sep=prefix.find(
'._')
390 elif ( prefix.rfind(
'#_') != -1 ):
391 sep=prefix.rfind(
'#_')
398 elif (prefix.find(
'._') != -1):
399 sep=prefix.rfind(
'._')
404 runArgs[
'prefix']._value = prefix
421 if (
'doNoisyStrip' in part
or 'doDeadStrip' in part
or 'doDeadChip' in part
or 'doQuietStrip' in part
or 'doQuietChip' in part)
and runArgs[
'splitHitMap']._value==2
and NumberOfEvents<1:
423 self._trf._exitCode = 0
424 self._trf._exitMsg =
'Noisy/dead/quiet strips/chips trying to read root files with 0 events. Gracefully exit and update lastRun counter to %s' %(RunNumber)
428 self._trf._dataDictionary = emptyDic
431 self._trf.generateReport(fast=
True)
435 self.conf.addToArgdict(
'JobNumber', trfArgClasses.argString(jobnb))
438 if not RunNumber == -1:
439 self.conf.addToArgdict(
'RunNumber', trfArgClasses.argInt(RunNumber))
441 self.conf.addToArgdict(
'Stream', trfArgClasses.argString(Stream))
444 super(SCTCalibExecutor, self).
preExecute(input,output)
448 runArgs=self.conf._argdict
450 if runArgs[
'doRunSelector']._value:
451 import SCT_CalibAlgs.runSelector
as runSelector
452 part=runArgs[
'part']._value
453 if runArgs[
'splitHitMap']._value == 1 :
460 print (
"Run ", RunNumber,
" didn't pass run selection criteria. It will not be processed and no output will be generated. Finish execution and exit gracefully")
462 self._trf._dataDictionary = emptyDic
465 self._trf._exitMsg =
'Did not pass run selection criteria. Finish execution and exit gracefully.'
466 self._trf._exitCode = 0
468 self._trf.generateReport(fast=
True)
474 for inputFileName
in runArgs[
'input'] :
475 if inputFileName.find(
"SCTHitMaps") != -1:
476 rootHitmapFiles.append(inputFileName)
477 if inputFileName.find(
"SCTLB") != -1:
478 rootLbFiles.append(inputFileName)
479 if inputFileName.find(
"SCTBSErrors") != -1:
480 rootBSerrFiles.append(inputFileName)
482 if runArgs[
'splitHitMap']._value ==2 :
484 if len(rootHitmapFiles) > 0 :
486 fileutil.remove(
'SCTHitMaps.root')
488 cmd =
"cp -v $ROOTSYS/bin/hadd . \n"
489 cmd +=
"hadd -n 10 SCTHitMaps.root "
490 for inputFileName
in rootHitmapFiles :
491 cmd +=
"%s " %(inputFileName)
495 self._echologger.
info(
'Merging Hitmap files!')
498 retcode = os.system(cmd)
502 self._echologger.
info(
'Root merge successful')
504 self._echologger.
error(
"FAILED to merge root files")
506 if ( len(rootLbFiles) > 0
and (len(rootLbFiles) == len(rootHitmapFiles)) ):
508 fileutil.remove(
'SCTLB.root')
510 cmd =
"cp -v $ROOTSYS/bin/hadd . \n"
511 cmd +=
"hadd -n 10 SCTLB.root "
512 for inputFileName
in rootLbFiles :
513 cmd +=
"%s " %(inputFileName)
517 self._echologger.
info(
'Merging LBHitmap files!')
520 retcode = os.system(cmd)
524 self._echologger.
info(
'Root merge successful')
526 self._echologger.
error(
"FAILED to merge root files")
528 if ( len(rootBSerrFiles) > 0
and (len(rootBSerrFiles) == len(rootHitmapFiles)) ):
530 fileutil.remove(
'SCTBSErrors.root')
532 cmd =
"cp -v $ROOTSYS/bin/hadd . \n"
533 cmd +=
"hadd -n 10 SCTBSErrors.root "
534 for inputFileName
in rootBSerrFiles :
535 cmd +=
"%s " %(inputFileName)
539 self._echologger.
info(
'Merging BSerr files!')
542 retcode = os.system(cmd)
546 self._echologger.
info(
'Root merge successful')
548 self._echologger.
error(
"FAILED to merge root files")
550 super(SCTCalibExecutor, self).
execute()
554 if 'less than the required minimum number of events' in open(
'log.sctcalib').
read():
555 self.
_errMsg =
'Successful but warrants further investigation'
556 raise trfExceptions.TransformValidationException(trfExit.nameToCode(
'TRF_UNKOWN'), self.
_errMsg)
557 except trfExceptions.TransformValidationException:
562 runArgs=self.conf._argdict
563 prefix=runArgs[
'prefix']._value
569 listOfKeys = self._trf.dataDictionary
571 if 'doNoisyStrip' in runArgs[
'part']._value
and runArgs[
'splitHitMap']._value == 1:
572 outInstance0 = self.conf.dataDictionary[
list(self._output)[0]]
573 outTFile0 = TFile(outInstance0._value[0])
574 print (outTFile0.GetName())
575 outNentries0 =
int(outTFile0.Get(
'GENERAL/events').
GetEntries())
576 outInstance0._setMetadata(outInstance0._value,{
'nentries': outNentries0})
578 outInstance1 = self.conf.dataDictionary[
list(self._output)[1]]
579 outTFile1 = TFile(outInstance1._value[0])
580 print (outTFile1.GetName())
581 outNentries1 =
int(outTFile1.Get(
'GENERAL/events').
GetEntries())
582 outInstance1._setMetadata(outInstance1._value,{
'nentries': outNentries1})
584 if (
'doDeadStrip' in runArgs[
'part']._value
or 'doDeadChip' in runArgs[
'part']._value
or 'doQuietStrip' in runArgs[
'part']._value
or 'doQuietChip' in runArgs[
'part']._value )
and runArgs[
'splitHitMap']._value == 1:
585 outInstance0 = self.conf.dataDictionary[
list(self._output)[0]]
586 outTFile0 = TFile(outInstance0._value[0])
587 print (outTFile0.GetName())
588 outNentries0 =
int(outTFile0.Get(
'GENERAL/events').
GetEntries())
589 outInstance0._setMetadata(outInstance0._value,{
'nentries': outNentries0})
591 outInstance1 = self.conf.dataDictionary[
list(self._output)[1]]
592 outTFile1 = TFile(outInstance1._value[0])
593 print (outTFile1.GetName())
594 outNentries1 =
int(outTFile1.Get(
'GENERAL/events').
GetEntries())
595 outInstance1._setMetadata(outInstance1._value,{
'nentries': outNentries1})
597 if 'doDeadStrip' in runArgs[
'part']._value
and runArgs[
'splitHitMap']._value != 1:
599 deadFile=pwd+
'/'+prefix+
'.DeadStripsFile.xml'
600 deadSummary=pwd+
'/'+prefix+
'.DeadSummaryFile.xml'
604 if os.path.exists(deadFile):
605 numLinesFile =
sum(1
for line
in open(deadFile))
606 if os.path.exists(deadSummary):
607 numLinesSummary =
sum(1
for line
in open(deadSummary))
612 if ( numLinesFile == 2
and numLinesSummary == 20 ):
613 dataDic = self._trf.dataDictionary
618 listOfKeys.append(key)
620 redDict = {key:dataDic[key]
for key
in listOfKeys}
621 self._trf._dataDictionary = redDict
623 if 'doDeadChip' in runArgs[
'part']._value
and runArgs[
'splitHitMap']._value != 1:
625 deadFile=pwd+
'/'+prefix+
'.DeadChipsFile.xml'
626 deadSummary=pwd+
'/'+prefix+
'.DeadSummaryFile.xml'
630 if os.path.exists(deadFile):
631 numLinesFile =
sum(1
for line
in open(deadFile))
632 if os.path.exists(deadSummary):
633 numLinesSummary =
sum(1
for line
in open(deadSummary))
638 if ( numLinesFile == 2
and numLinesSummary == 20 ):
639 dataDic = self._trf.dataDictionary
644 listOfKeys.append(key)
646 redDict = {key:dataDic[key]
for key
in listOfKeys}
647 self._trf._dataDictionary = redDict
649 if 'doQuietStrip' in runArgs[
'part']._value
and runArgs[
'splitHitMap']._value != 1:
651 deadFile=pwd+
'/'+prefix+
'.QuietStripsFile.xml'
652 deadSummary=pwd+
'/'+prefix+
'.QuietSummaryFile.xml'
656 if os.path.exists(deadFile):
657 numLinesFile =
sum(1
for line
in open(deadFile))
658 if os.path.exists(deadSummary):
659 numLinesSummary =
sum(1
for line
in open(deadSummary))
664 if ( numLinesFile == 2
and numLinesSummary == 20 ):
665 dataDic = self._trf.dataDictionary
670 listOfKeys.append(key)
672 redDict = {key:dataDic[key]
for key
in listOfKeys}
673 self._trf._dataDictionary = redDict
675 if 'doQuietChip' in runArgs[
'part']._value
and runArgs[
'splitHitMap']._value != 1:
677 deadFile=pwd+
'/'+prefix+
'.QuietChipsFile.xml'
678 deadSummary=pwd+
'/'+prefix+
'.QuietSummaryFile.xml'
682 if os.path.exists(deadFile):
683 numLinesFile =
sum(1
for line
in open(deadFile))
684 if os.path.exists(deadSummary):
685 numLinesSummary =
sum(1
for line
in open(deadSummary))
690 if ( numLinesFile == 2
and numLinesSummary == 20 ):
691 dataDic = self._trf.dataDictionary
696 listOfKeys.append(key)
698 redDict = {key:dataDic[key]
for key
in listOfKeys}
699 self._trf._dataDictionary = redDict
703 if runArgs[
'splitHitMap']._value !=1
and 'COOL' in listOfKeys:
704 os.rename(
'mycool.db',prefix+
'.mycool.db')
705 if runArgs[
'splitHitMap']._value == 2:
706 os.rename(
'SCTHitMaps.root',prefix+
'.SCTHitMaps.root')
707 if 'doNoisyStrip' in runArgs[
'part']._value:
708 os.rename(
'SCTLB.root',prefix+
'.SCTLB.root')
709 if (
'doDeadStrip' in runArgs[
'part']._value
or 'doDeadChip' in runArgs[
'part']._value
or 'doQuietStrip' in runArgs[
'part']._value
or 'doQuietChip' in runArgs[
'part']._value ):
710 os.rename(
'SCTBSErrors.root',prefix+
'.SCTBSErrors.root')
712 self._echologger.warning(
'failed to rename DB, ROOT or LOG file.' )
718 deferredException =
None
720 if 'ignorePatterns' in self.conf._argdict:
721 igPat = self.conf.argdict[
'ignorePatterns'].value
724 if 'ignoreFiles' in self.conf._argdict:
725 ignorePatterns = trfValidation.ignorePatterns(files = self.conf._argdict[
'ignoreFiles'].value, extraSearch=igPat)
726 elif self._errorMaskFiles
is not None:
727 ignorePatterns = trfValidation.ignorePatterns(files = self._errorMaskFiles, extraSearch=igPat)
729 ignorePatterns = trfValidation.ignorePatterns(files = athenaExecutor._defaultIgnorePatternFile, extraSearch=igPat)
732 msg.info(
'Scanning logfile {0} for errors'.
format(self._logFileName))
733 self.
_logScan = trfValidation.athenaLogFileReport(logfile = self._logFileName, ignoreList = ignorePatterns)
734 worstError = self.
_logScan.worstError()
738 if worstError[
'firstError']:
739 if len(worstError[
'firstError'][
'message']) > athenaExecutor._exitMessageLimit:
740 if 'CoreDumpSvc' in worstError[
'firstError'][
'message']:
741 exitErrorMessage =
"Core dump at line {0} (see jobReport for further details)".
format(worstError[
'firstError'][
'firstLine'])
742 elif 'G4Exception' in worstError[
'firstError'][
'message']:
743 exitErrorMessage =
"G4 exception at line {0} (see jobReport for further details)".
format(worstError[
'firstError'][
'firstLine'])
745 exitErrorMessage =
"Long {0} message at line {1} (see jobReport for further details)".
format(worstError[
'level'], worstError[
'firstError'][
'firstLine'])
747 exitErrorMessage =
"Logfile error in {0}: \"{1}\"".
format(self._logFileName, worstError[
'firstError'][
'message'])
749 exitErrorMessage =
"Error level {0} found (see athena logfile for details)".
format(worstError[
'level'])
752 if deferredException
is not None:
754 if worstError[
'nLevel'] >= stdLogLevels[
'ERROR']:
755 deferredException.errMsg = deferredException.errMsg +
"; {0}".
format(exitErrorMessage)
756 raise deferredException
762 if worstError[
'firstError']
is not None:
763 if 'ERROR Unknown offlineId for OnlineId' in worstError[
'firstError'][
'message']:
764 worstError[
'nLevel'] = 30
765 worstError[
'level'] =
'WARNING'
768 if worstError[
'nLevel'] == stdLogLevels[
'ERROR']
and (
'ignoreErrors' in self.conf._argdict
and self.conf._argdict[
'ignoreErrors'].value
is True):
769 msg.warning(
'Found ERRORs in the logfile, but ignoring this as ignoreErrors=True (see jobReport for details)')
770 elif worstError[
'nLevel'] >= stdLogLevels[
'ERROR']:
772 msg.error(
'Fatal error in athena logfile (level {0})'.
format(worstError[
'level']))
773 raise trfExceptions.TransformLogfileErrorException(trfExit.nameToCode(
'TRF_EXEC_LOGERROR'),
774 ' Fatal error in athena logfile: "{0}"'.
format(exitErrorMessage))
777 msg.info(
'Executor {0} has validated successfully'.
format(self.name))
780 if __name__ ==
"__main__":