ATLAS Offline Software
LB_AnalMapSplitter.py
Go to the documentation of this file.
1 #!/bin/env python
2 #
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 from __future__ import print_function
6 
7 import sys
8 
9 # get the list of special run,lbn with more than 1 file
10 special_run_lbn = {}
11 with open("runs_lbn_files.txt") as f:
12  for line in f:
13  # print line
14  if not line.startswith("root"):
15  print("WARNING: line doesn't start with 'root'")
16  print(line)
17  continue
18  fileName = line.rstrip()
19  print(fileName)
20  finfo = fileName.split(".")
21  run = finfo[3]
22  lbi = 4 # index of the lbn info
23  while "_lb" not in finfo[lbi] and lbi < 20:
24  lbi += 1
25  if lbi >= 20:
26  print(finfo[lbi] + " doesnt contain _lb")
27  exit(1)
28  lbn = finfo[lbi].replace("_lb", "")
29  print(run+"_"+lbn)
30  if run+"_"+lbn in special_run_lbn:
31  if fileName in special_run_lbn[run+"_"+lbn]:
32  print("%s already in map for %s %s" % (fileName, run, lbn))
33  else:
34  special_run_lbn[run+"_"+lbn].append(fileName)
35  else:
36  special_run_lbn[run+"_"+lbn] = [fileName]
37  for key in special_run_lbn.keys():
38  pass
39  print("done with special_run_lbn")
40 
41 # do the work
42 maxstream = int(sys.argv[1])
43 print("maxstream=%d" % maxstream)
44 for s in range(0, maxstream+1): # 50
45  with open("lbn_anal_map_stream"+str(s)+".txt") as f:
46  tot = 0
47  nfile = 1
48  of = open("output_stream"+str(s) +
49  "/lbn_anal_map_"+str(nfile)+".txt", "w")
50  of2 = open("output_stream"+str(s)+"/filelist_"+str(nfile)+".txt", "w")
51  for line in f:
52  linfo = line.split(" ")
53  tot += int(linfo[16])
54  run = linfo[3].replace(",", "").zfill(8)
55  lbn = linfo[5].replace(",", "").zfill(4)
56  if tot > 100:
57  # replace last bit of line and also write it to the new file
58  extra = tot-100
59  forthisone = int(linfo[16])-extra
60  rline = line.replace(
61  linfo[16]+" wanted", str(forthisone)+" wanted")
62  of.write(rline)
63  if run+"_"+lbn in special_run_lbn:
64  for f in special_run_lbn[run+"_"+lbn]:
65  if of2.tell() > 0:
66  of2.write(",")
67  of2.write(f)
68  else:
69  print("%s %s not in files map!" % (run, lbn))
70 
71  of.close()
72  of2.close()
73  nfile += 1
74  of = open("output_stream"+str(s) +
75  "/lbn_anal_map_"+str(nfile)+".txt", "w")
76  of2 = open("output_stream"+str(s) +
77  "/filelist_"+str(nfile)+".txt", "w")
78  tot = extra # the number left over from the last set
79 
80  rline = line.replace(linfo[16]+" wanted", str(extra)+" wanted")
81  of.write(rline)
82  if run+"_"+lbn in special_run_lbn:
83  for f in special_run_lbn[run+"_"+lbn]:
84  if of2.tell() > 0:
85  of2.write(",")
86  of2.write(f)
87  else:
88  print("%s %s not in files map!" % (run, lbn))
89 
90  elif tot == 100:
91  of.write(line)
92  if run+"_"+lbn in special_run_lbn:
93  for f in special_run_lbn[run+"_"+lbn]:
94  if of2.tell() > 0:
95  of2.write(",")
96  of2.write(f)
97  else:
98  print("%s %s not in files map!" % (run, lbn))
99 
100  of.close()
101  of2.close()
102  nfile += 1
103  of = open("output_stream"+str(s) +
104  "/lbn_anal_map_"+str(nfile)+".txt", "w")
105  of2 = open("output_stream"+str(s) +
106  "/filelist_"+str(nfile)+".txt", "w")
107  tot = 0
108  else:
109  of.write(line)
110  if run+"_"+lbn in special_run_lbn:
111  for f in special_run_lbn[run+"_"+lbn]:
112  if of2.tell() > 0:
113  of2.write(",")
114  of2.write(f)
115  else:
116  print("%s %s not in files map!" % (run, lbn))
117 
118  print("done %d" % s)
119  of.close()
120  of2.close()
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
calibdata.exit
exit
Definition: calibdata.py:236
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70