ATLAS Offline Software
runSelector.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 import os
6 import sys
7 import time
8 
9 def main( runNum = None, procType = None, forceSkipQueue = 0, Stream = None ):
10 #def main( runNum = None, procType = None, forceSkipQueue = 0 ):
11  #===== Run number =====
12  if runNum is None:
13  print('ERROR no run number given')
14  return False
15  Run0 = runNum
16  #===== procType =====
17  if procType is None:
18  print('ERROR no process type given')
19  return False
20  if Stream is None:
21  print('ERROR no stream given')
22  return False
23  for iType in procType:
24  if iType not in ['doNoisyStrip','doNoiseOccupancy','doDeadChip','doDeadStrip','doHV','doBSErrorDB','doRawOccupancy','doEfficiency','doLorentzAngle']:
25  print('ERROR process type does not match any possible candidates')
26  return False
27  else :
28  pType = iType
29 
30  #run RunQuery only if the stream _is not_ cosmics
31 
32  print('STREAM')
33  print(Stream)
34  #===== Check the stable beam flag in Run0 =====
35  #--- RunQuery
36  runQuery = 'AtlRunQuery.py '
37  runQuery += '--run \"' + str(Run0) + '\" '
38 
39  if 'cos' not in Stream and 'idcomm' not in Stream:
40  runQuery += '--lhc \"stablebeams TRUE\" '
41 
42  runQuery += '--partition \"ATLAS\" '
43  runQuery += '--detmaskin \"240A\" '
44 
45 
46  if 'eV' in Stream:
47  runQuery += '--projecttag \"data*_*eV\" '
48  elif 'hi' in Stream:
49  runQuery += '--projecttag \"data*_hi\" '
50  elif 'cos' in Stream:
51  runQuery += '--projecttag \"data*_cos\" '
52  else:
53  runQuery += '--projecttag \"data*_idcom\" '
54 
55  if pType == 'doNoisyStrip':
56  runQuery += '--streams \"*calibration_SCTNoise 10000+\" '
57  runQuery += '--show \"streams *calibration_SCTNoise\" '
58 
59  if pType == 'doDeadChip' or pType == 'doDeadStrip':
60 
61  if 'cos' not in Stream:
62  runQuery += '--streams \"*express 200000+\" '
63  runQuery += '--show \"streams *express\" '
64  else:
65  runQuery += '--streams \"*IDCosmic 200000+\" '
66  runQuery += '--show \"streams *IDCosmic\" '
67 
68 
69  runQuery += '--show run --show projecttag --show events --show time --show \"lhc\" '
70  runQuery += '--noroot --nohtml --verbose'
71  print(runQuery)
72  os.system(runQuery)
73 
74 
75  print(Run0)
76 
77 # --- Check stable beam flag if stream _is not_ cosmics
78  if 'cos' not in Stream and 'idcomm' not in Stream:
79 
80  StableBeam = False
81  if os.path.exists('./data/MyLBCollection.xml'):
82  f = open('./data/MyLBCollection.xml')
83  line = f.readline()
84  while line:
85  if "Metadata" in line and "RunList" in line and str(Run0) in line:
86  StableBeam = True
87  print("Run %s : run selection passed ---> job will be launched" %(Run0))
88  line = f.readline()
89  f.close()
90 
91  else:
92  print("ERROR problem in access to /data/MyLBCollection.xml file produced by AtlRunQuery.py --- probably due to AtlRunQuery crash...")
93  sys.exit( -1 )
94 
95  if not StableBeam:
96  print("Run %s : run selection didn't pass Stable Beam check--- job will be finished" %(Run0))
97  return False
98 
99  #===== Read last run uploaded : only for NoisyStrip =====
100  #--- Only for NoisyStrip
101  Wait = True
102  if pType != 'doNoisyStrip' or forceSkipQueue == 1 :
103  Wait = False
104 
105  #--- Check if Run0 is next to the last run uploaded
106  while Wait:
107  #--- Read last run uploaded
108  RunLast = '0'
109  if os.path.exists('/afs/cern.ch/work/s/sctcalib/lastRun') :
110  f = open('/afs/cern.ch/work/s/sctcalib/lastRun')
111  line = f.readline()
112  while line:
113  RunLast = line
114  line = f.readline()
115  f.close()
116  print("Run %s : the last run uploaded" %(RunLast)[:-1])
117 
118 # --- Check last run is before Run0
119  if int(RunLast) > int(Run0) :
120  print("Run %s : taken later than the current run ---> job will not be run" %(RunLast)[:-1])
121  return False
122 
123  #--- RunQuery
124  runQuery = 'AtlRunQuery.py '
125  runQuery += '--run \"' + str(RunLast[:-1]) + '+\" '
126 
127 # if 'cos' not in Stream:
128  if 'cos' not in Stream and 'idcomm' not in Stream:
129  runQuery += '--lhc \"stablebeams TRUE\" '
130  runQuery += '--partition \"ATLAS\" '
131  runQuery += '--detmaskin \"240A\" '
132 
133  if 'eV' in Stream:
134  runQuery += '--projecttag \"data*_*eV\" '
135  elif 'hi' in Stream:
136  runQuery += '--projecttag \"data*_hi\" '
137  elif 'cos' in Stream:
138  runQuery += '--projecttag \"data*_cos\" '
139  else:
140  runQuery += '--projecttag \"data*_idcomm\" '
141  # if 'cos' not in Stream:
142  # runQuery += '--projecttag \"data*_*eV\" '
143  # else:
144  # runQuery += '--projecttag \"data*_cos\" '
145 
146  runQuery += '--streams \"*calibration_SCTNoise 10000+\" '
147  runQuery += '--show \"streams *calibration_SCTNoise\" '
148  runQuery += '--show run --show projecttag --show events --show time --show \"lhc\" '
149  runQuery += '--noroot --nohtml --verbose'
150  print(runQuery)
151  os.system(runQuery)
152 
153  #--- Check Run0 and RunLast
154  runList=[]
155  runDict={}
156  runNum=''
157  runPro=''
158  if os.path.exists("./data/QueryResult.txt") :
159  f = open('./data/QueryResult.txt')
160  line = f.readline()
161  while line:
162  if 'Run:' in line and runNum=='':
163  runNum = line.split(':')[1]
164  runNum = runNum.replace("\n",'').replace(' ','')
165  if 'Project tag:' in line and runPro=='':
166  runPro = line.split('\'')[1]
167  if runNum!='' and runPro!='':
168  if 'data' in runPro:
169  runList.append(runNum)
170  runDict[runNum] = runPro
171  runNum=''
172  runPro=''
173  line = f.readline()
174 
175  f.close()
176 
177 
178  RunWait = 0
179  for iRun in range( int(RunLast)+1, int(Run0) ):
180  if str(iRun) in runList:
181  RunWait += 1
182  print("Run %s: this run has to be processed/uploaded ---> job in pending state " %(iRun))
183 
184 
185  if RunWait == 0:
186  Wait = False
187  print("Run %s : checked the last run uploaded ---> job will be launched" %(Run0))
188 
189  # if os.path.exists("./data/MyLBCollection.xml") :
190  # f = open('./data/MyLBCollection.xml')
191  # line = f.readline()
192  # while line:
193  # if "Metadata" in line and "RunList" in line :
194  # #--- Check if there are runs waiting for processing/upload
195  # RunWait = 0
196  # for iRun in range( int(RunLast)+1, int(Run0) ):
197  # if str(iRun) in line:
198  # RunWait += 1
199  # print("Run %s : this run has to be processed/uploaded ---> job in pending state " %(iRun))
200 
201  # if RunWait == 0:
202  # Wait = False
203  # print("Run %s : checked the last run uploaded ---> job will be launched" %(Run0))
204 
205  # line = f.readline()
206  # f.close()
207 
208  #--- Wait for RunLast update
209  if Wait:
210  print('Run %s : waiting for previous run(s) processed/uploaded' %(Run0))
211  time.sleep(5)
212 
213  #--- Start processing
214  print('Run %s : job starts running now' %(Run0))
215  return True
216 
217 #===== Execute
218 if __name__ == "__main__":
219  try :
220  runNumber = int( sys.argv[1] )
221  except Exception:
222  print("Failed to read run number" %(sys.argv[1]))
223  sys.exit( -1 )
224  try :
225  processType = str( sys.argv[2] )
226  except Exception:
227  print("Failed to read proces type" %(sys.argv[2]))
228  sys.exit( -1 )
229  try :
230  skipQueue = int( sys.argv[3] )
231  except Exception:
232  print("Setting skipqueue to default (wait until previous runs are analysed)")
233  skipQueue = 0
234 
235  main( runNum = runNumber, procType = processType, forceSkipQueue = skipQueue )
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
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
runSelector.main
def main(runNum=None, procType=None, forceSkipQueue=0, Stream=None)
Definition: runSelector.py:9
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