~sophie-middleton08/maus/devel

« back to all changes in this revision

Viewing changes to bin/examples/load_json_file.py

  • Committer: Chris Rogers
  • Date: 2012-11-06 12:04:39 UTC
  • mfrom: (659.1.45 release-candidate)
  • Revision ID: chris.rogers@stfc.ac.uk-20121106120439-e6znfg5kfg850l38
Tags: MAUS-v0.4.0
MAUS-v0.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
    tof1_digits_1_hist = ROOT.TH1D("tof1 digits_1", # pylint: disable = E1101
64
64
                                   "tof1 digits for plane 1;Slab number",
65
65
                                    7, -0.5, 6.5)
66
 
    for line in json_file.readlines():
67
 
        spill = json.loads(line)
 
66
    # get all events - nb: this is python preferred way of extracting a list
 
67
    # from another list
 
68
    events = [json.loads(line) for line in json_file.readlines()]
 
69
    # make a list of events with type 'Spill' (i.e. output from DAQ)
 
70
    spills = [event for event in events if event['maus_event_type'] == 'Spill']
 
71
    for spill in spills:
68
72
        # Print some basic information about the spill
69
73
        print "Found spill number", spill["spill_number"],
70
74
        print "in run number", spill["run_number"],
72
76
        # bureaucracy
73
77
        print "DAQ event type", spill["daq_event_type"]
74
78
        if spill["daq_event_type"] == "physics_event":
75
 
            # note PyROOT gives a segmentation fault if we try to call the STL
76
 
            # vector directly
77
79
            for event in spill["recon_events"]:
78
80
                tof_event = event["tof_event"]
79
81
                digits = tof_event["tof_digits"]