~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to bin/examples/simple_scalers_example.py

  • Committer: Christopher Hunt
  • Date: 2015-06-18 14:48:59 UTC
  • mfrom: (697.69.1 merge)
  • mto: (697.69.2 merge_hunt)
  • mto: This revision was merged to the branch mainline in revision 708.
  • Revision ID: christopher.hunt08@imperial.ac.uk-20150618144859-rki5ma1lv8722w41
Merged in latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
import json
8
8
import io
 
9
import os
9
10
import MAUS
10
 
import time
 
11
from Configuration import Configuration
 
12
from _InputCppDAQOfflineData import InputCppDAQOfflineData
11
13
 
12
14
def run():
13
15
    """
14
16
    Create a JSON document and create a histogram.
15
17
    """
16
 
    # Create sample JSON documents with spills containing data 
17
 
    # expected by ReducePyScalersTable.
18
 
    input_docs = []
19
 
    for i in range(0, 4):
20
 
        json_doc = {}
21
 
        json_doc["daq_data"] = {}
22
 
        json_doc["daq_data"]["V830"] = {}
23
 
        scalers = json_doc["daq_data"]["V830"]
24
 
        scalers["phys_event_number"] = "Sample event %d" % i
25
 
        scalers["time_stamp"] = time.time()
26
 
        hits = {}
27
 
        hits["ch0"] = i
28
 
        hits["ch1"] = i
29
 
        hits["ch2"] = i
30
 
        hits["ch3"] = i
31
 
        hits["ch4"] = i
32
 
        hits["ch12"] = i
33
 
        scalers["channels"] = hits
34
 
        input_docs.append(json.dumps(json_doc))
35
 
        input_docs.append("\n")
36
 
    input_file = io.StringIO(unicode("".join(input_docs)))
 
18
    if not os.environ.get("MAUS_ROOT_DIR"):
 
19
        raise Exception('InitializeFail', 'MAUS_ROOT_DIR unset!')
 
20
    config = Configuration().getConfigJSON()
 
21
    config_json = json.loads(config)
 
22
    datapath = '%s/src/input/InputCppDAQData' % \
 
23
                            os.environ.get("MAUS_ROOT_DIR")
 
24
 
 
25
    # Set up a run configuration
 
26
    datafile = '05466'
 
27
    if os.environ['MAUS_UNPACKER_VERSION'] == "StepIV":
 
28
        datafile = '06008'
 
29
    config_json["daq_data_path"] = datapath
 
30
    config_json["daq_data_file"] = datafile
37
31
 
38
32
    # Set up data cards.
39
33
    data_cards_list = []
40
34
    data_cards_list.append("output_file_name='%s'\n" % "scalers")
41
35
    data_cards_list.append("output_file_auto_number=%s\n" % True)
 
36
    data_cards_list.append("daq_data_path='%s'\n" % datapath)
 
37
    data_cards_list.append("daq_data_file='%s'\n" % datafile)
42
38
    data_cards = io.StringIO(unicode("".join(data_cards_list)))
 
39
    print data_cards
43
40
 
44
41
    # Create workers.
45
 
    input_worker = MAUS.InputPyJSON(input_file)
 
42
    # inputter = InputCppDAQOfflineData(datapath, datafile)
 
43
    # inputter.birth(json.dumps(config_json))
 
44
    inputter = InputCppDAQOfflineData()
46
45
 
47
46
    mappers = MAUS.MapPyGroup()
48
47
    mappers.append(MAUS.MapPyDoNothing())  
49
48
 
50
49
    reducer = MAUS.ReducePyScalersTable()
51
50
 
52
 
    output_worker = MAUS.OutputPyFile()
 
51
    outputter = MAUS.OutputPyFile()
53
52
 
54
53
    # Execute the workers.
55
 
    MAUS.Go(input_worker, mappers, reducer, output_worker, data_cards)
 
54
    MAUS.Go(inputter, mappers, reducer, outputter, data_cards)
56
55
 
57
56
if __name__ == "__main__":
58
57
    run()