5 """Denotes a class that can be used by the Processes class""" 22 """base class for classes which are used as the 'parameters' for a ParameterSet""" 24 self.__dict__[
"_isFrozen"] =
False 33 return type(self).__name__
34 return 'untracked '+type(self).__name__
37 return 'cms.'+type(self).__name__
38 return 'cms.untracked.'+type(self).__name__
53 """base class for parameter classes which only hold a single value""" 55 super(_SimpleParameterTypeBase,self).
__init__()
57 if not self._isValid(value):
58 raise ValueError(
str(value)+
" is not a valid "+
str(type(self)))
62 if not self._isValid(value):
63 raise ValueError(
str(value)+
" is not a valid "+
str(type(self)))
72 if isinstance(other,_SimpleParameterTypeBase):
73 return self.
_value == other._value
74 return self.
_value == other
76 if isinstance(other,_SimpleParameterTypeBase):
77 return self.
_value != other._value
78 return self.
_value != other
80 if isinstance(other,_SimpleParameterTypeBase):
81 return self.
_value < other._value
84 if isinstance(other,_SimpleParameterTypeBase):
85 return self.
_value <= other._value
86 return self.
_value <= other
88 if isinstance(other,_SimpleParameterTypeBase):
89 return self.
_value > other._value
92 if isinstance(other,_SimpleParameterTypeBase):
93 return self.
_value >= other._value
94 return self.
_value >= other
98 """For injection purposes, pretend this is a new parameter type 99 then have a post process step which strips these out 102 super(UsingBlock,self).
__init__(value)
109 return isinstance(value,str)
111 """only used for cfg-parsing""" 118 parameterSet.addString(self.
isTracked(), myname, value)
121 return "process."+self.
value()
127 """Base class for classes which allow addition of _ParameterTypeBase data""" 129 self.__dict__[
'_Parameterizable__parameterNames'] = []
130 self.__dict__[
"_isFrozen"] =
False 131 """The named arguments are the 'parameters' which are added as 'python attributes' to the object""" 135 if type(block).__name__ !=
"PSet":
136 raise ValueError(
"Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
142 """Returns the name of the parameters""" 143 return self.__parameterNames[:]
148 param = self.__dict__[name]
149 if isinstance(param, _Parameterizable)
and param.isModified():
158 check that pset provided has the attribute chain 161 Eg, if params is [ 'attr1', 'attr2', 'attr3' ] 162 check for pset.attr1.attr2.attr3 164 returns True if parameter exists, False if not 172 Retrieve the specified parameter from the PSet Provided 173 given the attribute chain 175 returns None if not found 179 if type(params).__name__ ==
'str':
180 return getattr(self, params,
None)
182 lastParam = getattr(lastParam, param,
None)
184 if lastParam ==
None:
189 """Returns a dictionary of copies of the user-set parameters""" 193 result[name]=copy.deepcopy(self.__dict__[name])
197 if not isinstance(value,_ParameterTypeBase):
199 if name
in self.__dict__:
200 message =
"Duplicate insert of member " + name
201 message +=
"\nThe original parameters are:\n" 203 raise ValueError(message)
204 self.__dict__[name]=value
205 self.__parameterNames.append(name)
209 for name,value
in six.iteritems(parameters):
215 if self.
isFrozen()
and not (name
in [
"_Labelable__label",
"_isFrozen"]
or name.startswith(
'_')):
216 message =
"Object already added to a process. It is read only now\n" 217 message +=
" %s = %s" %(name, value)
218 message +=
"\nThe original parameters are:\n" 220 raise ValueError(message)
223 super(_Parameterizable,self).
__setattr__(name,value)
224 elif not name
in self.__dict__:
229 if isinstance(value,_ParameterTypeBase):
230 self.__dict__[name] = value
243 raise ValueError(
"Object already added to a process. It is read only now")
245 self.__parameterNames.remove(name)
248 raise TypeError(name+
" does not already exist, so it can only be set to a CMS python configuration type")
251 if len(sortedNames) > 200:
260 for name
in sortedNames:
261 param = self.__dict__[name]
263 name2 = name.replace(
'-',
'_')
266 if name.startswith(
"using_"):
267 usings.append(options.indentation()+param.dumpPython(options))
269 others.append((name2, param.dumpPython(options)))
272 resultList =
',\n'.
join(usings)
273 longOthers = options.indentation()+
"**dict(\n" 275 longOthers += options.indentation()+
"[\n" 280 if entriesInList > 200:
283 longOthers += options.indentation()+
"] +\n"+options.indentation()+
"[\n" 286 longOthers += options.indentation()+
'("'+n+
'" , '+v+
' ),\n' 288 longOthers += options.indentation()+
"]\n" 290 longOthers +=options.indentation()+
")\n" 294 ret.append(resultList)
296 ret.append(longOthers)
297 return ",\n".
join(ret)
301 for name
in sortedNames:
302 param = self.__dict__[name]
304 name2 = name.replace(
'-',
'_')
307 if name.startswith(
"using_"):
308 usings.append(options.indentation()+param.dumpPython(options))
310 others.append(options.indentation()+name2+
' = '+param.dumpPython(options))
314 resultList.extend(others)
315 return ',\n'.
join(resultList)+
'\n' 320 param = getattr(self,name)
321 param.insertInto(parameterSet, name)
325 """Base class for classes which are Parameterizable and have a 'type' assigned""" 327 self.__dict__[
'_TypedParameterizable__type'] = type_
333 arg = tuple([x
for x
in arg
if x !=
None])
334 super(_TypedParameterizable,self).
__init__(*arg,**kargs)
337 self._placeImpl(name,proc)
339 """returns the type of the object, e.g. 'FooProducer'""" 342 returnValue =_TypedParameterizable.__new__(type(self))
347 returnValue.__init__(self.__type,*args,
352 """Copies the object and allows one to modify the parameters of the clone. 353 New parameters may be added by specify the exact type 354 Modifying existing parameters can be done by just specifying the new 355 value without having to specify the type. 356 A parameter may be removed from the clone using the value None. 357 #remove the parameter foo.fred 358 mod.toModify(foo, fred = None) 359 A parameter embedded within a PSet may be changed via a dictionary 360 #change foo.fred.pebbles to 3 and foo.fred.friend to "barney" 361 mod.toModify(foo, fred = dict(pebbles = 3, friend = "barney)) ) 363 returnValue =_TypedParameterizable.__new__(type(self))
365 if len(myparams) == 0
and len(params)
and len(args):
370 returnValue.__init__(self.__type,*args,
372 returnValue._isModified =
False 373 returnValue._isFrozen =
False 384 choices.extend(glob.glob(d+
'/*/*/'+label+
'.py'))
394 mod = __import__(name)
395 components = name.split(
'.')
396 for comp
in components[1:]:
397 mod = getattr(mod,comp)
398 if hasattr(mod,label):
399 default = getattr(mod,label)
400 if isinstance(default,_TypedParameterizable):
401 if(default.type_() == type):
403 for name
in default.parameterNames_():
404 params[name] = getattr(default,name)
409 config = self.__type +
' { \n' 411 param = self.__dict__[name]
413 config+=options.indentation()+param.configTypeName()+
' '+name+
' = '+param.configValue(options)+
'\n' 415 config += options.indentation()+
'}\n' 419 result =
"cms."+
str(type(self).__name__)+
'("'+self.
type_()+
'"' 424 result +=
",\n"+_Parameterizable.dumpPython(self,options)+options.indentation() +
")\n" 428 """ dumps the object with all attributes declared after the constructor""" 431 param = self.__dict__[name]
432 result += options.indentation() + myname +
"." + name +
" = " + param.dumpPython(options) +
"\n" 440 newpset = parameterSet.newPSet()
441 newpset.addString(
True,
"@module_label", self.
moduleLabel_(myname))
442 newpset.addString(
True,
"@module_type", self.
type_())
443 newpset.addString(
True,
"@module_edm_type", type(self).__name__)
450 """A 'mixin' used to denote that the class can be paired with a label (e.g. an EDProducer)""" 452 if not hasattr(self,
"_Labelable__label"):
453 raise RuntimeError(
"module has no label. Perhaps it wasn't inserted into the process?")
456 return hasattr(self,
"_Labelable__label")
and self.
__label is not None 459 if self.
label_() != label
and label
is not None :
460 msg100 =
"Attempting to change the label of a Labelable object, possibly an attribute of the Process\n" 461 msg101 =
"Old label = "+self.
label_()+
" New label = "+label+
"\n" 462 msg102 =
"Type = "+
str(type(self))+
"\n" 463 msg103 =
"Some possible solutions:\n" 464 msg104 =
" 1. Clone modules instead of using simple assignment. Cloning is\n" 465 msg105 =
" also preferred for other types when possible.\n" 466 msg106 =
" 2. Declare new names starting with an underscore if they are\n" 467 msg107 =
" for temporaries you do not want propagated into the Process. The\n" 468 msg108 =
" underscore tells \"from x import *\" and process.load not to import\n" 469 msg109 =
" the name.\n" 470 msg110 =
" 3. Reorganize so the assigment is not necessary. Giving a second\n" 471 msg111 =
" name to the same object usually causes confusion and problems.\n" 472 msg112 =
" 4. Compose Sequences: newName = cms.Sequence(oldName)\n" 473 raise ValueError(msg100+msg101+msg102+msg103+msg104+msg105+msg106+msg107+msg108+msg109+msg110+msg111+msg112)
489 myDeps=knownDeps.get(self.
label_(),
None)
491 if presentDeps != myDeps:
492 raise RuntimeError(
"the module "+self.
label_()+
" has two dependencies \n" 493 +
str(presentDeps)+
"\n" 495 +
"Please modify sequences to rectify this inconsistency")
497 myDeps=set(presentDeps)
498 knownDeps[self.
label_()]=myDeps
499 presentDeps.add(self.
label_())
503 """A 'mixin' used to denote that the class can be used without a label (e.g. a Service)""" 506 class _ValidatingListBase(
list):
507 """Base class for a list which enforces that its entries pass a 'validity' test""" 509 super(_ValidatingListBase,self).
__init__(arg)
511 raise SyntaxError(
"named arguments ("+
','.
join([x
for x
in args])+
") passsed to "+
str(type(self)))
513 raise TypeError(
"wrong types ("+
','.
join([
str(type(value))
for value
in iter(self)])+
514 ") added to "+
str(type(self)))
516 if isinstance(key,slice):
518 raise TypeError(
"wrong type being inserted into this container "+self.
_labelIfAny())
520 if not self._itemIsValid(value):
521 raise TypeError(
"can not insert the type "+
str(type(value))+
" in container "+self.
_labelIfAny())
522 super(_ValidatingListBase,self).
__setitem__(key,value)
525 if isinstance(seq, str):
528 if not self._itemIsValid(item):
532 if not self._itemIsValid(x):
533 raise TypeError(
"wrong type being appended to container "+self.
_labelIfAny())
534 super(_ValidatingListBase,self).
append(x)
537 raise TypeError(
"wrong type being extended to container "+self.
_labelIfAny())
538 super(_ValidatingListBase,self).
extend(x)
541 raise TypeError(
"wrong type being added to container "+self.
_labelIfAny())
543 value = copy.copy(self)
547 if not self._itemIsValid(x):
548 raise TypeError(
"wrong type being inserted to container "+self.
_labelIfAny())
549 super(_ValidatingListBase,self).
insert(i,x)
551 result = type(self).__name__
552 if hasattr(self,
'__label'):
553 result +=
' ' + self.__label
558 _ParameterTypeBase.__init__(self)
559 if len (arg) == 1
and not isinstance(arg[0],str):
564 super(_ValidatingParameterListBase,self).
__init__(*arg,**args)
574 for value
in iter(self):
576 config += options.indentation()
582 config += options.indentation()+
'}\n' 593 if hasattr(self,
"_nPerLine"):
594 nPerLine = self._nPerLine
597 if n>nPerLine: options.indent()
601 for i, v
in enumerate(self):
603 if n>nPerLine: result +=
'\n'+options.indentation()
606 if i % nPerLine == 0:
607 result +=
'\n'+options.indentation()
611 result +=
'\n'+options.indentation()
622 frame = inspect.getframeinfo(inspect.currentframe(level+1))
626 obj._filename = frame[0]
627 obj._lineNumber = frame[1]
632 for key,value
in six.iteritems(newParams):
636 elif isinstance(value, dict):
637 if isinstance(params[key],_Parameterizable):
639 p =pset.parameters_()
640 oldkeys = set(p.keys())
643 (
"%s.%s" if isinstance(key, str)
else "%s[%s]")%(keyDepth,key))
644 for k,v
in six.iteritems(p):
649 elif isinstance(params[key],_ValidatingParameterListBase):
650 if any(
not isinstance(k, int)
for k
in value.keys()):
651 raise TypeError(
"Attempted to change a list using a dict whose keys are not integers")
653 if any((k < 0
or k >= len(plist))
for k
in value.keys()):
654 raise IndexError(
"Attempted to set an index which is not in the list")
655 p =
dict(enumerate(plist))
658 (
"%s.%s" if isinstance(key, str)
else "%s[%s]")%(keyDepth,key))
659 for k,v
in six.iteritems(p):
662 raise ValueError(
"Attempted to change non PSet value "+keyDepth+
" using a dictionary")
663 elif isinstance(value,_ParameterTypeBase)
or (isinstance(key, int)):
668 if isinstance(value,_ParameterTypeBase):
674 if __name__ ==
"__main__":
683 self.assertEqual(t,[1])
685 self.assertEqual(t,[1])
687 self.assertEqual(t,[
"one"])
689 self.assertEqual(t,[1])
691 self.assertEqual(t,[1])
694 self.assertEqual(t,[1,2])
696 self.assertEqual(t,[1,2])
698 self.assertEqual(t,[
"one",
"two"])
700 self.assertEqual(t,[
"one",
"two"])
702 self.assertEqual(t,[1,2])
704 self.assertEqual(t,[1,2])
706 self.assertEqual(t,[1,2])
712 args = [i
for i
in xrange(0,300)]
715 pdump= t.dumpPython()
719 pythonized = eval( pdump, globals(),{
'cms':
cms()} )
720 self.assertEqual(t,pythonized)
723 self.assert_(isinstance(a, _ParameterTypeBase))
728 def _isValid(self,value):
730 a = __Test(
"MyType",t=__TestType(1), u=__TestType(2))
732 self.assertEqual(b.t.value(),1)
733 self.assertEqual(b.u.value(),2)
738 def _isValid(self,value):
741 def __init__(self,*arg,**args):
743 _ParameterTypeBase.__init__(self)
744 _Parameterizable.__init__(self,*arg,**args)
749 x = __PSet(a = __TestType(4),
751 c = __PSet(gamma = __TestType(5))))
758 c = a.clone(x =
dict(a=
None, c=
None))
759 self.assertEqual(a.t.value(),1)
760 self.assertEqual(a.u.value(),2)
761 self.assertEqual(b.t.value(),3)
762 self.assertEqual(b.u.value(),2)
763 self.assertEqual(b.v.value(),4)
764 self.assertEqual(b.x.a.value(),7)
765 self.assertEqual(b.x.b.value(),6)
766 self.assertEqual(b.x.c.gamma.value(),8)
767 self.assertEqual(b.x.d.value(),9)
768 self.assertEqual(hasattr(b,
"w"),
False)
769 self.assertEqual(hasattr(c.x,
"a"),
False)
770 self.assertEqual(hasattr(c.x,
"c"),
False)
771 self.assertRaises(TypeError,a.clone,
None,**{
"v":1})
774 def _isValid(self,value):
777 self.assertEqual(a.isModified(),
False)
779 self.assertEqual(a.isModified(),
False)
781 self.assertEqual(a.isModified(),
True)
783 self.assertEqual(a.isModified(),
False)
788 def _isValid(self,value):
790 class __DummyModule(
object):
796 self.assertEqual(p.dumpPython(), eval(p.dumpPython(),{
"cms": __DummyModule()}).
dumpPython())
def __init__(self, arg, args)
def moduleLabel_(self, myname)
def dumpPython(self, options=PrintOptions())
def dumpConfig(self, options=PrintOptions())
def insertInto(self, parameterSet, myname)
def _modifyParametersFromDict(params, newParams, errorRaiser, keyDepth="")
def __setParameters(self, parameters)
def _findDependencies(self, knownDeps, presentDeps)
def dumpPython(self, options=PrintOptions())
bool any(const std::vector< T > &v, const T &what)
def dumpPython(self, options=PrintOptions())
def __init__(self, arg, kargs)
def dumpPythonAttributes(self, myname, options)
def _valueFromString(value)
def setLabel(self, label)
def nameInProcessDesc_(self, myname)
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...
def dumpPython(self, options=PrintOptions())
def testListConstruction(self)
def insertInto(self, parameterSet, myname)
def dumpPython(self, options=PrintOptions())
def __delattr__(self, name)
def _itemsFromStrings(strings, converter)
def clone(self, args, params)
def dumpSequenceConfig(self)
def __init__(self, type_, arg, kargs)
def testLargeParameterizable(self)
def __init__(self, value, s='', loc=0, file='')
def __addParameter(self, name, value)
def _place(self, name, proc)
def __findDefaultsFor(label, type)
def __setattr__(self, name, value)
def saveOrigin(obj, level)
def __raiseBadSetAttr(name)
Namespace of DDCMS conversion namespace.
def configValue(self, options=PrintOptions())
def _itemIsValid(self, item)
def configValue(self, options=PrintOptions())
def setIsTracked(self, trackness)
static std::string join(char **cmd)
def hasParameter(self, params)
def setValue(self, value)
def parameterNames_(self)
def dumpPython(process, name)
def pythonValueForItem(self, item, options)
def __setitem__(self, key, value)
def pythonValue(self, options=PrintOptions())
def configValueForItem(self, item, options)
def __init__(self, value)
def getParameter(self, params)
def insertContentsInto(self, parameterSet)
def dumpSequencePython(self, options=PrintOptions())
def __init__(self, arg, args)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run