ATLAS Offline Software
Functions | Variables
CscCalibQuery Namespace Reference

Functions

def updateList (oldListPath, newList)
 
def runCalib (calType, runNumber, workDir, castorCopyCmd)
 

Variables

int numFilesToRun = 3
 
string responsiblePerson = "youzhou@email.arizona.edu"
 
string maillist = responsiblePerson
 
bool CoolMergeByDefault = False
 
 calType = sys.argv[1]
 Main program#############################. More...
 
string calibFileDir = '/castor/cern.ch/user/l/lampen/CalibRunTest/slope/'
 
string oldListFilePath = '/afs/cern.ch/user/m/muoncali/CSC/run/pulserList.txt'
 
string outputDir = '/afs/cern.ch/user/m/muoncali/w0/CSC/runs/pulser/pulser'
 
 calibRe = re.compile('data1.*_calib.*calibration_pedCSC\\.daq\\.RAW.*\\.data')
 
 testFile = glob.glob("/afs/cern.ch/user/m/muoncali/CSC/run/runningCalibration*")
 
 currentLs = os.popen('rfdir ' + calibFileDir).read()
 
 inFile = open(oldListFilePath, 'r')
 
 oldLs = inFile.read()
 
 now = datetime.datetime.now()
 
 today = now.day
 
 currentDirList = currentLs.split('\n')
 
 oldDirList = oldLs.split('\n')
 
bool updateRunList = True
 
string runningDir = ""
 
 splitDir = Dir.split()
 
 day = int(splitDir[-3])
 
 DirName = splitDir[-1]
 
 timediff = today - day
 
string cmd = 'rfdir ' + calibFileDir + DirName
 
 fileList = os.popen(cmd).read().split('\n')
 
int nFiles = len(fileList) -1
 
 runNumber = DirName
 
string outputDirFull = outputDir + 'Run_' + runNumber
 
bool ThisCalibDir = False
 
string castorCopyCmd = "mkdir ${bytestreamDir}"
 
tuple fileName = (file.split(' '))[-1]
 
string fullPath = calibFileDir + DirName + '/' + fileName
 

Function Documentation

◆ runCalib()

def CscCalibQuery.runCalib (   calType,
  runNumber,
  workDir,
  castorCopyCmd 
)

Definition at line 47 of file CscCalibQuery.py.

47 def runCalib(calType, runNumber,workDir,castorCopyCmd):
48  #print ('running calib')
49  #initialize based on calibration type
50  scriptDir = '${HOME}/CSC/run/'
51  if calType == 'pulser':
52  calibScript = scriptDir + 'CscCalcSlopeMon.py'
53  dbScript = scriptDir + 'cscWritePSlopeCool.py'
54  webDir = '${HOME}/www/csc/pulser'
55  runListFile = "pulserRunList.pickle"
56  #extractScript = scriptDir +'CscExtractPulser.py'
57  elif( calType == 'ped'):
58  calibScript = scriptDir + 'CscCalcPedMon.py'
59  dbScript = scriptDir + 'cscWritePedRefCool.py'
60  onlDbFile = scriptDir + 'online.cal'
61  webDir = '${HOME}/www/csc/ped'
62  webPageUrl = 'https://atlas-csc-calib.web.cern.ch/atlas-csc-calib/ped/pedRun_' +runNumber
63  runListFile = "pedRunList.pickle"
64  #extractScript = scriptDir + 'CscExtractPed.py'
65 
66  outputDir = workDir +"/CalibResults"
67  bsDir = workDir +"/Bytestream"
68 
69  print ('outputDir = ' + outputDir)
70 
71 
72  #Setup finished email message
73  emailMessage = 'Finished ' + calType + ' calibration on run number ' + runNumber
74  emailMessage += '. Output in ' + outputDir + '.'
75  emailMessage += '\\nAnd website at:\\n'
76  emailMessage += webPageUrl
77 
78  #Setup finished email subjects
79  goodEmailSubject = '[CSC CALIB PROC]: SUCCESS with ' + calType + 'calib run' + runNumber
80  badEmailSubject = '[CSC CALIB PROC]: PROBLEMS with ' + calType + 'calib run' + runNumber
81 
82  #Prepare bash script for batch system
83  bashFilePath = workDir+'/CscCalib_' + calType + '_' + runNumber + '.sh'
84 
85  bsubCmd ='cd ' + outputDir + ';bsub -q 2nd -R "type==SLC5_64&&mem>420" ' + bashFilePath
86 
87  bashFileContents = "#!/bin/bash\n"
88  bashFileContents += "#To resubmit this job, submit it to the atlasmuonqueu like so:\n#"
89  bashFileContents += bsubCmd +"\n"
90  bashFileContents += "source ~/CSC/CscSetup.sh\n"
91  bashFileContents += "\n"
92  bashFileContents += "resultDir=\"" + outputDir + "\"\n"
93  bashFileContents += 'bytestreamDir="' + bsDir + '"\n'
94  bashFileContents += 'maillist="' + maillist + '"\n'
95  bashFileContents += 'webSiteDir="' + webDir + '"\n'
96 
97  calFilePrefix= "${resultDir}/" + runNumber
98  inputPattern = "${bytestreamDir}/*.data"
99 
100  calibCommand = 'echo "Running calibration"\n' \
101  + 'mkdir ${resultDir}\n' \
102  + 'athena.py -c "outputPre=\'' + calFilePrefix \
103  + '\';inputOnlCalibFile=\'' +onlDbFile \
104  + '\';inputPat=\'' + inputPattern \
105  + '\';reportPrefix=\'' + emailMessage \
106  + '\';" ' \
107  + calibScript
108 
109 
110  goodEmailCommand = ' mail -s "' + goodEmailSubject + '" $maillist < ' + calFilePrefix + "CalibReport.txt"
111  badEmailCommand = ' mail -s "' + badEmailSubject + '" $maillist < ' + calFilePrefix + "CalibReport.txt"
112 
113  #For reference tag, we actually want the IOV to start just after the LAST run number
114  #Get old run numbers
115  infile = open(runListFile,"rb")
116  runList = pickle.load(infile)
117  runList.sort()
118  print ("got runs")
119  print (runList)
120  infile.close()
121 
122 
123  if(runNumber in runList):
124  print ("Mailing message")
125  message =["mail","-s",\
126  '"New castor run directory found for previously processed run ' + str(runNumber) + '"',\
127  responsiblePerson,\
128  "<",\
129  "runAlreadyProcessed.mail"]
130  print (message)
131  subprocess.call(message)
132  sys.exit()
133 
134 
135  highestRun = runList[-1]
136 
137  isRunNumberConflict = False
138 
139 
140  if(highestRun > runNumber):
141  #Something odd happening. The Input run number is lower than the last run number
142  #this script (thinks it) processed
143  #Notify someone important, and don't add to cool when done...
144  subprocess.call(["mail","-s",\
145  "[CSC CALIB PROC] Wrong run number ordering on run " + str(runNumber) \
146  + "! Human intervension required!",\
147  responsiblePerson,\
148  "<",\
149  "runNumberConflict.mail"]\
150  )
151  isRunNumberConflict = True
152  else:
153  #No problem, update run list
154  runList += [runNumber]
155  outfile = open(runListFile,"wb")
156  pickle.dump(runList,outfile)
157  outfile.close()
158 
159 
160  #Label that we're working, so that other instances of CscCalibQuery won't run
161  subprocess.call(['touch','/afs/cern.ch/user/m/muoncali/CSC/run/runningCalibration' + runNumber])
162 
163  #Command to create .db file
164  DbCommand = 'athena.py -c "input=\'' + calFilePrefix+'.cal\';output=\'' \
165  + calFilePrefix + '.db\';IOVRunStart=int(\'' + highestRun + '\')" ' + dbScript
166 
167  UploadCommand = ''
168  #Noexec prevents actual execution of cool
169  #UploadCommand = '/afs/cern.ch/user/a/atlcond/utils/AtlCoolMerge.py ' \
170  # + "--batch --noexec --comment=\'Automated UPD1 update from " + calType \
171  # + ' run ' + runNumber +'\' ' \
172  # + calFilePrefix + '.db' \
173  # + ' COMP200 ATONR_COOL ATLAS_COOLONL_CSC_W PASSWORD '
174  #UploadCommand += "\n"
175 
176 
177 
178 
179 
180  #Command to upload .db file to database
181  UploadCommand += '/afs/cern.ch/user/a/atlcond/utils/AtlCoolMerge.py ' \
182  + "--batch "
183  if(not CoolMergeByDefault or isRunNumberConflict):
184  UploadCommand += " --noexec "
185 
186  UploadCommand += "--comment=\'Automated reference update from " + calType \
187  + ' run ' + runNumber + ' to IOV starting at ' + highestRun + "' " \
188  + calFilePrefix + '.db' \
189  + ' COMP200 ATLAS_COOLWRITE ATLAS_COOLOFL_CSC_W WCOOLOFL4CSC17 '
190 
191  WebSiteCommand = '\nfs sa ${resultDir} webserver:afs read\n'
192  WebSiteCommand += 'cd $resultDir\n'
193  WebSiteCommand += 'ln -s ${resultDir} ${webSiteDir}/pedRun_' + runNumber + '\n'
194  WebSiteCommand += 'MakeCscPedSite.exe ' + runNumber + '.root ' + runNumber + '.cal_online\n'
195 
196  t1 = '\t'
197 
198  #Run calibration. If no problems detected, go ahead and upload.
199  bashFileContents += '\ncd ' + workDir + '\n' \
200  + "#Copying files from castor#\n" \
201  + castorCopyCmd \
202  + '\n'\
203  + "#Running calibration (and calib monitoring)\n"\
204  + "#, resulting in .cal file and status report\n"\
205  + calibCommand +'\n' \
206  + "\n"\
207  + "#Athena job to transform *.cal file to *.db file.\n"\
208  + DbCommand + '\n' \
209  + "#Python utility to upload *.db file to database. When entering by\n"\
210  + "#hand, I recomend removing '--batch' flag so you can check puposed\n"\
211  + "#operations before submision to database\n"\
212  + UploadCommand + '\n' \
213  + '#Check if AllCalibMonGood file was created, which means that\n'\
214  + '#this run passed acceptable criteria in the calibration monitoring\n'\
215  + 'if [ -a AllCalibMonGood ]; then\n' \
216  + t1 + "#Email list that the calibration looks good\n"\
217  + t1 + goodEmailCommand +'\n' \
218  + t1 + "################################################################\n"\
219  + t1 + "#Execute next two commands if you want to submit database entry#\n"\
220  + t1 + "#Useful if these steps were skipped due to suspicious behaviour#\n"\
221  + t1 + "#during calibration. #\n"\
222  + t1 + "###############################################################\n"\
223  + t1 + "\n"\
224  + t1 + '\n'\
225  + 'else\n' \
226  + t1 + "#Suspicious behaviour in calibration. Notify mail list of this fact\n"\
227  + t1 + badEmailCommand + '\n' \
228  + 'fi\n'\
229  + '\n'\
230  + '#Always create website'\
231  + WebSiteCommand + '\n' \
232  + 'rm -rf $bytestreamDir\n' \
233  + 'rm -rf ' + scriptDir +"runningCalibration" + runNumber +'\n'
234 
235  #Write bashfile
236  print ("Printing bash file to: " +bashFilePath)
237  bashFile = open(bashFilePath, 'w')
238  bashFile.write(bashFileContents)
239  bashFile.close()
240 
241  #Submit script
242  os.system('chmod +x ' + bashFilePath)
243  bsubsMessage = os.popen(bsubCmd).read()
244 
245  #Send alert email
246  emailMessage = 'Starting ' + calType + ' calibration on run number ' + runNumber
247  emailSubject = '[CSC CALIB PROC]: ' + emailMessage
248  emailMessage += '\nbsubs output:\n' + bsubsMessage
249  os.system('echo "' + emailMessage + '" | mail -s "' + emailSubject + '" ' + maillist)
250 

◆ updateList()

def CscCalibQuery.updateList (   oldListPath,
  newList 
)

Definition at line 37 of file CscCalibQuery.py.

37 def updateList(oldListPath,newList):
38  print ('updating file list')
39  #update the old file list
40  outFile = open(oldListPath, 'w')
41  outFile.write(newList)
42  outFile.close()
43 
44 #runs calibration on input file.
45 #It creates a bash script which can setup the job, run it, and do post job
46 #processing. The bash script is submitted to lxbatch

Variable Documentation

◆ calibFileDir

string CscCalibQuery.calibFileDir = '/castor/cern.ch/user/l/lampen/CalibRunTest/slope/'

Definition at line 259 of file CscCalibQuery.py.

◆ calibRe

CscCalibQuery.calibRe = re.compile('data1.*_calib.*calibration_pedCSC\\.daq\\.RAW.*\\.data')

Definition at line 266 of file CscCalibQuery.py.

◆ calType

CscCalibQuery.calType = sys.argv[1]

Main program#############################.

Definition at line 257 of file CscCalibQuery.py.

◆ castorCopyCmd

string CscCalibQuery.castorCopyCmd = "mkdir ${bytestreamDir}"

Definition at line 346 of file CscCalibQuery.py.

◆ cmd

string CscCalibQuery.cmd = 'rfdir ' + calibFileDir + DirName

Definition at line 329 of file CscCalibQuery.py.

◆ CoolMergeByDefault

bool CscCalibQuery.CoolMergeByDefault = False

Definition at line 32 of file CscCalibQuery.py.

◆ currentDirList

CscCalibQuery.currentDirList = currentLs.split('\n')

Definition at line 301 of file CscCalibQuery.py.

◆ currentLs

CscCalibQuery.currentLs = os.popen('rfdir ' + calibFileDir).read()

Definition at line 282 of file CscCalibQuery.py.

◆ day

CscCalibQuery.day = int(splitDir[-3])

Definition at line 312 of file CscCalibQuery.py.

◆ DirName

CscCalibQuery.DirName = splitDir[-1]

Definition at line 313 of file CscCalibQuery.py.

◆ fileList

CscCalibQuery.fileList = os.popen(cmd).read().split('\n')

Definition at line 330 of file CscCalibQuery.py.

◆ fileName

tuple CscCalibQuery.fileName = (file.split(' '))[-1]

Definition at line 348 of file CscCalibQuery.py.

◆ fullPath

string CscCalibQuery.fullPath = calibFileDir + DirName + '/' + fileName

Definition at line 360 of file CscCalibQuery.py.

◆ inFile

CscCalibQuery.inFile = open(oldListFilePath, 'r')

Definition at line 287 of file CscCalibQuery.py.

◆ maillist

string CscCalibQuery.maillist = responsiblePerson

Definition at line 30 of file CscCalibQuery.py.

◆ nFiles

int CscCalibQuery.nFiles = len(fileList) -1

Definition at line 332 of file CscCalibQuery.py.

◆ now

CscCalibQuery.now = datetime.datetime.now()

Definition at line 295 of file CscCalibQuery.py.

◆ numFilesToRun

int CscCalibQuery.numFilesToRun = 3

Definition at line 28 of file CscCalibQuery.py.

◆ oldDirList

CscCalibQuery.oldDirList = oldLs.split('\n')

Definition at line 302 of file CscCalibQuery.py.

◆ oldListFilePath

string CscCalibQuery.oldListFilePath = '/afs/cern.ch/user/m/muoncali/CSC/run/pulserList.txt'

Definition at line 260 of file CscCalibQuery.py.

◆ oldLs

CscCalibQuery.oldLs = inFile.read()

Definition at line 288 of file CscCalibQuery.py.

◆ outputDir

string CscCalibQuery.outputDir = '/afs/cern.ch/user/m/muoncali/w0/CSC/runs/pulser/pulser'

Definition at line 261 of file CscCalibQuery.py.

◆ outputDirFull

string CscCalibQuery.outputDirFull = outputDir + 'Run_' + runNumber

Definition at line 338 of file CscCalibQuery.py.

◆ responsiblePerson

string CscCalibQuery.responsiblePerson = "youzhou@email.arizona.edu"

Definition at line 29 of file CscCalibQuery.py.

◆ runningDir

CscCalibQuery.runningDir = ""

Definition at line 305 of file CscCalibQuery.py.

◆ runNumber

CscCalibQuery.runNumber = DirName

Definition at line 335 of file CscCalibQuery.py.

◆ splitDir

CscCalibQuery.splitDir = Dir.split()

Definition at line 311 of file CscCalibQuery.py.

◆ testFile

CscCalibQuery.testFile = glob.glob("/afs/cern.ch/user/m/muoncali/CSC/run/runningCalibration*")

Definition at line 274 of file CscCalibQuery.py.

◆ ThisCalibDir

CscCalibQuery.ThisCalibDir = False

Definition at line 345 of file CscCalibQuery.py.

◆ timediff

CscCalibQuery.timediff = today - day

Definition at line 316 of file CscCalibQuery.py.

◆ today

CscCalibQuery.today = now.day

Definition at line 296 of file CscCalibQuery.py.

◆ updateRunList

bool CscCalibQuery.updateRunList = True

Definition at line 304 of file CscCalibQuery.py.

read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
CscCalibQuery.runCalib
def runCalib(calType, runNumber, workDir, castorCopyCmd)
Definition: CscCalibQuery.py:47
Trk::open
@ open
Definition: BinningType.h:40
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
str
Definition: BTagTrackIpAccessor.cxx:11
CscCalibQuery.updateList
def updateList(oldListPath, newList)
Definition: CscCalibQuery.py:37