ATLAS Offline Software
Loading...
Searching...
No Matches
python.JobProperties.JobProperty Class Reference
Inheritance diagram for python.JobProperties.JobProperty:
Collaboration diagram for python.JobProperties.JobProperty:

Public Member Functions

 __init__ (self, context='')
 __bool__ (self)
 __eq__ (self, rhs)
 __lt__ (self, rhs)
 __call__ (self)
 __str__ (self)
 __iadd__ (self, value)
 is_locked (self)
 set_On (self)
 set_Off (self)
 lock (self)
 unlock (self)
 __setattr__ (self, name, n_value)
 set_Value (self, n_value)
 get_Value (self)
 set_Value_and_Lock (self, n_value)
 isDefault (self)
 help (self)
 toBePrinted (self)
 print_JobProperty (self, mode='minimal')
 __new__ (self, name, bases, dct)

Static Public Attributes

bool statusOn = False
 allowedTypes = list()
 allowedValues = list()
 StoredValue = None

Protected Member Functions

 _do_action (self)
 _undo_action (self)

Protected Attributes

str _context_name = context+'.'+self.__class__.__name__

Static Protected Attributes

 _log = Logging.logging.getLogger('JobProperty ::')
 _nInstancesContextDict = dict()
bool _locked = False

Private Attributes

 __name__ = self.__class__.__name__
 __class__
 __doc__

Detailed Description

 Base class for the job properties.  
    
       The job properties are class definitions that will be 
    instanciated at the time the job property is added to global 
    container for the job properties called  "jobproperties". 
    The job properties can be also added to sub-containers within 
    the "jobproperties" container.        
  

    All the job properties must be defined as subclasses of 
    "JobProperty" and, as derived classes, can re-define: 

    statusOn, allowedTypes and allowedValues and StoredValue   

    The setting of the StoredValue will automatically check the new 
    value against the lists allowedTypes and allowedValues. A given 
    StoredValue can not be changed if the corresponding job property
    is locked. 
   
    The actual Value of the JobProperty is (statusOn AND StoredValue)

Definition at line 105 of file JobProperties.py.

Constructor & Destructor Documentation

◆ __init__()

python.JobProperties.JobProperty.__init__ ( self,
context = '' )
 Each JobProperty has only one possible instance in a given
    context. The context is given by the container and sub-containers
    to which the job property belongs. 

Definition at line 137 of file JobProperties.py.

137 def __init__(self,context=''):
138 """ Each JobProperty has only one possible instance in a given
139 context. The context is given by the container and sub-containers
140 to which the job property belongs.
141 """
142 if jobPropertiesDisallowed:
143 raise RuntimeError("JobProperty should not be called in pure CA config")
144
145 context_name=context+'.'+self.__class__.__name__
146 if not (context_name in self.__class__._nInstancesContextDict.keys()):
147 self.__class__._nInstancesContextDict[context_name]=self
148 self.__name__=self.__class__.__name__
149 self._context_name=context+'.'+self.__class__.__name__
150 else:
151 self._log.error("There is already an instance of %s at %s ",
152 self.__class__.__name__, context_name)
153 raise RuntimeError('JobProperties: JobProperty:: __init__()')
154

Member Function Documentation

◆ __bool__()

python.JobProperties.JobProperty.__bool__ ( self)

Definition at line 155 of file JobProperties.py.

155 def __bool__(self):
156 return self.get_Value()
157

◆ __call__()

python.JobProperties.JobProperty.__call__ ( self)

Definition at line 174 of file JobProperties.py.

174 def __call__(self):
175 return self.get_Value()
176

◆ __eq__()

python.JobProperties.JobProperty.__eq__ ( self,
rhs )

Definition at line 158 of file JobProperties.py.

158 def __eq__(self, rhs):
159 if isinstance(rhs, JobProperty):
160 # FIXME: should we only allow comparison between same class
161 # rather than b/w JobProperties ?
162 # OTOH, JobProperty-derived classes are 'singleton'...
163 return self() == rhs()
164 return self() == rhs
165

◆ __iadd__()

python.JobProperties.JobProperty.__iadd__ ( self,
value )

Definition at line 180 of file JobProperties.py.

180 def __iadd__(self,value):
181 aux=self.get_Value()
182 aux+=value
183 self.StoredValue = aux
184 return self.StoredValue
185
186

◆ __lt__()

python.JobProperties.JobProperty.__lt__ ( self,
rhs )

Definition at line 166 of file JobProperties.py.

166 def __lt__(self, rhs):
167 if isinstance(rhs, JobProperty):
168 # FIXME: should we only allow comparison between same class
169 # rather than b/w JobProperties ?
170 # OTOH, JobProperty-derived classes are 'singleton'...
171 return self() < rhs()
172 return self() < rhs
173

◆ __new__()

python.JobProperties._JobPropertyMeta.__new__ ( self,
name,
bases,
dct )
inherited

Definition at line 78 of file JobProperties.py.

78 def __new__( self, name, bases, dct ):
79 # StoredValue type check
80 try:
81 sv = dct[ 'StoredValue' ]
82 if sv is not None and not _isCompatible( dct[ 'allowedTypes' ], sv ):
83 raise TypeError(
84 'type of StoredValue (%s) not in allowedTypes (%s)' %
85 (type(sv).__name__,dct[ 'allowedTypes' ])
86 )
87 except KeyError:
88 pass
89
90 # StoredValue value check
91 try:
92 sv = dct[ 'StoredValue' ]
93 if sv is not None and dct[ 'allowedValues' ] and sv not in dct[ 'allowedValues' ]:
94 raise TypeError(
95 'value of StoredValue (%s) not in allowedValues (%s)' %
96 (str(sv),dct[ 'allowedValues' ])
97 )
98 except KeyError:
99 pass
100
101 return type.__new__( self, name, bases, dct )
102
103
104@functools.total_ordering

◆ __setattr__()

python.JobProperties.JobProperty.__setattr__ ( self,
name,
n_value )

Definition at line 245 of file JobProperties.py.

245 def __setattr__(self, name, n_value):
246 if hasattr(self, name):
247 if name=='StoredValue' and not(self._locked):
248 if len(self.allowedValues) == 0 or \
249 True in [ x == n_value for x in self.allowedValues ]:
250 # WLAV: the following is rather puzzling in the difference
251 # of treatment of bools, especially since it does not work
252 # as expected, and even worse for compatible types. It is
253 # left as-is in place, since changing it has side-effects on
254 # RecExCommon/myTopOptions.py ...
255 if len(self.allowedTypes) == 0:
256 self.__dict__[name] = n_value
257 self.set_On()
258 elif _isCompatible(self.allowedTypes, n_value):
259 self.__dict__[name] = n_value
260 if isinstance(n_value, bool) and n_value is False:
261 self.set_Off()
262 else:
263 self.set_On()
264 else:
265 raise ValueError(
266 ' %s is not the expected type for: %s' %
267 (n_value, self._context_name)
268 )
269 else:
270 raise ValueError(
271 ' %s is not the expected type and/or the value is not allowed for: %s' %
272 (n_value, self._context_name)
273 )
274 elif name == 'StoredValue' and self._locked:
275 self._log.info('The JobProperty %s is blocked', self.__name__)
276 else:
277 self.__dict__[name] = n_value
278 elif name == '__name__' or name == '_context_name':
279 self.__dict__[name] = n_value
280 else:
281 raise AttributeError("JobProperty:: You cannot add attributes to %s" % self)
282

◆ __str__()

python.JobProperties.JobProperty.__str__ ( self)

Definition at line 177 of file JobProperties.py.

177 def __str__(self):
178 return self.print_JobProperty('print_v')
179

◆ _do_action()

python.JobProperties.JobProperty._do_action ( self)
protected
 A place-holder for actions to be taken at the time 
  the JobProperty.StoredValue is set or JobProperty.statusOn 
  is set to True. 

  (for advanced use)

Definition at line 190 of file JobProperties.py.

190 def _do_action(self):
191 """ A place-holder for actions to be taken at the time
192 the JobProperty.StoredValue is set or JobProperty.statusOn
193 is set to True.
194
195 (for advanced use)
196 """
197 pass
198

◆ _undo_action()

python.JobProperties.JobProperty._undo_action ( self)
protected
 A place-holder for actions to be taken at the time 
  the JobProperty.statusOn is set to False. 

  (for advanced use)

Definition at line 199 of file JobProperties.py.

199 def _undo_action(self):
200 """ A place-holder for actions to be taken at the time
201 the JobProperty.statusOn is set to False.
202
203 (for advanced use)
204 """
205 pass
206

◆ get_Value()

python.JobProperties.JobProperty.get_Value ( self)
 Gets the value of the job property.

    This is the recommended way top retrieve the actual
   value of the job property. For boolean properties it
   gives the and(statusOn,StoredValue). For the rest of the
   properties it gives the StoredValue if the statusOn==True
   otherwise it gives None. 

Definition at line 299 of file JobProperties.py.

299 def get_Value(self):
300 """ Gets the value of the job property.
301
302 This is the recommended way top retrieve the actual
303 value of the job property. For boolean properties it
304 gives the and(statusOn,StoredValue). For the rest of the
305 properties it gives the StoredValue if the statusOn==True
306 otherwise it gives None.
307 """
308 obj_p=object.__getattribute__(self, 'StoredValue')
309 if isinstance(obj_p, type(True)):
310 return obj_p & self.statusOn
311 else:
312 if self.statusOn:
313 return obj_p
314 else:
315 self._log.warning('You are attempting to access the job'+
316 'property %s which has not been set', self._context_name)
317 return None
318

◆ help()

python.JobProperties.JobProperty.help ( self)
 Prints the documentation available for the JobProperty. 
    together with the actual value, values allowed and types
    allowed.   

Definition at line 335 of file JobProperties.py.

335 def help(self):
336 """ Prints the documentation available for the JobProperty.
337 together with the actual value, values allowed and types
338 allowed.
339 """
340 self._log.info('### Help for the class %s ###',
341 self.__class__)
342 self._log.info(self.__doc__)
343
344 print ('## job property:',self._context_name, self.statusOn, self.StoredValue)
345 print ('## allowed Values:',self.allowedValues)
346 print ('## default Value:', self.__class__.StoredValue )
347 print ('## allowed Types :',self.allowedTypes )
348 self._log.info('### End of the help for the class %s ###',
349 self.__class__)
350

◆ is_locked()

python.JobProperties.JobProperty.is_locked ( self)

Definition at line 187 of file JobProperties.py.

187 def is_locked(self):
188 return self._locked
189

◆ isDefault()

python.JobProperties.JobProperty.isDefault ( self)
check whether a flag has been modified or if it is still containing
its default value.

Definition at line 325 of file JobProperties.py.

325 def isDefault (self):
326 """check whether a flag has been modified or if it is still containing
327 its default value.
328 """
329 val = self.__getattribute__('StoredValue')
330 dft = self.__class__.StoredValue
331 return val==dft
332
333
334

◆ lock()

python.JobProperties.JobProperty.lock ( self)
 lock the property

Definition at line 225 of file JobProperties.py.

225 def lock(self):
226 """ lock the property
227 """
228 self._locked=True
229

◆ print_JobProperty()

python.JobProperties.JobProperty.print_JobProperty ( self,
mode = 'minimal' )
 Prints the information of the JobProperty  

    The available options are: 'minimal','full','tree','tree&value','tree&valuenondefault'

Definition at line 374 of file JobProperties.py.

374 def print_JobProperty(self,mode='minimal'):
375 """ Prints the information of the JobProperty
376
377 The available options are: 'minimal','full','tree','tree&value','tree&valuenondefault'
378 """
379 indent=''
380 obj_p=object.__getattribute__(self, 'StoredValue')
381 if self.statusOn:
382 obj_ps=obj_p
383 else:
384 obj_ps=None
385 for i in range(self._context_name.count('.')-2):
386 indent+='-'
387 if self.is_locked():
388 indent+='x'
389 else:
390 indent+='-'
391
392 if mode=='minimal':
393 self._log.info(" %s-> %s = %s ",indent,
394 self._context_name,pprint.pformat(obj_ps) )
395
396 elif(mode=='full'):
397 if len(self.allowedTypes)>0:
398 at=self.allowedTypes
399 else:
400 at='- - -'
401 if len(self.allowedValues)>0:
402 av=pprint.pformat(self.allowedValues)
403 else:
404 av='- - -'
405 self._log.info("%s-> %s = %s\n %40s %s\n %40s \
406 %s\n %40s %s\n %40s %s\n %40s %s\n %40s %s",
407 indent,
408 self._context_name,
409 self.__getattribute__('StoredValue'),
410 'allowedTypes :',at,
411 'allowedValues :',av,
412 'default value :', self.__class__.StoredValue,
413 'statusOn :',self.statusOn,
414 'locked :',self.is_locked(),
415 'StoredValue :',pprint.pformat(obj_p))
416 elif(mode=='tree'):
417 print (' |'+indent+' '+self.__name__)
418 elif(mode.startswith('tree&value')):
419 if mode=='tree&value':
420 printit=True
421 elif mode=='tree&valuenondefault':
422 if self.isDefault():
423 printit=False
424 else:
425 printit=True
426 else:
427 raise RuntimeError("This is a non valid print mode %s " % (mode,))
428 if printit:
429 print (' |'+indent+' '+self.__name__+" = "+\
430 self.toBePrinted())
431# fnToBePrinted(self)
432
433 elif(mode=='print_v'):
434 return ' |'+indent+' '+self.__name__+" = "+\
435 self.toBePrinted()
436 # fnToBePrinted(self)
437
438 else:
439 raise ValueError('Unknow mode, possible modes are: '
440 'minimal, full, tree, tree&value ')
441
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146

◆ set_Off()

python.JobProperties.JobProperty.set_Off ( self)
 Sets statusOn equals to False. 

Definition at line 216 of file JobProperties.py.

216 def set_Off(self):
217 """ Sets statusOn equals to False.
218 """
219 if not(self._locked):
220 self.__dict__['statusOn']=False
221 self._undo_action()
222 else:
223 self._log.info('The JobProperty %s is blocked', self.__name__)
224

◆ set_On()

python.JobProperties.JobProperty.set_On ( self)
 Sets statusOn equals to True.

Definition at line 207 of file JobProperties.py.

207 def set_On(self):
208 """ Sets statusOn equals to True.
209 """
210 if not(self._locked):
211 self.__dict__['statusOn']=True
212 self._do_action()
213 else:
214 self._log.info('The JobProperty %s is blocked', self.__name__)
215

◆ set_Value()

python.JobProperties.JobProperty.set_Value ( self,
n_value )
 Sets the value of the JobProperty . 
   
          MyJobProperty.set_Value(NewValue)

    is equivalent to
       
          MyJobProperty=NewValue 

      It is checked the type and if the value is allowed. The 
    statusOn is set to True automatically.
       This method is here for backwards compatibility. 

Definition at line 283 of file JobProperties.py.

283 def set_Value(self, n_value):
284 """ Sets the value of the JobProperty .
285
286 MyJobProperty.set_Value(NewValue)
287
288 is equivalent to
289
290 MyJobProperty=NewValue
291
292 It is checked the type and if the value is allowed. The
293 statusOn is set to True automatically.
294 This method is here for backwards compatibility.
295 """
296#Joerg S/Martin W advice
297 self.StoredValue=n_value
298

◆ set_Value_and_Lock()

python.JobProperties.JobProperty.set_Value_and_Lock ( self,
n_value )
 Sets the value of the JobProperty and lock it in one command . 

Definition at line 319 of file JobProperties.py.

319 def set_Value_and_Lock(self,n_value):
320 """ Sets the value of the JobProperty and lock it in one command .
321 """
322 self.set_Value(n_value)
323 self.lock()
324

◆ toBePrinted()

python.JobProperties.JobProperty.toBePrinted ( self)
 compute a string which is : empty if flag is set to default value
                                (<DefaultValue> if flag not set to default value or flas is off  

Definition at line 351 of file JobProperties.py.

351 def toBePrinted (self):
352 """ compute a string which is : empty if flag is set to default value
353 (<DefaultValue> if flag not set to default value or flas is off
354 """
355 if self.statusOn:
356 derived = self.get_Value() # can be overwritten
357 else:
358 derived = None
359 stored = self.__getattribute__('StoredValue')
360 default = self.__class__.StoredValue
361 if derived==stored:
362 tbp = '%s' % pprint.pformat(stored)
363 else:
364 tbp= '%s (Stored: %s)' %(pprint.pformat(derived),pprint.pformat(stored))
365 if stored!=default:
366 tbp= '%s (Default: %s)' %(tbp,pprint.pformat(default))
367
368 if not self.statusOn:
369 tbp = 'Off : %s ' % tbp
370
371 return tbp
372
373

◆ unlock()

python.JobProperties.JobProperty.unlock ( self)
 unlock the property

Definition at line 230 of file JobProperties.py.

230 def unlock(self):
231 """ unlock the property
232 """
233 self._locked=False
234 self._log.warning('The property %s is being unlocked ',
235 self._context_name)
236
237
238# def __getattribute__(self, name):
239# obj_p=object.__getattribute__(self, name)
240# if name=='StoredValue':
241# self._log.error('You must access the value of the jobproperty'+
242# ' using the get_Value() method. ')
243# return obj_p
244

Member Data Documentation

◆ __class__

python.JobProperties.JobProperty.__class__
private

Definition at line 341 of file JobProperties.py.

◆ __doc__

python.JobProperties.JobProperty.__doc__
private

Definition at line 342 of file JobProperties.py.

◆ __name__

python.JobProperties.JobProperty.__name__ = self.__class__.__name__
private

Definition at line 148 of file JobProperties.py.

◆ _context_name

python.JobProperties.JobProperty._context_name = context+'.'+self.__class__.__name__
protected

Definition at line 149 of file JobProperties.py.

◆ _locked

python.JobProperties.JobProperty._locked = False
staticprotected

Definition at line 135 of file JobProperties.py.

◆ _log

python.JobProperties.JobProperty._log = Logging.logging.getLogger('JobProperty ::')
staticprotected

Definition at line 133 of file JobProperties.py.

◆ _nInstancesContextDict

python.JobProperties.JobProperty._nInstancesContextDict = dict()
staticprotected

Definition at line 134 of file JobProperties.py.

◆ allowedTypes

python.JobProperties.JobProperty.allowedTypes = list()
static

Definition at line 130 of file JobProperties.py.

◆ allowedValues

python.JobProperties.JobProperty.allowedValues = list()
static

Definition at line 131 of file JobProperties.py.

◆ statusOn

python.JobProperties.JobProperty.statusOn = False
static

Definition at line 129 of file JobProperties.py.

◆ StoredValue

python.JobProperties.JobProperty.StoredValue = None
static

Definition at line 132 of file JobProperties.py.


The documentation for this class was generated from the following file: