CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/FWCore/ParameterSet/python/SequenceVisitors.py

Go to the documentation of this file.
00001 #from Modules import OutputModule, EDProducer, EDFilter
00002 from SequenceTypes import *
00003 from Modules import OutputModule, EDProducer, EDFilter, EDAnalyzer
00004 
00005 
00006 class PathValidator(object):
00007     def __init__(self):
00008         self.__label = ''
00009     def setLabel(self,label):
00010         self.__label = "'"+label+"' "
00011     def enter(self,visitee):
00012         if isinstance(visitee,OutputModule):
00013             raise ValueError("Path "+self.__label+"cannot contain an OutputModule, '"+visitee.type_()+"', with label '"+visitee.label_()+"'")
00014         if hasattr(visitee, "label_") and not isinstance(visitee,Sequence):
00015             if not visitee.hasLabel_():
00016                 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.")
00017     def leave(self,visitee):
00018         pass
00019 
00020 class EndPathValidator(object):
00021     _presetFilters = ["TriggerResultsFilter", "HLTPrescaler"]
00022     def __init__(self):   
00023         self.filtersOnEndpaths = []
00024         self.__label = ''
00025     def setLabel(self,label):
00026         self.__label = "'"+label+"' "
00027     def enter(self,visitee):
00028         if isinstance(visitee,EDFilter):
00029             if (visitee.type_() in self._presetFilters):
00030                 if (visitee.type_() not in self.filtersOnEndpaths):
00031                     self.filtersOnEndpaths.append(visitee.type_())
00032         if hasattr(visitee, "label_") and not isinstance(visitee,Sequence):
00033             if not visitee.hasLabel_():
00034                 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.")
00035     def leave(self,visitee):
00036         pass
00037 
00038 if __name__=="__main__":
00039     import unittest
00040     class TestModuleCommand(unittest.TestCase):
00041         def setUp(self):
00042             """Nothing to do """
00043             pass
00044         def testValidators(self):
00045             producer = EDProducer("Producer")
00046             analyzer = EDAnalyzer("Analyzer")
00047             output = OutputModule("Out")
00048             filter = EDFilter("Filter")
00049             unlabeled = EDAnalyzer("UnLabeled")
00050             producer.setLabel("producer")
00051             analyzer.setLabel("analyzer")
00052             output.setLabel("output")
00053             filter.setLabel("filter")
00054             s1 = Sequence(analyzer*producer)
00055             s2 = Sequence(output+filter)
00056             p1 = Path(s1)
00057             p2 = Path(s1*s2)
00058             p3 = Path(s1+unlabeled)
00059             ep1 = EndPath(producer+output+analyzer)
00060             ep2 = EndPath(filter+output)
00061             ep3 = EndPath(s2)
00062             ep4 = EndPath(unlabeled)
00063             pathValidator = PathValidator()
00064             endpathValidator = EndPathValidator()
00065             p1.visit(pathValidator)
00066             self.assertRaises(ValueError, p2.visit, pathValidator) 
00067             self.assertRaises(ValueError, p3.visit, pathValidator) 
00068             ep1.visit(endpathValidator) 
00069             ep2.visit(endpathValidator) 
00070             ep3.visit(endpathValidator) 
00071             self.assertRaises(ValueError, ep4.visit, endpathValidator) 
00072 
00073     unittest.main()
00074