Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:31

0001 import FWCore.ParameterSet.Config as cms
0002 from Configuration.Applications.ConfigBuilder import ConfigBuilder, defaultOptions
0003 
0004 import copy
0005 
0006 def prepareDQMSequenceOrder():
0007     options = copy.deepcopy(defaultOptions)
0008     options.scenario = "Test"
0009 
0010     process = cms.Process("Test")
0011     process.a1 = cms.EDAnalyzer("A1")
0012     process.a2 = cms.EDAnalyzer("A2")
0013     process.a3 = cms.EDAnalyzer("A3")
0014     process.a4 = cms.EDAnalyzer("A4")
0015     process.seq1 = cms.Sequence(process.a1)
0016     process.seq2 = cms.Sequence(process.a2)
0017     process.seq3 = cms.Sequence(process.a3)
0018     process.seq4 = cms.Sequence(process.a4)
0019     process.ps1 = cms.Sequence()
0020     process.ps2 = cms.Sequence()
0021     process.ps3 = cms.Sequence()
0022     process.ps3 = cms.Sequence()
0023     process.ps4 = cms.Sequence()
0024     return (options, process)
0025 
0026 if __name__=="__main__":
0027     import unittest
0028 
0029     class TestModuleCommand(unittest.TestCase):
0030         def setUp(self):
0031             """Nothing to do """
0032             None
0033 
0034         def testDQMSequenceOrder(self):
0035             def extract(process, count):
0036                 if count == 0:
0037                     return []
0038                 ret = list(process.dqmoffline_step.moduleNames())
0039                 for i in range(1, count):
0040                     ret.extend(list(getattr(process, f"dqmoffline_{i}_step").moduleNames()))
0041                 return ret
0042 
0043             # DQM sequences are unique
0044             (options, process) = prepareDQMSequenceOrder()
0045             order = [3, 1, 2]
0046             cb = ConfigBuilder(options, process)
0047             cb.prepare_DQM("+".join(f"seq{o}" for o in order))
0048             self.assertEqual([f"a{o}" for o in order], extract(process, len(order)))
0049 
0050             # Code in prepare_DQM() call assumes the 'sequenceList`
0051             # has at least as many elements as `postSequenceList`. We
0052             # can't fake 'postSequenceList' as it is also derived from
0053             # the prepare_DQM() argument, but duplicates are not
0054             # removed. The only handle we have (besides code changes,
0055             # that are beyond this bug fix), is to modify the autoDQM.
0056             from DQMOffline.Configuration.autoDQM import autoDQM
0057             autoDQM_orig = copy.deepcopy(autoDQM)
0058             autoDQM.clear()
0059             autoDQM["alias1"] = ["seq1", "ps1", "not needed"]
0060             autoDQM["alias2"] = ["seq2", "ps2", "not needed"]
0061             autoDQM["alias3"] = ["seq3", "ps3", "not needed"]
0062             # seq4 is used only to have the expanded and uniquified
0063             # 'sequenceList' to have at least as many elements as
0064             # 'postSequenceList'
0065             autoDQM["alias4"] = ["seq2+seq4", "ps4", "not needed"]
0066 
0067             order = [2, 1, 3]
0068             cb = ConfigBuilder(options, process)
0069             cb.prepare_DQM("+".join(f"@alias{o}" for o in order))
0070             self.assertEqual([f"a{o}" for o in order], extract(process, len(order)))
0071 
0072             cb = ConfigBuilder(options, process)
0073             order = [2, 1, 4, 3]
0074             cb.prepare_DQM("+".join(f"@alias{o}" for o in order))
0075             self.assertEqual([f"a{o}" for o in order], extract(process, len(order)))
0076 
0077             autoDQM.clear()
0078             autoDQM.update(autoDQM_orig)
0079 
0080     unittest.main()