ATLAS Offline Software
Loading...
Searching...
No Matches
trigbs_pickEvents.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4
5import eformat
6import sys
7import libpyevent_storage as EventStorage
8import getopt
9
10def usage():
11 print(" usage: %s [options] <filein> <fileout> <events1> [event2] ..." % sys.argv[0])
12 print(" Writes out selected events from a bytestream file")
13 print(" Events are specified as individual event number (counting from 0)")
14 print(" or as ranges of event numbers (e.g. 3-10).")
15 print(" Multiple ranges can be specified")
16 print()
17 print(" options: ")
18 print(" -1 - select on l1 id instead of event number")
19 print(" -g - select on global id instead of event number")
20 print(" -v - verbose")
21 print(" -h - help")
22 sys.exit(1)
23
24try:
25 opts, args = getopt.getopt(sys.argv[1:], "1ghv")
26 if len(args)<3:
27 raise getopt.GetoptError("not enough arguments provided")
28except getopt.GetoptError as err:
29 print(err)
30 usage()
31 sys.exit(2)
32
33useL1ID=False
34useGlobalID=False
35verbose=False
36for opt,arg in opts:
37 if opt == '-1':
38 useL1ID=True
39 if opt == '-g':
40 useGlobalID=True
41 if opt == '-v':
42 verbose=True
43
44input_file = args[0]
45output_file = args[1]
46eventNums=args[2:]
47
48if verbose:
49 print("Opening file: %s" % ( input_file))
50
51input = eformat.istream([input_file])
52dr=EventStorage.pickDataReader(input_file)
53output = eformat.ostream(core_name=output_file,
54 run_number=dr.runNumber(),
55 trigger_type=dr.triggerType(),
56 detector_mask=dr.detectorMask(),
57 beam_type=dr.beamType(),
58 beam_energy=dr.beamEnergy())
59
60ranges=[]
61for range in eventNums:
62 vals=range.split('-')
63 if len(vals)==1:
64 vals.append(vals[0])
65 if vals[0]=='':
66 vals[0]=0
67 if vals[1]=='':
68 vals[1]=1<<32
69 ranges.append( (int(vals[0]),int(vals[1])) )
70
71cnt=0
72numSaved=0
73for event in input:
74 if verbose:
75 print("Reading event %d with Lvl1 Id = %ld and global Id = %ld"% (cnt,event.lvl1_id(),event.global_id()))
76 num=cnt
77 if useL1ID:
78 num=event.lvl1_id()
79 if useGlobalID:
80 num=event.global_id()
81 for range in ranges:
82 if num>=range[0] and num<=range[1]:
83 print(" - Saving event %d with Lvl1 Id = %ld and global Id = %ld"% (cnt,event.lvl1_id(),event.global_id()))
84 output.write(event)
85 numSaved+=1
86 break
87 cnt+=1
88
89print(numSaved,'Events saved to',output.last_filename())
void print(char *figname, TCanvas *c1)