Skip to content
Snippets Groups Projects
Commit 6eea3395 authored by Adam Edward Barton's avatar Adam Edward Barton
Browse files

Merge branch 'cherry-pick-a4525c6c-master' into 'master'

Sweeping !41777 from 21.0 to master.
PyEvtFilterFromFile - extention of PyEvtFilter functionality

See merge request !41858
parents bfd478fc 6469b59e
No related branches found
No related tags found
6 merge requests!58791DataQualityConfigurations: Modify L1Calo config for web display,!46784MuonCondInterface: Enable thread-safety checking.,!46776Updated LArMonitoring config file for WD to match new files produced using MT,!45405updated ART test cron job,!42417Draft: DIRE and VINCIA Base Fragments for Pythia 8.3,!41858Sweeping !41777 from 21.0 to master. PyEvtFilterFromFile - extention of PyEvtFilter functionality
# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
# @file: GaudiSequencer/python/PyCompsExt.py
# @purpose: Library defines a class for filtering events. Allows to provide run/event numbers from a file.
# @author: Oldrich Kepka <oldrich.kepka@cern.ch>
__doc__ = 'Library defines a class for filtering events. Allows to provide run/event numbers from a file.'
__author__ = 'Oldrich Kepka <oldrich.kepka@cern.ch'
from GaudiSequencer.PyComps import PyEvtFilter
from AthenaPython.PyAthena import StatusCode
class PyEvtFilterFromFile (PyEvtFilter):
""" Algorithm which loads list of runnunber/eventnumbers from file for filtering and pass it to PyEvtFilter
"""
def __init__(self, name='filterFromFile', **kw):
super(PyEvtFilterFromFile, self).__init__(name,**kw)
self.input_file = kw.get('selectorInputFile', None)
def initialize(self):
_info = self.msg.info
_error = self.msg.error
_info('==> PyEvtFilterFromFile initialize')
if not self.input_file:
_error('Input_file is required.')
return StatusCode.Failure
try:
f = open(self.input_file, 'r')
except IOError:
_error = self.msg.error('File {} cannot be opened.'.format(self.input_file))
return StatusCode.Failure
else:
_info('==> File {} opened. Loading Runnumber/Eventnumber list'.format(self.input_file))
with f:
self.evt_list = []
for line in f:
if '#' in line:
continue
numbers = line.split()
if not numbers:
continue
if len(numbers) != 2:
self.msg.warning('Following line cannot be parsed: {}'.format(line))
self.evt_list.append((int(numbers[0]), int(numbers[1])))
super(PyEvtFilterFromFile,self).initialize()
return StatusCode.Success
from GaudiSequencer.PyCompsExt import PyEvtFilterFromFile
evtSelector = PyEvtFilterFromFile('eventSelector')
if 'selectorInputFile' in locals():
evtSelector.input_file = selectorInputFile
from AthenaCommon.AlgSequence import AthSequencer
filtseq = AthSequencer ("AthFilterSeq")
filtseq += evtSelector
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment