565def _hanAddDQParameter(handocument, dqparameter, output=DQHanConfMaker._default_output):
566 """
567 Add a DQParameter object to a HanDocument, Doing this it creates the tree of
568 dir and output.
569 """
570 try:
571 if dqparameter.type != "DQParameter":
572 raise HanCannotCreateConf(
573 "Object: "+str(dqparameter)+" type does not match 'DQParameter'")
574
575 histoname = dqparameter.getInput().
split(
'/')
576 theDir = handocument
577
578 for directory in histoname[0:len(histoname)-1]:
579 subdir = theDir.getSubDir(directory)
580 if subdir is None:
581 subdir = theDir.addSubDir(directory)
582 theDir = subdir
583
584 algo = dqparameter.getAlgorithm()
585 if algo is None:
586 raise Exception('DQParameter without DQAlgorithm')
587 dqalgoname, dqalgolibrary = algo.id, algo.getLibraryName()
588
589 dqrefname, dqreference, refs = "", dqparameter.getReference(), []
590 if dqreference != [None]:
591 refs = '[%s]' % (','.join(_.id for _ in dqreference))
592 for iref in dqreference:
593 ref = iref.id
594
595 if handocument.getReference(ref) is None:
596
597 refcompletename = iref.getReference()
598 filename = refcompletename.rpartition(':')[0]
599 refhistoname = refcompletename.rpartition(':')[
600 2].lstrip('/')
601 hanref = HanReference(
602 ref, histogramname=refhistoname, file=filename,
603 info=iref.getAnnotation('info'))
604 handocument.appendChild(hanref)
605 dqrefname = '_'+ref
606
607
608
609 warnings = toList(dqparameter.getWarnings())
610 errors = toList(dqparameter.getErrors())
611 thresholds, hanthreshold, thresholdsname = '', None, ''
612 if (warnings != [None]) and (errors != [None]):
613
614 thresholds = dqparameter.id.replace(
615 '_',
'__').
replace(
'/',
'_')+
'_thr'
616 hanthreshold = HanThreshold(thresholds)
617 thresholdsname = thresholds
618 thresholds = '_'+thresholds
619
620 def getCorrespondingRed(warningname):
621 for e in errors:
622 if e.getAttribute('Name')[1] == warningname:
623 return e
624 return None
625 for warning in warnings:
626 warningname = warning.getAttribute('Name')[1]
627 error = getCorrespondingRed(warningname)
628 if error is None:
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])
633
634 handocument.appendChild(hanthreshold)
635
636
637 parameterstr = '_'.join([x.id for x in toList(
638 dqparameter.getAlgorithmParameters()) if x is not None])
639 parameters = {}
640 for x in toList(dqparameter.getAlgorithmParameters()):
641 if x is None:
642 continue
643 parameters[x.getName()[1]] = x.getValue()[1][0]
644
645 hanalgoname = ("%s_%s%s%s%s" % (dqalgolibrary, dqalgoname,
646 dqrefname, thresholds.replace('/', '_'), parameterstr))
647
648 theDir.addHistogram(histogram=histoname[len(histoname)-1], algorithm=hanalgoname,
649 annotations=dqparameter.getAllAnnotations(), output=output, attributes=dqparameter.getAllAttributes())
650
651 if handocument.getAlgorithm(hanalgoname) is None:
652
653 node = HanAlgorithm(name=hanalgoname, algoname=dqalgoname, libname=dqalgolibrary,
654 reference=refs, thresholds=thresholdsname, parameters=parameters)
655 handocument.appendChild(node)
656
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))
665
666
667
668
669
670
671
672
std::string replace(std::string s, const std::string &s2, const std::string &s3)
std::vector< std::string > split(const std::string &s, const std::string &t=":")