ATLAS Offline Software
Loading...
Searching...
No Matches
LCE_postprocessing.py
Go to the documentation of this file.
1#!/bin/env python
2
3# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4
5import sys,os,subprocess,tempfile
6from LArCafJobs.GetLBsToIgnore import getLBsToIgnore
7
8eoscmd="eos "
9
10if __name__=="__main__":
11 if len(sys.argv)<2 or not sys.argv[1].isdigit():
12 print("Usage: %s <runnumber> {outputfile}" % sys.argv[0])
13 sys.exit(-1)
14
15
16 runnumber=int(sys.argv[1])
17 if len(sys.argv)>2:
18 outputFile=sys.argv[2]
19 else:
20 outputFile="LCE_CellList_%i.txt" % runnumber
21
22 if not os.access(os.path.dirname(outputFile),os.W_OK):
23 print("ERROR, no write access to output text file",outputFile)
24 sys.exit(-1)
25
26
27 #1. Try find input file on eos
28 path=None
29
30 #Get project tag (from SFO DB):
31 from GetProjectTag import GetProjectTag
32 projectTag=GetProjectTag(runnumber)
33 if projectTag is None:
34 print("Failed to get ProjectTag for run ",runnumber," from SFO DB")
35 sys.exit(-2)
36 else:
37 print("Found project tag ",projectTag," for run ",runnumber)
38
39 eospath="/eos/atlas/atlascerngroupdisk/det-larg/Tier0/perm/%s/calibration_LArCellsEmpty/%8.8i/" % (projectTag,runnumber)
40 cmd = eoscmd+" ls "+eospath
41 print(cmd)
42 sRes = subprocess.getstatusoutput(cmd)
43 print(sRes[1])
44 output = sRes[1].split('\n')
45
46 found=False
47 if (sRes[0] == 0):
48 print("output: ", output)
49 for d1 in output:
50 if d1.find("NTUP_SAMPLESMON")!=-1:
51 eospath+="/"+d1
52 found=True
53 break
54 pass
55 if not found:
56 print("Directory for LCE output of run %i not found on eos" % runnumber)
57 sys.exit(-1)
58
59 cmd = eoscmd+" ls "+eospath
60 print("Checking path ",eospath)
61 sRes = subprocess.getstatusoutput(cmd)
62 print(sRes[1])
63 output = sRes[1].split('\n')
64 if (sRes[0] == 0):
65 for d2 in output:
66 print(d2)
67 if d2 is not None and d2.find("NTUP_SAMPLESMON")!=-1:
68 filename=d2
69 path="root://eosatlas/"+eospath+"/"+filename
70 break
71 pass
72 pass
73 pass
74 pass
75
76 if path is not None:
77 print("Found project Tag",projectTag)
78 print("Input file ",path)
79 else:
80 print("LCE output of run %i not found on eos" % runnumber)
81 sys.exit(-1)
82
83
84 workdir=tempfile.mkdtemp()
85 LCEFile=workdir+"/"+filename
86 cmd=eoscmd+" cp "+path+" "+LCEFile
87 sRes = subprocess.getstatusoutput(cmd)
88 if (sRes[0] != 0 or not os.access(LCEFile,os.R_OK)):
89 print("ERROR, failed to copy LCE ntuple to local directory")
90 sys.exit(-1)
91 pass
92
93
94 #2. Get LBs to ignore:
95 requireStableBeam=projectTag.endswith("TeV")
96 bulk=False
97 badLBs=getLBsToIgnore(runnumber,True,bulk,requireStableBeam)
98 (badLBsF,badLBsFN)=tempfile.mkstemp(text=True)
99 #print(badLBsF,badLBsFN)
100 os.write(badLBsF,str.encode(', '.join([ str(i) for i in sorted(badLBs) ])))
101 os.write(badLBsF,str.encode("\n"))
102 os.close(badLBsF)
103 print(badLBsFN)
104
105
106 #3. running the list creation
107
108 print("Running LCE_CellList",LCEFile,outputFile,badLBsFN)
109
110 sc=subprocess.call(["LCE_CellList",LCEFile,outputFile,badLBsFN])
111
112 os.remove(badLBsFN)
113 os.remove(LCEFile)
void print(char *figname, TCanvas *c1)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177