ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.TrigValSteering.PyStep.PyStep Class Reference
Inheritance diagram for python.TrigValSteering.PyStep.PyStep:
Collaboration diagram for python.TrigValSteering.PyStep.PyStep:

Public Member Functions

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

Public Attributes

 func
 
 func_kwargs
 
 output_stream
 
 result
 

Detailed Description

Step calling a python function

Definition at line 13 of file PyStep.py.

Constructor & Destructor Documentation

◆ __init__()

def 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()

def 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__}'

Member Data Documentation

◆ func

python.TrigValSteering.PyStep.PyStep.func

Definition at line 19 of file PyStep.py.

◆ func_kwargs

python.TrigValSteering.PyStep.PyStep.func_kwargs

Definition at line 20 of file PyStep.py.

◆ output_stream

python.TrigValSteering.PyStep.PyStep.output_stream

Definition at line 21 of file PyStep.py.

◆ result

python.TrigValSteering.PyStep.PyStep.result

Definition at line 34 of file PyStep.py.


The documentation for this class was generated from the following file:
grepfile.info
info
Definition: grepfile.py:38
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
error
Definition: IImpactPoint3dEstimator.h:70