4 """Denotes a class that can be used by the Processes class"""
20 """base class for classes which are used as the 'parameters' for a ParameterSet"""
22 self.__dict__[
"_isFrozen"] =
False
31 return type(self).__name__
32 return 'untracked '+type(self).__name__
35 return 'cms.'+type(self).__name__
36 return 'cms.untracked.'+type(self).__name__
51 """base class for parameter classes which only hold a single value"""
53 super(_SimpleParameterTypeBase,self).
__init__()
55 if not self._isValid(value):
56 raise ValueError(str(value)+
" is not a valid "+str(type(self)))
60 if not self._isValid(value):
61 raise ValueError(str(value)+
" is not a valid "+str(type(self)))
70 if isinstance(other,_SimpleParameterTypeBase):
71 return self.
_value == other._value
72 return self.
_value == other
74 if isinstance(other,_SimpleParameterTypeBase):
75 return self.
_value != other._value
76 return self.
_value != other
80 """For injection purposes, pretend this is a new parameter type
81 then have a post process step which strips these out
83 def __init__(self,value, s='', loc=0, file=''):
84 super(UsingBlock,self).
__init__(value)
91 return isinstance(value,str)
93 """only used for cfg-parsing"""
100 parameterSet.addString(self.
isTracked(), myname, value)
103 return "process."+self.
value()
109 """Base class for classes which allow addition of _ParameterTypeBase data"""
111 self.__dict__[
'_Parameterizable__parameterNames'] = []
112 self.__dict__[
"_isFrozen"] =
False
113 """The named arguments are the 'parameters' which are added as 'python attributes' to the object"""
117 if type(block).__name__ !=
"PSet":
118 raise ValueError(
"Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
124 """Returns the name of the parameters"""
125 return self.__parameterNames[:]
130 param = self.__dict__[name]
131 if isinstance(param, _Parameterizable)
and param.isModified():
140 check that pset provided has the attribute chain
143 Eg, if params is [ 'attr1', 'attr2', 'attr3' ]
144 check for pset.attr1.attr2.attr3
146 returns True if parameter exists, False if not
154 Retrieve the specified parameter from the PSet Provided
155 given the attribute chain
157 returns None if not found
161 if type(params).__name__ ==
'str':
162 return getattr(self, params,
None)
164 lastParam = getattr(lastParam, param,
None)
166 if lastParam ==
None:
171 """Returns a dictionary of copies of the user-set parameters"""
175 result[name]=copy.deepcopy(self.__dict__[name])
179 if not isinstance(value,_ParameterTypeBase):
181 if name
in self.__dict__:
182 message =
"Duplicate insert of member " + name
183 message +=
"\nThe original parameters are:\n"
185 raise ValueError(message)
186 self.__dict__[name]=value
187 self.__parameterNames.append(name)
191 for name,value
in parameters.iteritems():
197 if self.
isFrozen()
and not (name
in [
"_Labelable__label",
"_isFrozen"]
or name.startswith(
'_')):
198 message =
"Object already added to a process. It is read only now\n"
199 message +=
" %s = %s" %(name, value)
200 message +=
"\nThe original parameters are:\n"
202 raise ValueError(message)
205 super(_Parameterizable,self).
__setattr__(name,value)
206 elif not name
in self.__dict__:
211 if isinstance(value,_ParameterTypeBase):
212 self.__dict__[name] = value
225 raise ValueError(
"Object already added to a process. It is read only now")
227 self.__parameterNames.remove(name)
230 raise TypeError(name+
" does not already exist, so it can only be set to a CMS python configuration type")
235 param = self.__dict__[name]
237 name2 = name.replace(
'-',
'_')
240 if name.startswith(
"using_"):
241 usings.append(options.indentation()+param.dumpPython(options))
243 others.append(options.indentation()+name2+
' = '+param.dumpPython(options))
247 resultList.extend(others)
248 return ',\n'.
join(resultList)+
'\n'
253 param = getattr(self,name)
254 param.insertInto(parameterSet, name)
258 """Base class for classes which are Parameterizable and have a 'type' assigned"""
260 self.__dict__[
'_TypedParameterizable__type'] = type_
266 arg = tuple([x
for x
in arg
if x !=
None])
267 super(_TypedParameterizable,self).
__init__(*arg,**kargs)
270 self._placeImpl(name,proc)
272 """returns the type of the object, e.g. 'FooProducer'"""
275 returnValue =_TypedParameterizable.__new__(type(self))
280 returnValue.__init__(self.__type,*args,
285 """Copies the object and allows one to modify the parameters of the clone.
286 New parameters may be added by specify the exact type
287 Modifying existing parameters can be done by just specifying the new
288 value without having to specify the type.
290 returnValue =_TypedParameterizable.__new__(type(self))
292 if len(myparams) == 0
and len(params)
and len(args):
296 for key,value
in params.iteritems():
298 if isinstance(value,_ParameterTypeBase):
303 if isinstance(value,_ParameterTypeBase):
306 self._Parameterizable__raiseBadSetAttr(key)
308 returnValue.__init__(self.__type,*args,
310 returnValue._isModified =
False
311 returnValue._isFrozen =
False
322 choices.extend(glob.glob(d+
'/*/*/'+label+
'.py'))
332 mod = __import__(name)
333 components = name.split(
'.')
334 for comp
in components[1:]:
335 mod = getattr(mod,comp)
336 if hasattr(mod,label):
337 default = getattr(mod,label)
338 if isinstance(default,_TypedParameterizable):
339 if(default.type_() == type):
341 for name
in default.parameterNames_():
342 params[name] = getattr(default,name)
347 config = self.__type +
' { \n'
349 param = self.__dict__[name]
351 config+=options.indentation()+param.configTypeName()+
' '+name+
' = '+param.configValue(options)+
'\n'
353 config += options.indentation()+
'}\n'
357 result =
"cms."+str(type(self).__name__)+
'("'+self.
type_()+
'"'
362 result +=
",\n"+_Parameterizable.dumpPython(self,options)+options.indentation() +
")\n"
370 label =
"process."+self.label_()
377 """ dumps the object with all attributes declared after the constructor"""
380 param = self.__dict__[name]
381 result += options.indentation() + myname +
"." + name +
" = " + param.dumpPython(options) +
"\n"
389 newpset = parameterSet.newPSet()
390 newpset.addString(
True,
"@module_label", self.
moduleLabel_(myname))
391 newpset.addString(
True,
"@module_type", self.
type_())
392 newpset.addString(
True,
"@module_edm_type", type(self).__name__)
399 """A 'mixin' used to denote that the class can be paired with a label (e.g. an EDProducer)"""
403 if not hasattr(self,
"_Labelable__label"):
404 raise RuntimeError(
"module has no label. Perhaps it wasn't inserted into the process?")
407 return hasattr(self,
"_Labelable__label")
and self.
__label is not None
419 return 'process.'+str(self.
__label)
422 myDeps=knownDeps.get(self.
label_(),
None)
424 if presentDeps != myDeps:
425 raise RuntimeError(
"the module "+self.
label_()+
" has two dependencies \n"
426 +str(presentDeps)+
"\n"
428 +
"Please modify sequences to rectify this inconsistency")
430 myDeps=set(presentDeps)
431 knownDeps[self.
label_()]=myDeps
432 presentDeps.add(self.
label_())
436 """A 'mixin' used to denote that the class can be used without a label (e.g. a Service)"""
439 class _ValidatingListBase(
list):
440 """Base class for a list which enforces that its entries pass a 'validity' test"""
442 super(_ValidatingListBase,self).
__init__(arg)
444 raise SyntaxError(
"named arguments ("+
','.
join([x
for x
in args])+
") passsed to "+str(type(self)))
446 raise TypeError(
"wrong types ("+
','.
join([str(type(value))
for value
in iter(self)])+
447 ") added to "+str(type(self)))
449 if isinstance(key,slice):
451 raise TypeError(
"wrong type being inserted into this container "+self.
_labelIfAny())
453 if not self._itemIsValid(value):
454 raise TypeError(
"can not insert the type "+str(type(value))+
" in container "+self.
_labelIfAny())
455 super(_ValidatingListBase,self).
__setitem__(key,value)
458 if isinstance(seq, str):
461 if not self._itemIsValid(item):
465 if not self._itemIsValid(x):
466 raise TypeError(
"wrong type being appended to container "+self.
_labelIfAny())
467 super(_ValidatingListBase,self).
append(x)
470 raise TypeError(
"wrong type being extended to container "+self.
_labelIfAny())
471 super(_ValidatingListBase,self).
extend(x)
474 raise TypeError(
"wrong type being added to container "+self.
_labelIfAny())
476 value = copy.copy(self)
480 if not self._itemIsValid(x):
481 raise TypeError(
"wrong type being inserted to container "+self.
_labelIfAny())
482 super(_ValidatingListBase,self).
insert(i,x)
484 result = type(self).__name__
485 if hasattr(self,
'__label'):
486 result +=
' ' + self.__label
491 _ParameterTypeBase.__init__(self)
492 if len (arg) == 1
and not isinstance(arg[0],str):
497 super(_ValidatingParameterListBase,self).
__init__(*arg,**args)
507 for value
in iter(self):
509 config += options.indentation()
515 config += options.indentation()+
'}\n'
528 for i, v
in enumerate(self):
530 if hasattr(self,
"_nPerLine"):
531 nPerLine = self._nPerLine
540 if i % nPerLine == 0:
541 result +=
'\n'+options.indentation()
550 while(start < len(self)):
566 frame = inspect.getframeinfo(inspect.currentframe(level+1))
570 obj._filename = frame[0]
571 obj._lineNumber = frame[1]
573 if __name__ ==
"__main__":
582 self.assertEqual(t,[1])
584 self.assertEqual(t,[1])
586 self.assertEqual(t,[
"one"])
588 self.assertEqual(t,[1])
590 self.assertEqual(t,[1])
593 self.assertEqual(t,[1,2])
595 self.assertEqual(t,[1,2])
597 self.assertEqual(t,[
"one",
"two"])
599 self.assertEqual(t,[
"one",
"two"])
601 self.assertEqual(t,[1,2])
603 self.assertEqual(t,[1,2])
605 self.assertEqual(t,[1,2])
611 args = [i
for i
in xrange(0,300)]
614 pdump= t.dumpPython()
618 pythonized = eval( pdump, globals(),{
'cms':
cms()} )
619 self.assertEqual(t,pythonized)
622 self.assert_(isinstance(a, _ParameterTypeBase))
627 def _isValid(self,value):
629 a = __Test(
"MyType",t=__TestType(1), u=__TestType(2))
631 self.assertEqual(b.t.value(),1)
632 self.assertEqual(b.u.value(),2)
637 def _isValid(self,value):
639 a = __Test(
"MyType",t=__TestType(1), u=__TestType(2))
640 b = a.clone(t=3, v=__TestType(4))
641 self.assertEqual(a.t.value(),1)
642 self.assertEqual(a.u.value(),2)
643 self.assertEqual(b.t.value(),3)
644 self.assertEqual(b.u.value(),2)
645 self.assertEqual(b.v.value(),4)
646 self.assertRaises(TypeError,a.clone,
None,**{
"v":1})
649 def _isValid(self,value):
652 self.assertEqual(a.isModified(),
False)
654 self.assertEqual(a.isModified(),
False)
656 self.assertEqual(a.isModified(),
True)
658 self.assertEqual(a.isModified(),
False)
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...
static std::string join(char **cmd)
perl if(1 lt scalar(@::datatypes))
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