Belle II Software development
CalibrationBase Class Reference
Inheritance diagram for CalibrationBase:
Calibration

Public Member Functions

 __init__ (self, name, input_files=None)
 
 run (self)
 
 is_valid (self)
 
 depends_on (self, calibration)
 
 dependencies_met (self)
 
 failed_dependencies (self)
 

Public Attributes

 name = name
 Name of calibration object.
 
list future_dependencies = []
 List of calibration objects that depend on this one.
 
list dependencies = []
 List of calibration objects, where each one is a dependency of this one.
 
dict files_to_iovs = {}
 File -> Iov dictionary, should be :
 
list input_files = input_files
 Files used for collection procedure.
 
 iov = None
 IoV which will be calibrated.
 
str output_database_dir = ""
 The directory where we'll store the local database payloads from this calibration.
 
bool save_payloads = True
 Marks this Calibration as one which has payloads that should be copied and uploaded.
 
list jobs_to_submit = []
 A simple list of jobs that this Calibration wants submitted at some point.
 

Static Public Attributes

str end_state = "completed"
 The name of the successful completion state.
 
str fail_state = "failed"
 The name of the failure state.
 

Protected Member Functions

 _apply_calibration_defaults (self, defaults)
 

Detailed Description

Abstract base class of Calibration types. The CAF implements the :py:class:`Calibration` class which inherits from
this and runs the C++ CalibrationCollectorModule and CalibrationAlgorithm classes. But by inheriting from this
class and providing the minimal necessary methods/attributes you could plug in your own Calibration types
that doesn't depend on the C++ CAF at all and run everything in your own way.

.. warning:: Writing your own class inheriting from :py:class:`CalibrationBase` class is not recommended!
                         But it's there if you really need it.

Parameters:
    name (str): Name of this calibration object. Should be unique if you are going to run it.

Keyword Arguments:
    input_files (list[str]): Input files for this calibration. May contain wildcard expressions usable by `glob.glob`.

Definition at line 317 of file framework.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
name,
input_files = None )
 

Definition at line 340 of file framework.py.

340 def __init__(self, name, input_files=None):
341 """
342 """
343 super().__init__()
344
345 self.name = name
346
347 self.future_dependencies = []
348
349 self.dependencies = []
350
356 self.files_to_iovs = {}
357 if input_files:
358
359 self.input_files = input_files
360 else:
361 self.input_files = []
362
363
364 self.iov = None
365
366 self.output_database_dir = ""
367
369 self.save_payloads = True
370
371 self.jobs_to_submit = []
372

Member Function Documentation

◆ _apply_calibration_defaults()

_apply_calibration_defaults ( self,
defaults )
protected
We pass in default calibration options from the `CAF` instance here if called.
Won't overwrite any options already set.

Definition at line 431 of file framework.py.

431 def _apply_calibration_defaults(self, defaults):
432 """
433 We pass in default calibration options from the `CAF` instance here if called.
434 Won't overwrite any options already set.
435 """
436 for key, value in defaults.items():
437 try:
438 if getattr(self, key) is None:
439 setattr(self, key, value)
440 except AttributeError:
441 print(f"The calibration {self.name} does not support the attribute {key}.")
442
443

◆ dependencies_met()

dependencies_met ( self)
Checks if all of the Calibrations that this one depends on have reached a successful end state.

Definition at line 415 of file framework.py.

415 def dependencies_met(self):
416 """
417 Checks if all of the Calibrations that this one depends on have reached a successful end state.
418 """
419 return all(map(lambda x: x.state == x.end_state, self.dependencies))
420
STL class.

◆ depends_on()

depends_on ( self,
calibration )
Parameters:
    calibration (`CalibrationBase`): The Calibration object which will produce constants that this one depends on.

Adds dependency of this calibration on another i.e. This calibration
will not run until the dependency has completed, and the constants produced
will be used via the database chain.

You can define multiple dependencies for a single calibration simply
by calling this multiple times. Be careful when adding the calibration into
the `CAF` not to add a circular/cyclic dependency. If you do the sort will return an
empty order and the `CAF` processing  will fail.

This function appends to the `CalibrationBase.dependencies` and `CalibrationBase.future_dependencies` attributes of this
`CalibrationBase` and the input one respectively. This prevents us having to do too much recalculation later on.

Definition at line 387 of file framework.py.

387 def depends_on(self, calibration):
388 """
389 Parameters:
390 calibration (`CalibrationBase`): The Calibration object which will produce constants that this one depends on.
391
392 Adds dependency of this calibration on another i.e. This calibration
393 will not run until the dependency has completed, and the constants produced
394 will be used via the database chain.
395
396 You can define multiple dependencies for a single calibration simply
397 by calling this multiple times. Be careful when adding the calibration into
398 the `CAF` not to add a circular/cyclic dependency. If you do the sort will return an
399 empty order and the `CAF` processing will fail.
400
401 This function appends to the `CalibrationBase.dependencies` and `CalibrationBase.future_dependencies` attributes of this
402 `CalibrationBase` and the input one respectively. This prevents us having to do too much recalculation later on.
403 """
404 # Check that we don't have two calibration names that are the same
405 if self.name != calibration.name:
406 # Tests if we have the calibrations added as dependencies already and adds if not
407 if calibration not in self.dependencies:
408 self.dependencies.append(calibration)
409 if self not in calibration.dependencies:
410 calibration.future_dependencies.append(self)
411 else:
412 B2WARNING(f"Tried to add {calibration} as a dependency for {self} but they have the same name."
413 "Dependency was not added.")
414

◆ failed_dependencies()

failed_dependencies ( self)
Returns the list of calibrations in our dependency list that have failed.

Definition at line 421 of file framework.py.

421 def failed_dependencies(self):
422 """
423 Returns the list of calibrations in our dependency list that have failed.
424 """
425 failed = []
426 for calibration in self.dependencies:
427 if calibration.state == self.fail_state:
428 failed.append(calibration)
429 return failed
430

◆ is_valid()

is_valid ( self)
A simple method you should implement that will return True or False depending on whether
the Calibration has been set up correctly and can be run safely.

Reimplemented in Calibration.

Definition at line 381 of file framework.py.

381 def is_valid(self):
382 """
383 A simple method you should implement that will return True or False depending on whether
384 the Calibration has been set up correctly and can be run safely.
385 """
386

◆ run()

run ( self)
The most important method. Runs inside a new Thread and is called from `CalibrationBase.start`
once the dependencies of this `CalibrationBase` have returned with state == end_state i.e. "completed".

Reimplemented in Calibration.

Definition at line 374 of file framework.py.

374 def run(self):
375 """
376 The most important method. Runs inside a new Thread and is called from `CalibrationBase.start`
377 once the dependencies of this `CalibrationBase` have returned with state == end_state i.e. "completed".
378 """
379

Member Data Documentation

◆ dependencies

list dependencies = []

List of calibration objects, where each one is a dependency of this one.

Definition at line 349 of file framework.py.

◆ end_state

str end_state = "completed"
static

The name of the successful completion state.

The :py:class:CAF will use this as the state to decide when the Calibration is completed.

Definition at line 335 of file framework.py.

◆ fail_state

str fail_state = "failed"
static

The name of the failure state.

The :py:class:CAF will use this as the state to decide when the Calibration failed.

Definition at line 338 of file framework.py.

◆ files_to_iovs

dict files_to_iovs = {}

File -> Iov dictionary, should be :

{absolute_file_path:iov} : Where iov is a :py:class:IoV <caf.utils.IoV> object. Will be filled during CAF.run() if empty. To improve performance you can fill this yourself before calling CAF.run()

Reimplemented in Calibration, and Calibration.

Definition at line 356 of file framework.py.

◆ future_dependencies

list future_dependencies = []

List of calibration objects that depend on this one.

Definition at line 347 of file framework.py.

◆ input_files

list input_files = input_files

Files used for collection procedure.

Reimplemented in Calibration, and Calibration.

Definition at line 359 of file framework.py.

◆ iov

iov = None

IoV which will be calibrated.

This is set by the CAF itself when calling CAF.run()

Definition at line 364 of file framework.py.

◆ jobs_to_submit

list jobs_to_submit = []

A simple list of jobs that this Calibration wants submitted at some point.

Definition at line 371 of file framework.py.

◆ name

name = name

Name of calibration object.

This must be unique when adding into the py:class:CAF.

Definition at line 345 of file framework.py.

◆ output_database_dir

str output_database_dir = ""

The directory where we'll store the local database payloads from this calibration.

Definition at line 366 of file framework.py.

◆ save_payloads

bool save_payloads = True

Marks this Calibration as one which has payloads that should be copied and uploaded.

Defaults to True, and should only be False if this is an intermediate Calibration who's payloads are never needed.

Definition at line 369 of file framework.py.


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