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

Public Member Functions

 __init__ (self, func, **kwargs)
 run (self, dry_run=False)

Public Attributes

 func = func
 func_kwargs = dict([(k,v) for k,v in kwargs.items() if k != 'name'])
 output_stream = Step.OutputStream.STDOUT_ONLY
 name
int result = 0

Detailed Description

Step calling a python function

Definition at line 13 of file PyStep.py.

Constructor & Destructor Documentation

◆ __init__()

python.TrigValSteering.PyStep.PyStep.__init__ ( self,
func,
** kwargs )

Definition at line 16 of file PyStep.py.

16 def __init__(self, func, **kwargs):
17 name = kwargs.get('name') or func.__name__
18 super(PyStep, self).__init__(name)
19 self.func = func
20 self.func_kwargs = dict([(k,v) for k,v in kwargs.items() if k != 'name'])
21 self.output_stream = Step.OutputStream.STDOUT_ONLY
22

Member Function Documentation

◆ run()

python.TrigValSteering.PyStep.PyStep.run ( self,
dry_run = False )

Definition at line 23 of file PyStep.py.

23 def run(self, dry_run=False):
24
25 self.log.info('Running %s step', self.name)
26
27 dest = sys.stdout
28 if self.output_stream == self.OutputStream.NO_PRINT:
29 dest = None
30 elif self.output_stream in [self.OutputStream.FILE_ONLY, self.OutputStream.FILE_AND_STDOUT]:
31 dest = open(self.get_log_file_name(), 'w')
32
33 if dry_run:
34 self.result = 0
35 else:
36 try:
37 with contextlib.redirect_stdout(dest), contextlib.redirect_stderr(dest):
38 self.result = self.func(**self.func_kwargs)
39
40 # Poor man's implementation of 'tee'
41 if self.output_stream == self.OutputStream.FILE_AND_STDOUT:
42 dest.close()
43 print(open(dest.name).read())
44
45 # In case function does not return a value, assume success
46 if self.result is None:
47 self.result = 0
48 except Exception as e:
49 self.log.error('Exception calling %s: %s', self.func.__name__, e)
50 self.result = 1
51
52 return self.result, f'# (internal) {self.func.__name__}'
void print(char *figname, TCanvas *c1)
Definition run.py:1
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)

Member Data Documentation

◆ func

python.TrigValSteering.PyStep.PyStep.func = func

Definition at line 19 of file PyStep.py.

◆ func_kwargs

python.TrigValSteering.PyStep.PyStep.func_kwargs = dict([(k,v) for k,v in kwargs.items() if k != 'name'])

Definition at line 20 of file PyStep.py.

◆ name

python.TrigValSteering.PyStep.PyStep.name

Definition at line 25 of file PyStep.py.

◆ output_stream

python.TrigValSteering.PyStep.PyStep.output_stream = Step.OutputStream.STDOUT_ONLY

Definition at line 21 of file PyStep.py.

◆ result

python.TrigValSteering.PyStep.PyStep.result = 0

Definition at line 34 of file PyStep.py.


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