CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
editorTools.py
Go to the documentation of this file.
1 import copy
2 import FWCore.ParameterSet.Config as cms
4 from FWCore.ParameterSet.Types import InputTag
5 
7  """ User code tool """
8  _label="userCode"
9  _defaultParameters=dicttypes.SortedKeysDict()
10  def __init__(self):
11  ConfigToolBase.__init__(self)
12  self.addParameter(self._defaultParameters,'code','', 'User code modifying the process: e.g. process.maxevents=1')
13  self._parameters=copy.deepcopy(self._defaultParameters)
14  self._comment = ""
15  def dumpPython(self):
16  dumpPython=""
17  if self._comment!="":
18  dumpPython = "#"+self._comment+"\n"
19  dumpPython+=self._parameters['code'].value
20  return ("",dumpPython)
21  def __call__(self,process,code):
22  self.setParameter('code',code)
23  self.apply(process)
24  return self
25  def toolCode(self,process):
26  code=self._parameters['code'].value
27  exec code
28 
29 userCodeTool=UserCodeTool()
30 
32 
33  """ Tool for changing the source of a Process;
34  Implemented for testing purposes.
35  """
36 
37  _label='changeSource'
38  _defaultParameters=dicttypes.SortedKeysDict()
39  def __init__(self):
40  ConfigToolBase.__init__(self)
41  self.addParameter(self._defaultParameters,'source','No default value. Set your own', ' Source filenames')
42  self._parameters=copy.deepcopy(self._defaultParameters)
43  self._comment = ""
44 
46  return self._defaultParameters
47 
48  def __call__(self,process,source=None) :
49  if source is None:
50  source=self._defaultParameters['source'].value
51  self.setParameter('source',source)
52  self.apply(process)
53 
54  def toolCode(self, process):
55  source=self._parameters['source'].value
56  process.source.fileNames=cms.untracked.vstring(source)
57 
58 changeSource=ChangeSource()
59 
60 from FWCore.ParameterSet.Modules import Source
61 
62 if __name__=='__main__':
63  import unittest
64  class TestEditorTools(unittest.TestCase):
65  def setUp(self):
66  pass
67  def testdumpPython(self):
68  process = cms.Process('unittest')
69  process.source=Source("PoolSource",fileNames = cms.untracked.string("file:file.root"))
70 
71  changeSource(process,"file:filename.root")
72  self.assertEqual(changeSource.dumpPython(), ('\nfrom FWCore.GuiBrowsers.editorTools import *\n', "\nchangeSource(process , 'file:filename.root')\n"))
73 
74  unittest.main()