4 """Denotes a class that can be used by the Processes class""" 21 """base class for classes which are used as the 'parameters' for a ParameterSet""" 23 self.__dict__[
"_isFrozen"] =
False 32 return type(self).__name__
33 return 'untracked '+type(self).__name__
36 return 'cms.'+type(self).__name__
37 return 'cms.untracked.'+type(self).__name__
52 """base class for parameter classes which only hold a single value""" 54 super(_SimpleParameterTypeBase,self).
__init__()
56 if not self._isValid(value):
57 raise ValueError(
str(value)+
" is not a valid "+
str(type(self)))
61 if not self._isValid(value):
62 raise ValueError(
str(value)+
" is not a valid "+
str(type(self)))
71 if isinstance(other,_SimpleParameterTypeBase):
72 return self.
_value == other._value
73 return self.
_value == other
75 if isinstance(other,_SimpleParameterTypeBase):
76 return self.
_value != other._value
77 return self.
_value != other
79 if isinstance(other,_SimpleParameterTypeBase):
80 return self.
_value < other._value
83 if isinstance(other,_SimpleParameterTypeBase):
84 return self.
_value <= other._value
85 return self.
_value <= other
87 if isinstance(other,_SimpleParameterTypeBase):
88 return self.
_value > other._value
91 if isinstance(other,_SimpleParameterTypeBase):
92 return self.
_value >= other._value
93 return self.
_value >= other
97 """For injection purposes, pretend this is a new parameter type 98 then have a post process step which strips these out 101 super(UsingBlock,self).
__init__(value)
108 return isinstance(value,str)
110 """only used for cfg-parsing""" 117 parameterSet.addString(self.
isTracked(), myname, value)
120 return "process."+self.
value()
126 """Base class for classes which allow addition of _ParameterTypeBase data""" 128 self.__dict__[
'_Parameterizable__parameterNames'] = []
129 self.__dict__[
"_isFrozen"] =
False 130 """The named arguments are the 'parameters' which are added as 'python attributes' to the object""" 134 if type(block).__name__ !=
"PSet":
135 raise ValueError(
"Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
141 """Returns the name of the parameters""" 142 return self.__parameterNames[:]
147 param = self.__dict__[name]
148 if isinstance(param, _Parameterizable)
and param.isModified():
157 check that pset provided has the attribute chain 160 Eg, if params is [ 'attr1', 'attr2', 'attr3' ] 161 check for pset.attr1.attr2.attr3 163 returns True if parameter exists, False if not 171 Retrieve the specified parameter from the PSet Provided 172 given the attribute chain 174 returns None if not found 178 if type(params).__name__ ==
'str':
179 return getattr(self, params,
None)
181 lastParam = getattr(lastParam, param,
None)
183 if lastParam ==
None:
188 """Returns a dictionary of copies of the user-set parameters""" 192 result[name]=copy.deepcopy(self.__dict__[name])
196 if not isinstance(value,_ParameterTypeBase):
198 if name
in self.__dict__:
199 message =
"Duplicate insert of member " + name
200 message +=
"\nThe original parameters are:\n" 202 raise ValueError(message)
203 self.__dict__[name]=value
204 self.__parameterNames.append(name)
208 for name,value
in parameters.iteritems():
214 if self.
isFrozen()
and not (name
in [
"_Labelable__label",
"_isFrozen"]
or name.startswith(
'_')):
215 message =
"Object already added to a process. It is read only now\n" 216 message +=
" %s = %s" %(name, value)
217 message +=
"\nThe original parameters are:\n" 219 raise ValueError(message)
222 super(_Parameterizable,self).
__setattr__(name,value)
223 elif not name
in self.__dict__:
228 if isinstance(value,_ParameterTypeBase):
229 self.__dict__[name] = value
242 raise ValueError(
"Object already added to a process. It is read only now")
244 self.__parameterNames.remove(name)
247 raise TypeError(name+
" does not already exist, so it can only be set to a CMS python configuration type")
250 if len(sortedNames) > 200:
259 for name
in sortedNames:
260 param = self.__dict__[name]
262 name2 = name.replace(
'-',
'_')
265 if name.startswith(
"using_"):
266 usings.append(options.indentation()+param.dumpPython(options))
268 others.append((name2, param.dumpPython(options)))
271 resultList =
',\n'.
join(usings)
272 longOthers = options.indentation()+
"**dict(\n" 274 longOthers += options.indentation()+
"[\n" 279 if entriesInList > 200:
282 longOthers += options.indentation()+
"] +\n"+options.indentation()+
"[\n" 285 longOthers += options.indentation()+
'("'+n+
'" , '+v+
' ),\n' 287 longOthers += options.indentation()+
"]\n" 289 longOthers +=options.indentation()+
")\n" 293 ret.append(resultList)
295 ret.append(longOthers)
296 return ",\n".
join(ret)
300 for name
in sortedNames:
301 param = self.__dict__[name]
303 name2 = name.replace(
'-',
'_')
306 if name.startswith(
"using_"):
307 usings.append(options.indentation()+param.dumpPython(options))
309 others.append(options.indentation()+name2+
' = '+param.dumpPython(options))
313 resultList.extend(others)
314 return ',\n'.
join(resultList)+
'\n' 319 param = getattr(self,name)
320 param.insertInto(parameterSet, name)
324 """Base class for classes which are Parameterizable and have a 'type' assigned""" 326 self.__dict__[
'_TypedParameterizable__type'] = type_
332 arg = tuple([x
for x
in arg
if x !=
None])
333 super(_TypedParameterizable,self).
__init__(*arg,**kargs)
336 self._placeImpl(name,proc)
338 """returns the type of the object, e.g. 'FooProducer'""" 341 returnValue =_TypedParameterizable.__new__(type(self))
346 returnValue.__init__(self.__type,*args,
351 """Copies the object and allows one to modify the parameters of the clone. 352 New parameters may be added by specify the exact type 353 Modifying existing parameters can be done by just specifying the new 354 value without having to specify the type. 355 A parameter may be removed from the clone using the value None. 356 #remove the parameter foo.fred 357 mod.toModify(foo, fred = None) 358 A parameter embedded within a PSet may be changed via a dictionary 359 #change foo.fred.pebbles to 3 and foo.fred.friend to "barney" 360 mod.toModify(foo, fred = dict(pebbles = 3, friend = "barney)) ) 362 returnValue =_TypedParameterizable.__new__(type(self))
364 if len(myparams) == 0
and len(params)
and len(args):
369 returnValue.__init__(self.__type,*args,
371 returnValue._isModified =
False 372 returnValue._isFrozen =
False 383 choices.extend(glob.glob(d+
'/*/*/'+label+
'.py'))
393 mod = __import__(name)
394 components = name.split(
'.')
395 for comp
in components[1:]:
396 mod = getattr(mod,comp)
397 if hasattr(mod,label):
398 default = getattr(mod,label)
399 if isinstance(default,_TypedParameterizable):
400 if(default.type_() == type):
402 for name
in default.parameterNames_():
403 params[name] = getattr(default,name)
408 config = self.__type +
' { \n' 410 param = self.__dict__[name]
412 config+=options.indentation()+param.configTypeName()+
' '+name+
' = '+param.configValue(options)+
'\n' 414 config += options.indentation()+
'}\n' 418 result =
"cms."+
str(type(self).__name__)+
'("'+self.
type_()+
'"' 423 result +=
",\n"+_Parameterizable.dumpPython(self,options)+options.indentation() +
")\n" 427 """ dumps the object with all attributes declared after the constructor""" 430 param = self.__dict__[name]
431 result += options.indentation() + myname +
"." + name +
" = " + param.dumpPython(options) +
"\n" 439 newpset = parameterSet.newPSet()
440 newpset.addString(
True,
"@module_label", self.
moduleLabel_(myname))
441 newpset.addString(
True,
"@module_type", self.
type_())
442 newpset.addString(
True,
"@module_edm_type", type(self).__name__)
449 """A 'mixin' used to denote that the class can be paired with a label (e.g. an EDProducer)""" 451 if not hasattr(self,
"_Labelable__label"):
452 raise RuntimeError(
"module has no label. Perhaps it wasn't inserted into the process?")
455 return hasattr(self,
"_Labelable__label")
and self.
__label is not None 458 if self.
label_() != label
and label
is not None :
459 msg100 =
"Attempting to change the label of a Labelable object, possibly an attribute of the Process\n" 460 msg101 =
"Old label = "+self.
label_()+
" New label = "+label+
"\n" 461 msg102 =
"Type = "+
str(type(self))+
"\n" 462 msg103 =
"Some possible solutions:\n" 463 msg104 =
" 1. Clone modules instead of using simple assignment. Cloning is\n" 464 msg105 =
" also preferred for other types when possible.\n" 465 msg106 =
" 2. Declare new names starting with an underscore if they are\n" 466 msg107 =
" for temporaries you do not want propagated into the Process. The\n" 467 msg108 =
" underscore tells \"from x import *\" and process.load not to import\n" 468 msg109 =
" the name.\n" 469 msg110 =
" 3. Reorganize so the assigment is not necessary. Giving a second\n" 470 msg111 =
" name to the same object usually causes confusion and problems.\n" 471 msg112 =
" 4. Compose Sequences: newName = cms.Sequence(oldName)\n" 472 raise ValueError(msg100+msg101+msg102+msg103+msg104+msg105+msg106+msg107+msg108+msg109+msg110+msg111+msg112)
488 myDeps=knownDeps.get(self.
label_(),
None)
490 if presentDeps != myDeps:
491 raise RuntimeError(
"the module "+self.
label_()+
" has two dependencies \n" 492 +
str(presentDeps)+
"\n" 494 +
"Please modify sequences to rectify this inconsistency")
496 myDeps=set(presentDeps)
497 knownDeps[self.
label_()]=myDeps
498 presentDeps.add(self.
label_())
502 """A 'mixin' used to denote that the class can be used without a label (e.g. a Service)""" 505 class _ValidatingListBase(
list):
506 """Base class for a list which enforces that its entries pass a 'validity' test""" 508 super(_ValidatingListBase,self).
__init__(arg)
510 raise SyntaxError(
"named arguments ("+
','.
join([x
for x
in args])+
") passsed to "+
str(type(self)))
512 raise TypeError(
"wrong types ("+
','.
join([
str(type(value))
for value
in iter(self)])+
513 ") added to "+
str(type(self)))
515 if isinstance(key,slice):
517 raise TypeError(
"wrong type being inserted into this container "+self.
_labelIfAny())
519 if not self._itemIsValid(value):
520 raise TypeError(
"can not insert the type "+
str(type(value))+
" in container "+self.
_labelIfAny())
521 super(_ValidatingListBase,self).
__setitem__(key,value)
524 if isinstance(seq, str):
527 if not self._itemIsValid(item):
531 if not self._itemIsValid(x):
532 raise TypeError(
"wrong type being appended to container "+self.
_labelIfAny())
533 super(_ValidatingListBase,self).
append(x)
536 raise TypeError(
"wrong type being extended to container "+self.
_labelIfAny())
537 super(_ValidatingListBase,self).
extend(x)
540 raise TypeError(
"wrong type being added to container "+self.
_labelIfAny())
542 value = copy.copy(self)
546 if not self._itemIsValid(x):
547 raise TypeError(
"wrong type being inserted to container "+self.
_labelIfAny())
548 super(_ValidatingListBase,self).
insert(i,x)
550 result = type(self).__name__
551 if hasattr(self,
'__label'):
552 result +=
' ' + self.__label
557 _ParameterTypeBase.__init__(self)
558 if len (arg) == 1
and not isinstance(arg[0],str):
563 super(_ValidatingParameterListBase,self).
__init__(*arg,**args)
573 for value
in iter(self):
575 config += options.indentation()
581 config += options.indentation()+
'}\n' 592 if hasattr(self,
"_nPerLine"):
593 nPerLine = self._nPerLine
596 if n>nPerLine: options.indent()
600 for i, v
in enumerate(self):
602 if n>nPerLine: result +=
'\n'+options.indentation()
605 if i % nPerLine == 0:
606 result +=
'\n'+options.indentation()
610 result +=
'\n'+options.indentation()
621 frame = inspect.getframeinfo(inspect.currentframe(level+1))
625 obj._filename = frame[0]
626 obj._lineNumber = frame[1]
631 for key,value
in newParams.iteritems():
635 elif isinstance(value, dict):
636 if isinstance(params[key],_Parameterizable):
638 p =pset.parameters_()
639 oldkeys = set(p.keys())
642 (
"%s.%s" if type(key)==str
else "%s[%s]")%(keyDepth,key))
643 for k,v
in p.iteritems():
648 elif isinstance(params[key],_ValidatingParameterListBase):
649 if any(type(k) != int
for k
in value.keys()):
650 raise TypeError(
"Attempted to change a list using a dict whose keys are not integers")
652 if any((k < 0
or k >= len(plist))
for k
in value.keys()):
653 raise IndexError(
"Attempted to set an index which is not in the list")
654 p =
dict(enumerate(plist))
657 (
"%s.%s" if type(key)==str
else "%s[%s]")%(keyDepth,key))
658 for k,v
in p.iteritems():
661 raise ValueError(
"Attempted to change non PSet value "+keyDepth+
" using a dictionary")
662 elif isinstance(value,_ParameterTypeBase)
or (type(key) == int):
667 if isinstance(value,_ParameterTypeBase):
673 if __name__ ==
"__main__":
682 self.assertEqual(t,[1])
684 self.assertEqual(t,[1])
686 self.assertEqual(t,[
"one"])
688 self.assertEqual(t,[1])
690 self.assertEqual(t,[1])
693 self.assertEqual(t,[1,2])
695 self.assertEqual(t,[1,2])
697 self.assertEqual(t,[
"one",
"two"])
699 self.assertEqual(t,[
"one",
"two"])
701 self.assertEqual(t,[1,2])
703 self.assertEqual(t,[1,2])
705 self.assertEqual(t,[1,2])
711 args = [i
for i
in xrange(0,300)]
714 pdump= t.dumpPython()
718 pythonized = eval( pdump, globals(),{
'cms':
cms()} )
719 self.assertEqual(t,pythonized)
722 self.assert_(isinstance(a, _ParameterTypeBase))
727 def _isValid(self,value):
729 a = __Test(
"MyType",t=__TestType(1), u=__TestType(2))
731 self.assertEqual(b.t.value(),1)
732 self.assertEqual(b.u.value(),2)
737 def _isValid(self,value):
740 def __init__(self,*arg,**args):
742 _ParameterTypeBase.__init__(self)
743 _Parameterizable.__init__(self,*arg,**args)
748 x = __PSet(a = __TestType(4),
750 c = __PSet(gamma = __TestType(5))))
757 c = a.clone(x =
dict(a=
None, c=
None))
758 self.assertEqual(a.t.value(),1)
759 self.assertEqual(a.u.value(),2)
760 self.assertEqual(b.t.value(),3)
761 self.assertEqual(b.u.value(),2)
762 self.assertEqual(b.v.value(),4)
763 self.assertEqual(b.x.a.value(),7)
764 self.assertEqual(b.x.b.value(),6)
765 self.assertEqual(b.x.c.gamma.value(),8)
766 self.assertEqual(b.x.d.value(),9)
767 self.assertEqual(hasattr(b,
"w"),
False)
768 self.assertEqual(hasattr(c.x,
"a"),
False)
769 self.assertEqual(hasattr(c.x,
"c"),
False)
770 self.assertRaises(TypeError,a.clone,
None,**{
"v":1})
773 def _isValid(self,value):
776 self.assertEqual(a.isModified(),
False)
778 self.assertEqual(a.isModified(),
False)
780 self.assertEqual(a.isModified(),
True)
782 self.assertEqual(a.isModified(),
False)
787 def _isValid(self,value):
789 class __DummyModule(
object):
795 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)
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