Project

General

Profile

MAUSOnlineReconstructionOverview » History » Version 10

Jackson, Mike, 15 March 2012 16:20

1 1 Jackson, Mike
h1. Online Reconstruction Overview
2
3 7 Jackson, Mike
{{>toc}}
4
5 6 Jackson, Mike
"Manchego" is the online reconstruction components of MAUS. Manchego stands for "Manchego is Analysis No-nonsense Control room Helping Existentially Guided Onlineness".
6 5 Jackson, Mike
7 10 Jackson, Mike
"Architecture diagrams":http://micewww.pp.rl.ac.uk/attachments/855/20120315-OnlineReconstructionArchitecture.ppt
8 1 Jackson, Mike
9 6 Jackson, Mike
h2. Introduction
10
11
The MAUS framework consists of four types of component. Each component creates or manipulates spills. A spill is a JSON document representing information about particles.
12
13
* Inputters - these input or generate spills e.g. read DAQ data live and convert into spills, read archived DAQ data and convert into spills, or generate simulated spill data.
14
* Transforms - these analyse the data within the spill in various ways, derive new data and add this to the spill. 
15
* Mergers - these summarise data within a series of successive spills and output new spills with the summarised data.
16
* Outputters - these output spills, for example saving them as JSON files or, where applicable, extracting image data from them and saving this as image files.
17
18 1 Jackson, Mike
h2. Parallel transformation of spills
19 5 Jackson, Mike
20 6 Jackson, Mike
As each spill is independant, spills can be transformed in parallel.
21 5 Jackson, Mike
22
Celery, an distributed asynchronous task queue for Python is used to support parallel transformation of spills. Celery uses RabbitMQ as a message broker to handle communications between clients and Celery worker nodes.
23
24 8 Jackson, Mike
A Celery worker executes one or more sub-processes each of which execute tasks. When a worker starts up it registers with RabbitMQ - the RabbitMQ task broker can be local or remote. By default Celery spawns N sub-processes where N is the number of CPUs on the host, but N can be explicitly set by a user. Each sub-process can execute tasks. Multiple Celery workers can be deployed, each of which with one or more sub-processes. Celery therefore supports highly-parallelisable applications.
25 5 Jackson, Mike
26 8 Jackson, Mike
For MAUS, each Celery worker needs a complete MAUS deployment running on the same node as the worker.
27 5 Jackson, Mike
28
MAUS configures Celery as follows:
29
30
* The framework uses reflection to get the names of the transforms the user wants to use e.g. @MapPyGroup(MapPyBeamMaker, MapCppSimulation, MapCppTrackerDigitization)@. This is termed a "transform specification".
31
* A Celery broadcast is invoked, passing the transform specification, the MAUS configuration and a configuration ID (e.g. the client's process ID).
32
* Celery broadcasts are received by all Celery workers registered with the RabbitMQ message broker.
33
* On receipt of the broadcast, each Celery worker:
34
** Checks that the client's MAUS version is the same as the workers. If not then an error is returned to the client.
35
** Forces the transform specification down to each sub-process.
36
** Waits for the sub-processes to confirm receipt.
37
** If all sub-processes update correctly then a success message is returned to the client.
38
** If any sub-process fails to update then a failure message, with details, is returned to the client.
39 9 Jackson, Mike
* Each Celery sub-process:
40
** Invokes @death@ on the existing transforms, to allow for clean-up to be done.
41
** Updates their configuration to be the one received.
42
** Creates new transforms as specified in the transform configuration.
43
** Invokes @birth@ on these with the new configuration.
44
** Confirms with the Celery worker that the update has been done.
45
* Celery workers and sub-processes catch any exceptions they can to avoid the sub-processes or, more seriously, the Celery worker itself from crashing in an unexpected way.
46 5 Jackson, Mike
47
MAUS uses Celery as follows:
48
49
* A Celery client-side proxy is used to submit the spill to Celery. It gets an object which it can use to poll the status of the "job".
50
* The client-side proxy forwards the spill to RabbitMQ.
51 8 Jackson, Mike
* RabbitMQ forwards this to an available Celery worker. If none are available then the job is queued.
52
* The Celery worker picks an available sub-process.
53 5 Jackson, Mike
* The sub-process executes the current transform on the spill.
54
* The result spill is returned to the Celery worker and there back to RabbitMQ.
55
* The MAUS framework regularly polls the status of the transform job until it's status is successful, in which case the result spill is available, or failed, in which case the error is recorded but execution continues.
56
57
h2. Document-oriented database
58
59 1 Jackson, Mike
After spills have been transformed, a document-oriented database, MongoDB, is used to store the transformed spills. The database represents the interface between the input-transform and merge-output phases of a spill processing workflow.
60
61
Use of a database allows many merge-output clients to use the same data.
62
63
The MAUS framework is given the name of a collection of spills and reads these in order of the dates and times they were added to the database. It passes each spill to a merger and then takes the output of the merger and passes it to an outputter.
64 5 Jackson, Mike
65 1 Jackson, Mike
h2. Histogram mergers
66
67 6 Jackson, Mike
Histogram mergers take in spills and, from the data within the spills, update histograms. They regularly output one or more histograms (either on a spill-by-spill basis or every N spills, where N is configurable). The histogram is output in the form of a JSON document which includes:
68 5 Jackson, Mike
69 6 Jackson, Mike
* A list of keywords.
70
* A description of the histogram.
71
* A tag which can be used to name a file when the histogram is saved.
72
* An image type e.g. EPS, PNG, JPG,.... The image type is a configuration option.
73
* The image data itself in base64-encoded format./
74 5 Jackson, Mike
75 6 Jackson, Mike
Histogram mergers do not display or save the histograms, merely output the image and its meta-data.
76 5 Jackson, Mike
77 6 Jackson, Mike
Example histogram mergers, and generic super-classes to build these, currently exist for histograms drawn using PyROOT (@ReducePyTOFPlot and @ReducePyROOTHistogram@) and matplotlib (@ReducePyHistogramTDCADCCounts@ and @ReducePyMatplotlibHistogram@).
78 5 Jackson, Mike
79 6 Jackson, Mike
h2. Saving images
80 5 Jackson, Mike
81 6 Jackson, Mike
An outputter (@OutputPyImage@) allows the JSON documents output by histogram mergers to be saved. The user can configure the directory where the images are saved and a file name prefix for the files. The tag in the JSON document is also used for the file name.
82 5 Jackson, Mike
83 6 Jackson, Mike
The outputter extracts the base-64 encoded image data, unencodes it and saves it in a file. It also saves the JSON document (minus the image data) in an associated meta-data file.
84 5 Jackson, Mike
85 6 Jackson, Mike
h2. Web front-end
86 5 Jackson, Mike
87 6 Jackson, Mike
A web front-end allows histogram images to be vierwed in real-time. The MAUS web front-end is implemented in Django, a Python web framework. Django ships with its own lightweight web server or can be run under Apache web server.
88 5 Jackson, Mike
89 6 Jackson, Mike
The web front-end serves up histogram images from a directory and supports keyword-based searches for images of particular types. 
90 5 Jackson, Mike
91 6 Jackson, Mike
Each web page dynamically refreshes so updated images deposited into the image directory can be automatically presented to users.
92 5 Jackson, Mike
93 6 Jackson, Mike
The interface between the online reconstruction framework and the web front-end is just a set of image files and their accomanying JSON meta-data documents (though the web front-end can render images without any accopanying JSON meta-data).
94 1 Jackson, Mike
95 6 Jackson, Mike
h2. Design in detail
96 1 Jackson, Mike
97 6 Jackson, Mike
h3. Run numbers
98
99 1 Jackson, Mike
Run numbers are assumed to be as follows:
100
101
* -N : Monte Carlo simulation of run N
102
* 0 : pure Monte Carlo simulation
103
* +N : run N
104
105 6 Jackson, Mike
h3. Transforming spills from an input stream (Input-Transform)
106 1 Jackson, Mike
107
This is the algorithm used to transform spills from an input stream:
108
<pre>
109
CLEAR document store
110
run_number = None
111
WHILE an input spill is available
112
  GET next spill
113
  IF spill does not have a run number
114
    # Assume pure MC
115
    spill_run_number = 0
116
  IF (spill_run_number != run_number)
117
    # We've changed run.
118
    IF spill is NOT a start_of_run spill
119
      WARN user of missing start_of_run spill
120
    WAIT for current Celery tasks to complete
121
      WRITE result spills to document store
122
    run_number = spill_run_number
123
    CONFIGURE Celery by DEATHing current transforms and BIRTHing new transforms
124
  TRANSFORM spill using Celery
125
  WRITE result spill to document store
126
 DEATH Celery worker transforms
127
</pre>
128
If there is no initial @start_of_run@ spill (or no @spill_num@ in the spills) in the input stream (as can occur when using @simple_histogram_example.py@ or @simulate_mice.py@) then spill_run_number will be 0, run_number will be None and a Celery configuration will be done before the first spill needs to be transformed. 
129
130
Spills are inserted into the document store in the order of their return from Celery workers. This may not be in synch with the order in which they were originally read from the input stream.
131
132 6 Jackson, Mike
h3. Merging spills and passing results to an output stream (Merge-Output)
133 1 Jackson, Mike
134 2 Jackson, Mike
This is the algorithm used to merge spills and pass the results to an output stream:
135 1 Jackson, Mike
<pre>
136
run_number = None
137
end_of_run = None
138
is_birthed = FALSE
139
last_time = 01/01/1970
140 2 Jackson, Mike
WHILE TRUE
141 1 Jackson, Mike
  READ spills added since last time from document store
142
  IF spill IS "end_of_run"
143 2 Jackson, Mike
    end_of_run = spill
144
  IF spill_run_number != run_number
145
    IF is_birthed
146 1 Jackson, Mike
      IF end_of_run == None
147
          end_of_run = {"daq_event_type":"end_of_run", "run_num":run_number}
148
      Send end_of_run to merger
149
      DEATH merger and outputter
150 2 Jackson, Mike
    BIRTH merger and outputter
151 1 Jackson, Mike
    run_number = spill_run_number
152
    end_of_run = None
153
    is_birthed = TRUE
154
  MERGE and OUTPUT spill
155
Send END_OF_RUN block to merger
156
DEATH merger and outputter
157
</pre>
158
159
The Input-Transform policy of waiting for the processing of spills from a run to complete before starting processing spills from a new run means that all spills from run N-1 are guaranteed to have a time stamp < spills from run N.
160
161
is_birthed is used to ensure that there is no BIRTH-DEATH-BIRTH redundancy on receipt of the first spill.
162
163 6 Jackson, Mike
h3. Document store
164 1 Jackson, Mike
165
Spills are stored in documents in a collection in the document store. 
166
167
Documents are of form @{"_id":ID, "date":DATE, "doc":SPILL}@ where:
168
169
* ID: index of this document in the chain of those successfuly transformed. It has no significance beyond being unique in an execution of Input-Transform loop below. It is not equal to the spill_num (Python @string@)
170
* DATE: date and time to the milli-second noting when the document was added (Python @timestamp@)
171
* DOC: spill document. (Python @string@ holding a valid JSON document)
172
173 6 Jackson, Mike
h4. Collection names
174 1 Jackson, Mike
175
For Input-Transform,
176
177
* If configuration parameter @doc_collection_name@ is @None@, @""@, or @auto@ then @HOSTNAME_PID@, where @HOSTNAME@ is the machine name and @PID@ the process ID, is used.
178
* Otherwise the value of @doc_collection_name@ is used.
179
* @doc_collection_name@ has default value @spills@.
180
181
For Merge-Output,
182
183
* If configuration parameter @doc_collection_name@ is @None@, @""@, or undefined then an error is raised.
184
* Otherwise the value of @doc_collection_name@ is used.
185
186 6 Jackson, Mike
h3. Miscellaneous
187 1 Jackson, Mike
188
* Currently Celery timeouts are not used, transforming a spill takes as long as it takes.
189
* Celery task retries on failure option is not used. If the transformation of a spill fails first time it can't be expected to succeed on a retry.
190
* If memory leaks arise, e.g. from C++ code, look at Celery rate limitss, which allow the time or number of tasks before sub-process is killed and respawned, to be defined. Soft rate limits would allow @death@ to be run on the transforms first.