567 def _hanAddDQParameter(handocument, dqparameter, output=DQHanConfMaker._default_output):
569 Add a DQParameter object to a HanDocument, Doing this it creates the tree of
573 if dqparameter.type !=
"DQParameter":
574 raise HanCannotCreateConf(
575 "Object: "+
str(dqparameter)+
" type does not match 'DQParameter'")
577 histoname = dqparameter.getInput().
split(
'/')
580 for directory
in histoname[0:len(histoname)-1]:
581 subdir = theDir.getSubDir(directory)
583 subdir = theDir.addSubDir(directory)
586 algo = dqparameter.getAlgorithm()
588 raise Exception(
'DQParameter without DQAlgorithm')
589 dqalgoname, dqalgolibrary = algo.id, algo.getLibraryName()
591 dqrefname, dqreference, refs =
"", dqparameter.getReference(), []
592 if dqreference != [
None]:
593 refs =
'[%s]' % (
','.
join(_.id
for _
in dqreference))
594 for iref
in dqreference:
597 if handocument.getReference(ref)
is None:
599 refcompletename = iref.getReference()
600 filename = refcompletename.rpartition(
':')[0]
601 refhistoname = refcompletename.rpartition(
':')[
603 hanref = HanReference(
604 ref, histogramname=refhistoname, file=filename,
605 info=iref.getAnnotation(
'info'))
606 handocument.appendChild(hanref)
611 warnings = toList(dqparameter.getWarnings())
612 errors = toList(dqparameter.getErrors())
613 thresholds, hanthreshold, thresholdsname =
'',
None,
''
614 if (warnings != [
None])
and (errors != [
None]):
616 thresholds = dqparameter.id.replace(
617 '_',
'__').
replace(
'/',
'_')+
'_thr'
618 hanthreshold = HanThreshold(thresholds)
619 thresholdsname = thresholds
620 thresholds =
'_'+thresholds
622 def getCorrespondingRed(warningname):
624 if e.getAttribute(
'Name')[1] == warningname:
627 for warning
in warnings:
628 warningname = warning.getAttribute(
'Name')[1]
629 error = getCorrespondingRed(warningname)
631 raise HanCannotCreateConf(
632 'Cannot find corresponding error for warning names: '+warning.id)
633 hanthreshold.addLimit(warningname, warning.getAttribute(
634 'Value')[1], error.getAttribute(
'Value')[1])
636 handocument.appendChild(hanthreshold)
639 parameterstr =
'_'.
join([x.id
for x
in toList(
640 dqparameter.getAlgorithmParameters())
if x
is not None])
642 for x
in toList(dqparameter.getAlgorithmParameters()):
645 parameters[x.getName()[1]] = x.getValue()[1][0]
647 hanalgoname = (
"%s_%s%s%s%s" % (dqalgolibrary, dqalgoname,
648 dqrefname, thresholds.replace(
'/',
'_'), parameterstr))
650 theDir.addHistogram(histogram=histoname[len(histoname)-1], algorithm=hanalgoname,
651 annotations=dqparameter.getAllAnnotations(), output=output, attributes=dqparameter.getAllAttributes())
653 if handocument.getAlgorithm(hanalgoname)
is None:
655 node = HanAlgorithm(name=hanalgoname, algoname=dqalgoname, libname=dqalgolibrary,
656 reference=refs, thresholds=thresholdsname, parameters=parameters)
657 handocument.appendChild(node)
659 compalg = algo.getCompositeAlgorithm()
660 if compalg
is not None:
661 node = HanCompositeAlgorithm(name=compalg.id, subalgnames=compalg.getSubAlgNames(),
662 libnames=compalg.getLibNames())
663 handocument.appendChild(node)
664 except Exception
as msg:
665 raise HanCannotCreateConf(
666 "Object: "+
str(dqparameter)+
" is not a valid DQParameter. Reason: "+
str(msg))