~9marusia6/maus/beamlinesimulation

« back to all changes in this revision

Viewing changes to bin/examples/simple_scalers_example.py

  • Committer: Chris Rogers
  • Date: 2012-04-16 13:33:25 UTC
  • mfrom: (659.1.17 release-candidate)
  • Revision ID: chris.rogers@stfc.ac.uk-20120416133325-11tyj7pb7xs7m37m
ReleaseĀ 0.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
#################################################################
 
4
###!!! YOU ARE NOT ALLOWED TO MODIFY THIS FILE DIRECTLY    !!!###
 
5
###!!! PLEASE MAKE A COPY OF THIS FILE WITH THE CP COMMAND !!!###
 
6
#################################################################
 
7
 
 
8
"""
 
9
Simple example showing use of ReducePyScalersTable and OutputPyJSON.
 
10
"""
 
11
 
 
12
import json
 
13
import io
 
14
import MAUS
 
15
import time
 
16
 
 
17
def run():
 
18
    """
 
19
    Create a JSON document and create a histogram.
 
20
    """
 
21
    # Create sample JSON documents with spills containing data 
 
22
    # expected by ReducePyScalersTable.
 
23
    input_docs = []
 
24
    for i in range(0, 4):
 
25
        json_doc = {}
 
26
        json_doc["daq_data"] = {}
 
27
        json_doc["daq_data"]["V830"] = {}
 
28
        scalers = json_doc["daq_data"]["V830"]
 
29
        scalers["phys_event_number"] = "Sample event %d" % i
 
30
        scalers["time_stamp"] = time.time()
 
31
        hits = {}
 
32
        hits["ch0"] = i
 
33
        hits["ch1"] = i
 
34
        hits["ch2"] = i
 
35
        hits["ch3"] = i
 
36
        hits["ch4"] = i
 
37
        hits["ch12"] = i
 
38
        scalers["channels"] = hits
 
39
        input_docs.append(json.dumps(json_doc))
 
40
        input_docs.append("\n")
 
41
    input_file = io.StringIO(unicode("".join(input_docs)))
 
42
 
 
43
    # Set up data cards.
 
44
    data_cards_list = []
 
45
    data_cards_list.append("output_file_name='%s'\n" % "scalers")
 
46
    data_cards_list.append("output_file_auto_number=%s\n" % True)
 
47
    data_cards = io.StringIO(unicode("".join(data_cards_list)))
 
48
 
 
49
    # Create workers.
 
50
    input_worker = MAUS.InputPyJSON(input_file)
 
51
 
 
52
    mappers = MAUS.MapPyGroup()
 
53
    mappers.append(MAUS.MapPyDoNothing())  
 
54
 
 
55
    reducer = MAUS.ReducePyScalersTable()
 
56
 
 
57
    output_worker = MAUS.OutputPyFile()
 
58
 
 
59
    # Execute the workers.
 
60
    MAUS.Go(input_worker, mappers, reducer, output_worker, data_cards)
 
61
 
 
62
if __name__ == "__main__":
 
63
    run()