ATLAS Offline Software
PyCompsExt.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 # @file: GaudiSequencer/python/PyCompsExt.py
4 # @purpose: Library defines a class for filtering events. Allows to provide run/event numbers from a file.
5 # @author: Oldrich Kepka <oldrich.kepka@cern.ch>
6 
7 
8 __doc__ = 'Library defines a class for filtering events. Allows to provide run/event numbers from a file.'
9 __author__ = 'Oldrich Kepka <oldrich.kepka@cern.ch'
10 
11 from GaudiSequencer.PyComps import PyEvtFilter
12 from AthenaPython.PyAthena import StatusCode
13 
14 class PyEvtFilterFromFile (PyEvtFilter):
15  """ Algorithm which loads list of runnunber/eventnumbers from file for filtering and pass it to PyEvtFilter
16  """
17 
18  def __init__(self, name='filterFromFile', **kw):
19  super(PyEvtFilterFromFile, self).__init__(name,**kw)
20 
21  self.input_file = kw.get('selectorInputFile', None)
22 
23  def initialize(self):
24 
25  _info = self.msg.info
26  _error = self.msg.error
27 
28  _info('==> PyEvtFilterFromFile initialize')
29  if not self.input_file:
30  _error('Input_file is required.')
31  return StatusCode.Failure
32  try:
33  f = open(self.input_file, 'r')
34  except IOError:
35  _error = self.msg.error('File {} cannot be opened.'.format(self.input_file))
36  return StatusCode.Failure
37  else:
38  _info('==> File {} opened. Loading Runnumber/Eventnumber list'.format(self.input_file))
39  with f:
40  self.evt_list = []
41  for line in f:
42  if '#' in line:
43  continue
44 
45  numbers = line.split()
46 
47  if not numbers:
48  continue
49  if len(numbers) != 2:
50  self.msg.warning('Following line cannot be parsed: {}'.format(line))
51 
52  self.evt_list.append((int(numbers[0]), int(numbers[1])))
53 
54  super(PyEvtFilterFromFile,self).initialize()
55  return StatusCode.Success
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.PyCompsExt.PyEvtFilterFromFile.input_file
input_file
Definition: PyCompsExt.py:21
python.PyCompsExt.PyEvtFilterFromFile.initialize
def initialize(self)
Definition: PyCompsExt.py:23
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.PyCompsExt.PyEvtFilterFromFile
Definition: PyCompsExt.py:14
python.PyCompsExt.PyEvtFilterFromFile.evt_list
evt_list
Definition: PyCompsExt.py:40
python.PyCompsExt.PyEvtFilterFromFile.__init__
def __init__(self, name='filterFromFile', **kw)
Definition: PyCompsExt.py:18
Trk::open
@ open
Definition: BinningType.h:40
error
Definition: IImpactPoint3dEstimator.h:70