xboa
_hit_factory_base.py
Go to the documentation of this file.
1 # This file is a part of xboa
2 #
3 # xboa is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # xboa is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with xboa in the doc folder. If not, see
15 # <http://www.gnu.org/licenses/>.
16 
17 import xboa.hit
18 
19 class HitFactoryBase(object):
20  """
21  Base factory class for making hits
22  """
23  def __init__(self):
24  """
25  Initialise the base class
26  """
27  pass
28 
29  def make_hit(self):
30  """
31  Generate a new hit
32  """
33  raise NotImplementedError("make_hit not implemented")
34 
35  def hit_generator(self):
36  try:
37  print "gen in"
38  yield self.make_hit()
39  print "gen out"
40  except (EOFError, xboa.hit.BadEventError):
41  self.new_spill()
42  try:
43  yield self.make_hit()
44  except (EOFError, xboa.hit.BadEventError):
45  raise StopIteration("Finished")
46  except StopIteration:
47  raise
48 
49  def new_spill(self):
50  """
51  Load the next spill from the file handle
52 
53  For files that have data bundled into spills (i.e. MAUS format), this
54  enables user to load the next spill. Otherwise it is a no-op.
55  """
56  pass
57 
58  @classmethod
59  def bad_pid(cls, pid):
60  if pid not in cls.bad_pids:
61  print "Failed to parse pid", pid
62  cls.bad_pids.append(pid)
63 
64  bad_pids = []
65 
Base factory class for making hits.
Implemented within this module:
Definition: __init__.py:1
def new_spill
Load the next spill from the file handle.