567 Add a DQParameter object to a HanDocument, Doing this it creates the tree of
571 if dqparameter.type !=
"DQParameter":
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(
':')[
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'
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)
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:
660 libnames=compalg.getLibNames())
661 handocument.appendChild(node)
662 except Exception
as msg:
664 "Object: "+str(dqparameter)+
" is not a valid DQParameter. Reason: "+str(msg))
724 Writes the configuration to a han file.
725 The configuration has to be passed as a list of roots in han configuration.
729 for element
in configList:
731 if not DQHanConfMaker._isAceptedHanElement(element):
732 print(
"==========WARNING===========")
735 " does not have a valid han representation, cannot save")
736 print(
"The object is referenced by:", element.isReferencedBy)
737 print(
"You may need to manually edit the configuration")
738 print(
"============================")
739 configList.remove(element)
741 print(element.isReferencedBy)
749 def _addchild(hanfather, dqregion, handocument):
750 outputalgo = dqregion.getAlgorithm()
751 if handocument.getAlgorithm(outputalgo.id)
is None:
756 outputalgo.id, outputalgo.id, outputalgo.getLibraryName()))
757 output = hanfather.addOutput(dqregion.id, outputalgo.id, annotations=dqregion.getAllAnnotations(
758 ), attributes=dqregion.getAllAttributes())
760 for subregion
in dqregion.getSubRegions():
761 if subregion
is not None:
762 _addchild(output, subregion, doc)
764 for parameter
in dqregion.getDQParameters():
765 if parameter
is not None:
767 output=output.getOutputPath())
769 for region
in rootregions:
770 _addchild(doc, region, doc)
772 fileout = open(filename,
'w')
773 print(doc.toprettyhan(
" "), file=fileout)