1 from __future__
import print_function
6 """Denotes a class that can be used by the Processes class""" 23 """base class for classes which are used as the 'parameters' for a ParameterSet""" 25 self.__dict__[
"_isFrozen"] =
False 34 return type(self).__name__
35 return 'untracked '+type(self).__name__
38 return 'cms.'+type(self).__name__
39 return 'cms.untracked.'+type(self).__name__
54 """base class for parameter classes which only hold a single value""" 56 super(_SimpleParameterTypeBase,self).
__init__()
58 if not self._isValid(value):
59 raise ValueError(
str(value)+
" is not a valid "+
str(type(self)))
63 if not self._isValid(value):
64 raise ValueError(
str(value)+
" is not a valid "+
str(type(self)))
73 if isinstance(other,_SimpleParameterTypeBase):
74 return self.
_value == other._value
75 return self.
_value == other
77 if isinstance(other,_SimpleParameterTypeBase):
78 return self.
_value != other._value
79 return self.
_value != other
81 if isinstance(other,_SimpleParameterTypeBase):
82 return self.
_value < other._value
85 if isinstance(other,_SimpleParameterTypeBase):
86 return self.
_value <= other._value
87 return self.
_value <= other
89 if isinstance(other,_SimpleParameterTypeBase):
90 return self.
_value > other._value
93 if isinstance(other,_SimpleParameterTypeBase):
94 return self.
_value >= other._value
95 return self.
_value >= other
99 """For injection purposes, pretend this is a new parameter type 100 then have a post process step which strips these out 103 super(UsingBlock,self).
__init__(value)
110 return isinstance(value,str)
112 """only used for cfg-parsing""" 119 parameterSet.addString(self.
isTracked(), myname, value)
122 return "process."+self.
value()
128 """Base class for classes which allow addition of _ParameterTypeBase data""" 130 self.__dict__[
'_Parameterizable__parameterNames'] = []
131 self.__dict__[
"_isFrozen"] =
False 132 """The named arguments are the 'parameters' which are added as 'python attributes' to the object""" 136 if type(block).__name__ !=
"PSet":
137 raise ValueError(
"Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
143 """Returns the name of the parameters""" 144 return self.__parameterNames[:]
149 param = self.__dict__[name]
150 if isinstance(param, _Parameterizable)
and param.isModified():
159 check that pset provided has the attribute chain 162 Eg, if params is [ 'attr1', 'attr2', 'attr3' ] 163 check for pset.attr1.attr2.attr3 165 returns True if parameter exists, False if not 173 Retrieve the specified parameter from the PSet Provided 174 given the attribute chain 176 returns None if not found 180 if type(params).__name__ ==
'str':
181 return getattr(self, params,
None)
183 lastParam = getattr(lastParam, param,
None)
185 if lastParam ==
None:
190 """Returns a dictionary of copies of the user-set parameters""" 194 result[name]=copy.deepcopy(self.__dict__[name])
198 if not isinstance(value,_ParameterTypeBase):
200 if name
in self.__dict__:
201 message =
"Duplicate insert of member " + name
202 message +=
"\nThe original parameters are:\n" 204 raise ValueError(message)
205 self.__dict__[name]=value
206 self.__parameterNames.append(name)
210 for name,value
in six.iteritems(parameters):
216 if self.
isFrozen()
and not (name
in [
"_Labelable__label",
"_isFrozen"]
or name.startswith(
'_')):
217 message =
"Object already added to a process. It is read only now\n" 218 message +=
" %s = %s" %(name, value)
219 message +=
"\nThe original parameters are:\n" 221 raise ValueError(message)
224 super(_Parameterizable,self).
__setattr__(name,value)
225 elif not name
in self.__dict__:
230 if isinstance(value,_ParameterTypeBase):
231 self.__dict__[name] = value
244 raise ValueError(
"Object already added to a process. It is read only now")
246 self.__parameterNames.remove(name)
249 raise TypeError(name+
" does not already exist, so it can only be set to a CMS python configuration type")
252 if len(sortedNames) > 200:
261 for name
in sortedNames:
262 param = self.__dict__[name]
264 name2 = name.replace(
'-',
'_')
267 if name.startswith(
"using_"):
268 usings.append(options.indentation()+param.dumpPython(options))
270 others.append((name2, param.dumpPython(options)))
273 resultList =
',\n'.
join(usings)
274 longOthers = options.indentation()+
"**dict(\n" 276 longOthers += options.indentation()+
"[\n" 281 if entriesInList > 200:
284 longOthers += options.indentation()+
"] +\n"+options.indentation()+
"[\n" 287 longOthers += options.indentation()+
'("'+n+
'" , '+v+
' ),\n' 289 longOthers += options.indentation()+
"]\n" 291 longOthers +=options.indentation()+
")\n" 295 ret.append(resultList)
297 ret.append(longOthers)
298 return ",\n".
join(ret)
302 for name
in sortedNames:
303 param = self.__dict__[name]
305 name2 = name.replace(
'-',
'_')
308 if name.startswith(
"using_"):
309 usings.append(options.indentation()+param.dumpPython(options))
311 others.append(options.indentation()+name2+
' = '+param.dumpPython(options))
315 resultList.extend(others)
316 return ',\n'.
join(resultList)+
'\n' 321 param = getattr(self,name)
322 param.insertInto(parameterSet, name)
326 """Base class for classes which are Parameterizable and have a 'type' assigned""" 328 self.__dict__[
'_TypedParameterizable__type'] = type_
334 arg = tuple([x
for x
in arg
if x !=
None])
335 super(_TypedParameterizable,self).
__init__(*arg,**kargs)
338 self._placeImpl(name,proc)
340 """returns the type of the object, e.g. 'FooProducer'""" 343 returnValue =_TypedParameterizable.__new__(type(self))
348 returnValue.__init__(self.__type,*args,
353 """Copies the object and allows one to modify the parameters of the clone. 354 New parameters may be added by specify the exact type 355 Modifying existing parameters can be done by just specifying the new 356 value without having to specify the type. 357 A parameter may be removed from the clone using the value None. 358 #remove the parameter foo.fred 359 mod.toModify(foo, fred = None) 360 A parameter embedded within a PSet may be changed via a dictionary 361 #change foo.fred.pebbles to 3 and foo.fred.friend to "barney" 362 mod.toModify(foo, fred = dict(pebbles = 3, friend = "barney)) ) 364 returnValue =_TypedParameterizable.__new__(type(self))
366 if len(myparams) == 0
and len(params)
and len(args):
371 returnValue.__init__(self.__type,*args,
373 returnValue._isModified =
False 374 returnValue._isFrozen =
False 385 choices.extend(glob.glob(d+
'/*/*/'+label+
'.py'))
395 mod = __import__(name)
396 components = name.split(
'.')
397 for comp
in components[1:]:
398 mod = getattr(mod,comp)
399 if hasattr(mod,label):
400 default = getattr(mod,label)
401 if isinstance(default,_TypedParameterizable):
402 if(default.type_() == type):
404 for name
in default.parameterNames_():
405 params[name] = getattr(default,name)
410 config = self.__type +
' { \n' 412 param = self.__dict__[name]
414 config+=options.indentation()+param.configTypeName()+
' '+name+
' = '+param.configValue(options)+
'\n' 416 config += options.indentation()+
'}\n' 420 result =
"cms."+
str(type(self).__name__)+
'("'+self.
type_()+
'"' 425 result +=
",\n"+_Parameterizable.dumpPython(self,options)+options.indentation() +
")\n" 429 """ dumps the object with all attributes declared after the constructor""" 432 param = self.__dict__[name]
433 result += options.indentation() + myname +
"." + name +
" = " + param.dumpPython(options) +
"\n" 441 newpset = parameterSet.newPSet()
442 newpset.addString(
True,
"@module_label", self.
moduleLabel_(myname))
443 newpset.addString(
True,
"@module_type", self.
type_())
444 newpset.addString(
True,
"@module_edm_type", type(self).__name__)
451 """A 'mixin' used to denote that the class can be paired with a label (e.g. an EDProducer)""" 453 if not hasattr(self,
"_Labelable__label"):
454 raise RuntimeError(
"module has no label. Perhaps it wasn't inserted into the process?")
457 return hasattr(self,
"_Labelable__label")
and self.
__label is not None 460 if self.
label_() != label
and label
is not None :
461 msg100 =
"Attempting to change the label of a Labelable object, possibly an attribute of the Process\n" 462 msg101 =
"Old label = "+self.
label_()+
" New label = "+label+
"\n" 463 msg102 =
"Type = "+
str(type(self))+
"\n" 464 msg103 =
"Some possible solutions:\n" 465 msg104 =
" 1. Clone modules instead of using simple assignment. Cloning is\n" 466 msg105 =
" also preferred for other types when possible.\n" 467 msg106 =
" 2. Declare new names starting with an underscore if they are\n" 468 msg107 =
" for temporaries you do not want propagated into the Process. The\n" 469 msg108 =
" underscore tells \"from x import *\" and process.load not to import\n" 470 msg109 =
" the name.\n" 471 msg110 =
" 3. Reorganize so the assigment is not necessary. Giving a second\n" 472 msg111 =
" name to the same object usually causes confusion and problems.\n" 473 msg112 =
" 4. Compose Sequences: newName = cms.Sequence(oldName)\n" 474 raise ValueError(msg100+msg101+msg102+msg103+msg104+msg105+msg106+msg107+msg108+msg109+msg110+msg111+msg112)
490 myDeps=knownDeps.get(self.
label_(),
None)
492 if presentDeps != myDeps:
493 raise RuntimeError(
"the module "+self.
label_()+
" has two dependencies \n" 494 +
str(presentDeps)+
"\n" 496 +
"Please modify sequences to rectify this inconsistency")
498 myDeps=set(presentDeps)
499 knownDeps[self.
label_()]=myDeps
500 presentDeps.add(self.
label_())
504 """A 'mixin' used to denote that the class can be used without a label (e.g. a Service)""" 507 class _ValidatingListBase(
list):
508 """Base class for a list which enforces that its entries pass a 'validity' test""" 510 super(_ValidatingListBase,self).
__init__(arg)
512 raise SyntaxError(
"named arguments ("+
','.
join([x
for x
in args])+
") passsed to "+
str(type(self)))
514 raise TypeError(
"wrong types ("+
','.
join([
str(type(value))
for value
in iter(self)])+
515 ") added to "+
str(type(self)))
517 if isinstance(key,slice):
519 raise TypeError(
"wrong type being inserted into this container "+self.
_labelIfAny())
521 if not self._itemIsValid(value):
522 raise TypeError(
"can not insert the type "+
str(type(value))+
" in container "+self.
_labelIfAny())
523 super(_ValidatingListBase,self).
__setitem__(key,value)
526 if isinstance(seq, str):
529 if not self._itemIsValid(item):
533 if not self._itemIsValid(x):
534 raise TypeError(
"wrong type being appended to container "+self.
_labelIfAny())
535 super(_ValidatingListBase,self).
append(x)
538 raise TypeError(
"wrong type being extended to container "+self.
_labelIfAny())
539 super(_ValidatingListBase,self).
extend(x)
542 raise TypeError(
"wrong type being added to container "+self.
_labelIfAny())
544 value = copy.copy(self)
548 if not self._itemIsValid(x):
549 raise TypeError(
"wrong type being inserted to container "+self.
_labelIfAny())
550 super(_ValidatingListBase,self).
insert(i,x)
552 result = type(self).__name__
553 if hasattr(self,
'__label'):
554 result +=
' ' + self.__label
559 _ParameterTypeBase.__init__(self)
560 if len (arg) == 1
and not isinstance(arg[0],str):
565 super(_ValidatingParameterListBase,self).
__init__(*arg,**args)
575 for value
in iter(self):
577 config += options.indentation()
583 config += options.indentation()+
'}\n' 594 if hasattr(self,
"_nPerLine"):
595 nPerLine = self._nPerLine
598 if n>nPerLine: options.indent()
602 for i, v
in enumerate(self):
604 if n>nPerLine: result +=
'\n'+options.indentation()
607 if i % nPerLine == 0:
608 result +=
'\n'+options.indentation()
612 result +=
'\n'+options.indentation()
623 frame = inspect.getframeinfo(inspect.currentframe(level+1))
627 obj._filename = frame[0]
628 obj._lineNumber = frame[1]
633 for key,value
in six.iteritems(newParams):
637 elif isinstance(value, dict):
638 if isinstance(params[key],_Parameterizable):
640 p =pset.parameters_()
641 oldkeys = set(p.keys())
644 (
"%s.%s" if isinstance(key, str)
else "%s[%s]")%(keyDepth,key))
645 for k,v
in six.iteritems(p):
650 elif isinstance(params[key],_ValidatingParameterListBase):
651 if any(
not isinstance(k, int)
for k
in value.keys()):
652 raise TypeError(
"Attempted to change a list using a dict whose keys are not integers")
654 if any((k < 0
or k >= len(plist))
for k
in value.keys()):
655 raise IndexError(
"Attempted to set an index which is not in the list")
656 p =
dict(enumerate(plist))
659 (
"%s.%s" if isinstance(key, str)
else "%s[%s]")%(keyDepth,key))
660 for k,v
in six.iteritems(p):
663 raise ValueError(
"Attempted to change non PSet value "+keyDepth+
" using a dictionary")
664 elif isinstance(value,_ParameterTypeBase)
or (isinstance(key, int)):
669 if isinstance(value,_ParameterTypeBase):
675 if __name__ ==
"__main__":
684 self.assertEqual(t,[1])
686 self.assertEqual(t,[1])
688 self.assertEqual(t,[
"one"])
690 self.assertEqual(t,[1])
692 self.assertEqual(t,[1])
695 self.assertEqual(t,[1,2])
697 self.assertEqual(t,[1,2])
699 self.assertEqual(t,[
"one",
"two"])
701 self.assertEqual(t,[
"one",
"two"])
703 self.assertEqual(t,[1,2])
705 self.assertEqual(t,[1,2])
707 self.assertEqual(t,[1,2])
713 args = [i
for i
in xrange(0,300)]
716 pdump= t.dumpPython()
720 pythonized = eval( pdump, globals(),{
'cms':
cms()} )
721 self.assertEqual(t,pythonized)
724 self.assert_(isinstance(a, _ParameterTypeBase))
729 def _isValid(self,value):
731 a = __Test(
"MyType",t=__TestType(1), u=__TestType(2))
733 self.assertEqual(b.t.value(),1)
734 self.assertEqual(b.u.value(),2)
739 def _isValid(self,value):
742 def __init__(self,*arg,**args):
744 _ParameterTypeBase.__init__(self)
745 _Parameterizable.__init__(self,*arg,**args)
750 x = __PSet(a = __TestType(4),
752 c = __PSet(gamma = __TestType(5))))
759 c = a.clone(x =
dict(a=
None, c=
None))
760 self.assertEqual(a.t.value(),1)
761 self.assertEqual(a.u.value(),2)
762 self.assertEqual(b.t.value(),3)
763 self.assertEqual(b.u.value(),2)
764 self.assertEqual(b.v.value(),4)
765 self.assertEqual(b.x.a.value(),7)
766 self.assertEqual(b.x.b.value(),6)
767 self.assertEqual(b.x.c.gamma.value(),8)
768 self.assertEqual(b.x.d.value(),9)
769 self.assertEqual(hasattr(b,
"w"),
False)
770 self.assertEqual(hasattr(c.x,
"a"),
False)
771 self.assertEqual(hasattr(c.x,
"c"),
False)
772 self.assertRaises(TypeError,a.clone,
None,**{
"v":1})
775 def _isValid(self,value):
778 self.assertEqual(a.isModified(),
False)
780 self.assertEqual(a.isModified(),
False)
782 self.assertEqual(a.isModified(),
True)
784 self.assertEqual(a.isModified(),
False)
789 def _isValid(self,value):
791 class __DummyModule(
object):
797 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)
S & print(S &os, JobReport::InputFile const &f)
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