ATLAS Offline Software
Functions
trigbs_mergeBSfiles Namespace Reference

Functions

def get_parser ()
 
def get_filenames (dirs)
 
def main ()
 

Function Documentation

◆ get_filenames()

def trigbs_mergeBSfiles.get_filenames (   dirs)

Definition at line 46 of file trigbs_mergeBSfiles.py.

46 def get_filenames(dirs):
47  filenames = []
48  for dirname in sorted(dirs):
49  files = os.listdir(dirname)
50  logging.debug('Found %d files in %s', len(files), dirname)
51  for f in sorted(files):
52  filenames.append(dirname + '/' + f)
53  return filenames
54 
55 

◆ get_parser()

def trigbs_mergeBSfiles.get_parser ( )

Definition at line 18 of file trigbs_mergeBSfiles.py.

18 def get_parser():
19  parser = argparse.ArgumentParser(usage='%(prog)s [options] outBaseName dir1 [dir2 ...]',
20  description=__doc__,
21  formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=36, width=100))
22  parser.add_argument('outBaseName',
23  help='Output file name base')
24  parser.add_argument('dirs',
25  metavar='dir',
26  nargs='+',
27  help='Input directory (can be multiple)')
28  parser.add_argument('--copyFrom', '-c',
29  metavar='FILE', action='store',
30  help='Copy metadata from other ByteStream file')
31  parser.add_argument('--nepfOutput', '-n',
32  metavar='NUM', action='store', type=int, default=500,
33  help='Number of events per output file (default=%(default)s)')
34  parser.add_argument('--nepfInput', '-N',
35  metavar='NUM', action='store', type=int, default=0,
36  help='Number of events per input file, 0 means all (default=%(default)s)')
37  parser.add_argument('--renumber', '-r',
38  action='store_true',
39  help='Renumber event IDs from 1')
40  parser.add_argument('--verbose', '-v',
41  action='store_true',
42  help='Increase output verbosity')
43  return parser
44 
45 

◆ main()

def trigbs_mergeBSfiles.main ( )

Definition at line 56 of file trigbs_mergeBSfiles.py.

56 def main():
57  args = get_parser().parse_args()
58  logging.basicConfig(stream=sys.stdout,
59  format='%(levelname)-8s %(message)s',
60  level=logging.DEBUG if args.verbose else logging.INFO)
61 
62  filenames = get_filenames(args.dirs)
63  logging.info('Merging %d files', len(filenames))
64  logging.info('filenames: %s', filenames)
65 
66  ievt = 1
67  dr = EventStorage.pickDataReader(filenames[0])
68  output = eformat.ostream(core_name=args.outBaseName,
69  run_number=dr.runNumber(),
70  trigger_type=dr.triggerType(),
71  detector_mask=dr.detectorMask(),
72  beam_type=dr.beamType(),
73  beam_energy=dr.beamEnergy())
74  output.max_events_per_file(args.nepfOutput)
75 
76  for ifile, input_file in enumerate(filenames):
77  logging.info("Opening file %d: %s", ifile+1, input_file)
78  inputFile = eformat.istream([input_file])
79 
80  for ievt_in_file, event in enumerate(inputFile):
81  if args.nepfInput > 0 and ievt_in_file >= args.nepfInput:
82  break
83  logging.debug("Reading event with Lvl1 Id = %ld", event.lvl1_id())
84  new_event = eformat.write.FullEventFragment(event)
85  if args.renumber:
86  logging.debug("Rewriting the event with Lvl1 Id = %ld", ievt)
87  new_event.lvl1_id(ievt)
88  new_event.global_id(ievt)
89  for rob in new_event.children():
90  rob.rod_lvl1_id(ievt)
91  rob.checksum_type(0) # remove checksum
92  rob.rod_lvl1_trigger_type(event.lvl1_trigger_type())
93  else:
94  logging.debug("Rewriting the event with unchanged Lvl1 Id")
95 
96  output.write(new_event)
97  ievt += 1
98 
99  logging.info('Wrote %d events to %d files', ievt-1, 1+((ievt-2)//args.nepfOutput))
100 
101 
trigbs_mergeBSfiles.get_filenames
def get_filenames(dirs)
Definition: trigbs_mergeBSfiles.py:46
trigbs_mergeBSfiles.main
def main()
Definition: trigbs_mergeBSfiles.py:56
trigbs_mergeBSfiles.get_parser
def get_parser()
Definition: trigbs_mergeBSfiles.py:18
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
confTool.parse_args
def parse_args()
Definition: confTool.py:35