565 def _hanAddDQParameter(handocument, dqparameter, output=DQHanConfMaker._default_output):
567 Add a DQParameter object to a HanDocument, Doing this it creates the tree of
571 if dqparameter.type !=
"DQParameter":
572 raise HanCannotCreateConf(
573 "Object: "+
str(dqparameter)+
" type does not match 'DQParameter'")
575 histoname = dqparameter.getInput().
split(
'/')
578 for directory
in histoname[0:len(histoname)-1]:
579 subdir = theDir.getSubDir(directory)
581 subdir = theDir.addSubDir(directory)
584 algo = dqparameter.getAlgorithm()
586 raise Exception(
'DQParameter without DQAlgorithm')
587 dqalgoname, dqalgolibrary = algo.id, algo.getLibraryName()
589 dqrefname, dqreference, refs =
"", dqparameter.getReference(), []
590 if dqreference != [
None]:
591 refs =
'[%s]' % (
','.
join(_.id
for _
in dqreference))
592 for iref
in dqreference:
595 if handocument.getReference(ref)
is None:
597 refcompletename = iref.getReference()
598 filename = refcompletename.rpartition(
':')[0]
599 refhistoname = refcompletename.rpartition(
':')[
601 hanref = HanReference(
602 ref, histogramname=refhistoname, file=filename,
603 info=iref.getAnnotation(
'info'))
604 handocument.appendChild(hanref)
609 warnings = toList(dqparameter.getWarnings())
610 errors = toList(dqparameter.getErrors())
611 thresholds, hanthreshold, thresholdsname =
'',
None,
''
612 if (warnings != [
None])
and (errors != [
None]):
614 thresholds = dqparameter.id.replace(
615 '_',
'__').
replace(
'/',
'_')+
'_thr'
616 hanthreshold = HanThreshold(thresholds)
617 thresholdsname = thresholds
618 thresholds =
'_'+thresholds
620 def getCorrespondingRed(warningname):
622 if e.getAttribute(
'Name')[1] == warningname:
625 for warning
in warnings:
626 warningname = warning.getAttribute(
'Name')[1]
627 error = getCorrespondingRed(warningname)
629 raise HanCannotCreateConf(
630 'Cannot find corresponding error for warning names: '+warning.id)
631 hanthreshold.addLimit(warningname, warning.getAttribute(
632 'Value')[1], error.getAttribute(
'Value')[1])
634 handocument.appendChild(hanthreshold)
637 parameterstr =
'_'.
join([x.id
for x
in toList(
638 dqparameter.getAlgorithmParameters())
if x
is not None])
640 for x
in toList(dqparameter.getAlgorithmParameters()):
643 parameters[x.getName()[1]] = x.getValue()[1][0]
645 hanalgoname = (
"%s_%s%s%s%s" % (dqalgolibrary, dqalgoname,
646 dqrefname, thresholds.replace(
'/',
'_'), parameterstr))
648 theDir.addHistogram(histogram=histoname[len(histoname)-1], algorithm=hanalgoname,
649 annotations=dqparameter.getAllAnnotations(), output=output, attributes=dqparameter.getAllAttributes())
651 if handocument.getAlgorithm(hanalgoname)
is None:
653 node = HanAlgorithm(name=hanalgoname, algoname=dqalgoname, libname=dqalgolibrary,
654 reference=refs, thresholds=thresholdsname, parameters=parameters)
655 handocument.appendChild(node)
657 compalg = algo.getCompositeAlgorithm()
658 if compalg
is not None:
659 node = HanCompositeAlgorithm(name=compalg.id, subalgnames=compalg.getSubAlgNames(),
660 libnames=compalg.getLibNames())
661 handocument.appendChild(node)
662 except Exception
as msg:
663 raise HanCannotCreateConf(
664 "Object: "+
str(dqparameter)+
" is not a valid DQParameter. Reason: "+
str(msg))