CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SequenceVisitors.py
Go to the documentation of this file.
1 #from Modules import OutputModule, EDProducer, EDFilter
2 from SequenceTypes import *
3 from Modules import OutputModule, EDProducer, EDFilter, EDAnalyzer
4 
5 
6 class PathValidator(object):
7  def __init__(self):
8  self.__label = ''
9  def setLabel(self,label):
10  self.__label = "'"+label+"' "
11  def enter(self,visitee):
12  if isinstance(visitee,OutputModule):
13  raise ValueError("Path "+self.__label+"cannot contain an OutputModule, '"+visitee.type_()+"', with label '"+visitee.label_()+"'")
14  if hasattr(visitee, "label_") and not isinstance(visitee,Sequence):
15  if not visitee.hasLabel_():
16  raise ValueError("Path "+self.__label+"contains a module of type '"+visitee.type_()+"' which has no assigned label.\n Most likely the module was never added to the process or it got replaced before being inserted into the process.")
17  def leave(self,visitee):
18  pass
19 
20 class EndPathValidator(object):
21  _presetFilters = ["TriggerResultsFilter", "HLTPrescaler"]
22  def __init__(self):
24  self.__label = ''
25  def setLabel(self,label):
26  self.__label = "'"+label+"' "
27  def enter(self,visitee):
28  if isinstance(visitee,EDFilter):
29  if (visitee.type_() in self._presetFilters):
30  if (visitee.type_() not in self.filtersOnEndpaths):
31  self.filtersOnEndpaths.append(visitee.type_())
32  if hasattr(visitee, "label_") and not isinstance(visitee,Sequence):
33  if not visitee.hasLabel_():
34  raise ValueError("EndPath "+self.__label+"contains a module of type '"+visitee.type_()+"' which has no assigned label.\n Most likely the module was never added to the process or it got replaced before being inserted into the process.")
35  def leave(self,visitee):
36  pass
37 
38 if __name__=="__main__":
39  import unittest
40  class TestModuleCommand(unittest.TestCase):
41  def setUp(self):
42  """Nothing to do """
43  pass
44  def testValidators(self):
45  producer = EDProducer("Producer")
46  analyzer = EDAnalyzer("Analyzer")
47  output = OutputModule("Out")
48  filter = EDFilter("Filter")
49  unlabeled = EDAnalyzer("UnLabeled")
50  producer.setLabel("producer")
51  analyzer.setLabel("analyzer")
52  output.setLabel("output")
53  filter.setLabel("filter")
54  s1 = Sequence(analyzer*producer)
55  s2 = Sequence(output+filter)
56  p1 = Path(s1)
57  p2 = Path(s1*s2)
58  p3 = Path(s1+unlabeled)
59  ep1 = EndPath(producer+output+analyzer)
60  ep2 = EndPath(filter+output)
61  ep3 = EndPath(s2)
62  ep4 = EndPath(unlabeled)
63  pathValidator = PathValidator()
64  endpathValidator = EndPathValidator()
65  p1.visit(pathValidator)
66  self.assertRaises(ValueError, p2.visit, pathValidator)
67  self.assertRaises(ValueError, p3.visit, pathValidator)
68  ep1.visit(endpathValidator)
69  ep2.visit(endpathValidator)
70  ep3.visit(endpathValidator)
71  self.assertRaises(ValueError, ep4.visit, endpathValidator)
72 
73  unittest.main()
74