1
# This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
# MAUS 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.
8
# MAUS 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.
13
# You should have received a copy of the GNU General Public License
14
# along with MAUS. If not, see <http://www.gnu.org/licenses/>.
17
Generate spills from a socket
20
from docstore.root_document_store import RootDocumentStore
24
Generates a user defined number of empty spills, defined by the
25
spill_generator_number_of_spills. Empty spill is just an empty dict.
30
Initialise InputPySpillGenerator to 0
35
def birth(self, json_config):
37
birth() reads the number of spills from the configuration
45
n_docstore_retries = 0
48
self.tree_names = self.doc_store.default_tree_names()
50
self.doc_store = RootDocumentStore(timeout,
55
self.doc_store.connect({"host":host, "port":port})
56
if not self.doc_store.has_collection(self.collection):
57
raise RuntimeError("Could not find collection "+\
60
def save(self, event):
65
if type(event) == type(""):
66
event_out = json.loads(event)
67
elif type(event) == type([]) or type(event) == type({}):
69
elif type(event) == type(ROOT.TObject):
70
event_out = ROOT.TTree("OutputPySocket", "TTree") # pylint: disable = E1101
71
for name, a_type in self.tree_names.iteritems():
72
if type(event) == a_type:
73
event_out.Branch(name, event, event.GetSizeOf(), 1)
76
raise TypeError("Could not unpack the type of event "+str(event))
77
self.doc_store.put(self.collection, self.last_doc, event)
82
death() relinquishes the document store
84
self.doc_store.disconnect()