ATLAS Offline Software
Loading...
Searching...
No Matches
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
11from GaudiSequencer.PyComps import PyEvtFilter
12from AthenaPython.PyAthena import StatusCode
13
14class 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
__init__(self, name='filterFromFile', **kw)
Definition PyCompsExt.py:18
void initialize()