1 import math, re, optparse, commands, os, sys, time, datetime
2 from BeamSpotObj
import BeamSpot
11 timeFormat =
"%a,%Y/%m/%d,%H:%M:%S"
12 currentTime = time.gmtime()
13 timeoutLine = type +
' ' + time.strftime(timeFormat, currentTime) +
'\n'
17 fileExist = os.path.isfile(fileName)
27 fields = line.strip(
'\n').
split(
' ')
31 text = text.replace(line,
'')
34 fileTime = time.strptime(fields[1],timeFormat)
35 myTime = time.mktime(fileTime)
36 referenceTime = time.mktime(time.gmtime())
38 if currentTime.tm_isdst == 0:
40 elapsedTime = referenceTime-myTime-daylight
41 if elapsedTime > timeout:
44 print "Timeout! " + str(elapsedTime) +
" seconds passed since the " + type +
" timeout was set and you can't tolerate more than " + str(timeout) +
" seconds!"
47 print "Timeout of type " + type +
" already exist and was generated " + str(elapsedTime) +
" seconds ago at " + fields[1]
51 if not fileExist
or not alreadyThere
and not reset:
55 if not fileExist
or not alreadyThere
or isTimeout
or (reset
and alreadyThere):
57 commands.getstatusoutput(
"rm -rf " + fileName)
58 file = open(fileName,
'w')
73 if os.path.isfile(lockFile):
81 commands.getstatusoutput(
"touch " + lockFile)
87 commands.getstatusoutput(
"rm " + lockFile)
92 raise SystemExit(msg
or optionstring.replace(
"%prog",sys.argv[0]))
102 USAGE = re.compile(
r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
108 optionstring = docstring
109 match = USAGE.search(optionstring)
110 if not match:
raise ParsingError(
"Cannot find the option string")
111 optlines = match.group(1).splitlines()
113 p = optparse.OptionParser(optlines[0])
114 for line
in optlines[1:]:
115 opt, help=line.split(
':')[:2]
116 short,long=opt.split(
',')[:2]
119 long=long.split(
'=')[0]
122 p.add_option(short.strip(),long.strip(),
123 action = action, help = help.strip())
124 except (IndexError,ValueError):
125 raise ParsingError(
"Cannot parse the option string correctly")
126 return p.parse_args(arglist)
130 "True if options were given"
131 for v
in self.__dict__.itervalues():
132 if v
is not None:
return True
136 optparse.Values.__nonzero__ = nonzero
149 print "Sending email to " + mailList +
" with body: " + error
150 list = mailList.split(
',')
152 p = os.popen(
"mail -s \"Automatic workflow error\" " + email ,
"w")
158 if dir.find(
"castor") != -1:
159 lsCommand =
"nsls " + dir
160 output = commands.getstatusoutput( lsCommand )
163 return os.path.exists(dir)
166 def ls(dir,filter=""):
169 if dir.find(
'castor') != -1:
171 elif not os.path.exists(dir):
172 print "ERROR: File or directory " + dir +
" doesn't exist"
175 aCommand = lsCommand +
'ls '+ dir
178 aCommand +=
" | grep " + filter
180 tmpStatus = commands.getstatusoutput( aCommand )
181 listOfFiles = tmpStatus[1].
split(
'\n')
182 if len(listOfFiles) == 1:
183 if listOfFiles[0].
find(
'No such file or directory') != -1:
184 exit(
"ERROR: File or directory " + dir +
" doesn't exist")
189 def cp(fromDir,toDir,listOfFiles,overwrite=False,smallList=False):
192 if fromDir.find(
'castor') != -1
or toDir.find(
'castor') != -1 :
194 elif fromDir.find(
'resilient') != -1:
196 if fromDir[len(fromDir)-1] !=
'/':
199 if toDir[len(toDir)-1] !=
'/':
202 for file
in listOfFiles:
203 if os.path.isfile(toDir+file):
205 print "File " + file +
" already exists in destination directory. We will overwrite it."
207 print "File " + file +
" already exists in destination directory. We will Keep original file."
209 copiedFiles.append(file)
212 aCommand = cpCommand +
'cp '+ fromDir + file +
" " + toDir
213 print " >> " + aCommand
214 tmpStatus = commands.getstatusoutput( aCommand )
215 if tmpStatus[0] == 0:
216 copiedFiles.append(file)
218 print "[cp()]\tERROR: Can't copy file " + file
228 """pack high,low 32bit unsigned int to one unsigned 64bit long long
229 Note:the print value of result number may appear signed, if the sign bit is used.
236 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
244 """unpack 64bit lumiid to dictionary {'run','lumisection'}
247 return {
'run':j[0],
'lumisection':j[1]}
254 if int(a.IOVfirst) < int(b.IOVfirst):
return -1
255 if int(a.IOVfirst) == int(b.IOVfirst):
return 0
256 if int(a.IOVfirst) > int(b.IOVfirst):
return 1
260 if int(a.Run) < int(b.Run):
return -1
261 if int(a.Run) == int(b.Run):
262 if int(a.IOVfirst) < int(b.IOVfirst):
return -1
263 if int(a.IOVfirst) == int(b.IOVfirst):
return 0
264 if int(a.IOVfirst) > int(b.IOVfirst):
return 1
265 if int(a.Run) > int(b.Run) :
return 1
278 x1 = x2/(x2err * x2err)
279 tmperr = 1/(x2err*x2err)
281 x1 = x1/(x1err*x1err) + x2/(x2err * x2err)
282 tmperr = 1/(x1err*x1err) + 1/(x2err*x2err)
285 x1err = math.sqrt(x1err)
286 return (str(x1), str(x1err))
291 file.write(
"Runnumber "+beam.Run+end)
292 file.write(
"BeginTimeOfFit "+str(beam.IOVBeginTime)+end)
293 file.write(
"EndTimeOfFit "+str(beam.IOVEndTime)+end)
294 file.write(
"LumiRange "+str(beam.IOVfirst)+
" - "+str(beam.IOVlast)+end)
300 file.write(
"Type "+str(beam.Type)+end)
301 file.write(
"X0 "+str(beam.X)+end)
302 file.write(
"Y0 "+str(beam.Y)+end)
303 file.write(
"Z0 "+str(beam.Z)+end)
304 file.write(
"sigmaZ0 "+str(beam.sigmaZ)+end)
305 file.write(
"dxdz "+str(beam.dxdz)+end)
306 file.write(
"dydz "+str(beam.dydz)+end)
307 file.write(
"BeamWidthX "+beam.beamWidthX+end)
308 file.write(
"BeamWidthY "+beam.beamWidthY+end)
309 file.write(
"Cov(0,j) "+str(math.pow(float(beam.Xerr),2))+
" 0 0 0 0 0 0" +end)
310 file.write(
"Cov(1,j) 0 "+str(math.pow(float(beam.Yerr),2))+
" 0 0 0 0 0" +end)
311 file.write(
"Cov(2,j) 0 0 "+str(math.pow(float(beam.Zerr),2))+
" 0 0 0 0" +end)
312 file.write(
"Cov(3,j) 0 0 0 "+str(math.pow(float(beam.sigmaZerr),2))+
" 0 0 0" +end)
313 file.write(
"Cov(4,j) 0 0 0 0 "+str(math.pow(float(beam.dxdzerr),2))+
" 0 0" +end)
314 file.write(
"Cov(5,j) 0 0 0 0 0 "+str(math.pow(float(beam.dydzerr),2))+
" 0" +end)
315 file.write(
"Cov(6,j) 0 0 0 0 0 0 "+str(math.pow(float(beam.beamWidthXerr),2)) +end)
316 file.write(
"EmittanceX 0"+end)
317 file.write(
"EmittanceY 0"+end)
318 file.write(
"BetaStar 0"+end)
323 return ( float(x) - float(nextx), math.sqrt(math.pow(float(xerr),2) + math.pow(float(nextxerr),2)) )
326 return math.fabs(x[0])/x[1]
329 def readBeamSpotFile(fileName,listbeam=[],IOVbase="runbase", firstRun='1',lastRun='4999999999'):
335 if IOVbase ==
"lumibase" and firstRun==
'1' and lastRun==
'4999999999' :
337 lastRun =
"4999999999:4999999999"
347 tmpfile = open(fileName)
348 atmpline = tmpfile.readline()
349 if atmpline.find(
'Runnumber') != -1:
351 if len(atmpline.split()) > 2:
353 print " Input data has been calculated as function of BUNCH CROSSINGS."
357 if inputfiletype ==1:
362 if line.find(
'Type') != -1:
363 tmpbeam.Type = int(line.split()[1])
365 if line.find(
'X0') != -1:
366 tmpbeam.X = line.split()[1]
370 if line.find(
'Y0') != -1:
371 tmpbeam.Y = line.split()[1]
375 if line.find(
'Z0') != -1
and line.find(
'sigmaZ0') == -1:
376 tmpbeam.Z = line.split()[1]
379 if line.find(
'sigmaZ0') !=-1:
380 tmpbeam.sigmaZ = line.split()[1]
383 if line.find(
'dxdz') != -1:
384 tmpbeam.dxdz = line.split()[1]
387 if line.find(
'dydz') != -1:
388 tmpbeam.dydz = line.split()[1]
391 if line.find(
'BeamWidthX') != -1:
392 tmpbeam.beamWidthX = line.split()[1]
395 if line.find(
'BeamWidthY') != -1:
396 tmpbeam.beamWidthY = line.split()[1]
399 if line.find(
'Cov(0,j)') != -1:
400 tmpbeam.Xerr = str(math.sqrt( float( line.split()[1] ) ) )
402 if line.find(
'Cov(1,j)') != -1:
403 tmpbeam.Yerr = str(math.sqrt( float( line.split()[2] ) ) )
405 if line.find(
'Cov(2,j)') != -1:
406 tmpbeam.Zerr = str(math.sqrt( float( line.split()[3] ) ) )
408 if line.find(
'Cov(3,j)') != -1:
409 tmpbeam.sigmaZerr = str(math.sqrt( float( line.split()[4] ) ) )
411 if line.find(
'Cov(4,j)') != -1:
412 tmpbeam.dxdzerr = str(math.sqrt( float( line.split()[5] ) ) )
414 if line.find(
'Cov(5,j)') != -1:
415 tmpbeam.dydzerr = str(math.sqrt( float( line.split()[6] ) ) )
417 if line.find(
'Cov(6,j)') != -1:
418 tmpbeam.beamWidthXerr = str(math.sqrt( float( line.split()[7] ) ) )
419 tmpbeam.beamWidthYerr = tmpbeam.beamWidthXerr
421 if line.find(
'LumiRange') != -1:
422 if IOVbase==
"lumibase":
423 tmpbeam.IOVfirst = line.split()[1]
424 tmpbeam.IOVlast = line.split()[3]
426 if line.find(
'Runnumber') != -1:
427 tmpbeam.Run = line.split()[1]
428 if IOVbase ==
"runbase":
429 tmpbeam.IOVfirst = line.split()[1]
430 tmpbeam.IOVlast = line.split()[1]
432 tmpBX = line.split()[3]
434 if line.find(
'BeginTimeOfFit') != -1:
435 tmpbeam.IOVBeginTime = line.split()[1] +
" "+line.split()[2] +
" "+line.split()[3]
436 if IOVbase ==
"timebase":
437 tmpbeam.IOVfirst = time.mktime( time.strptime(line.split()[1] +
" " + line.split()[2] +
" " + line.split()[3],
"%Y.%m.%d %H:%M:%S %Z") )
439 if line.find(
'EndTimeOfFit') != -1:
440 tmpbeam.IOVEndTime = line.split()[1] +
" "+line.split()[2] +
" "+line.split()[3]
441 if IOVbase ==
"timebase":
442 tmpbeam.IOVlast = time.mktime( time.strptime(line.split()[1] +
" " + line.split()[2] +
" " + line.split()[3],
"%Y.%m.%d %H:%M:%S %Z") )
444 if tmpbeamsize == 20:
445 if IOVbase==
"lumibase":
446 tmprunfirst = int(firstRun.split(
":")[0])
447 tmprunlast = int(lastRun.split(
":")[0])
448 tmplumifirst = int(firstRun.split(
":")[1])
449 tmplumilast = int(lastRun.split(
":")[1])
450 acceptiov1 = acceptiov2 =
False
452 if tmprunfirst == tmprunlast
and int(tmpbeam.Run)==tmprunfirst:
453 if int(tmpbeam.IOVfirst) >= tmplumifirst
and int(tmpbeam.IOVlast)<=tmplumilast:
454 acceptiov1 = acceptiov2 =
True
456 elif int(tmpbeam.Run) == tmprunfirst:
457 if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 =
True
458 elif int(tmpbeam.Run) == tmprunlast:
459 if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 =
True
460 elif tmprunfirst <= int(tmpbeam.Run)
and tmprunlast >= int(tmpbeam.Run):
461 acceptiov1 = acceptiov2 =
True
463 if acceptiov1
and acceptiov2:
464 if tmpbeam.Type != 2:
465 print "invalid fit, skip Run "+str(tmpbeam.Run)+
" IOV: "+str(tmpbeam.IOVfirst) +
" to "+ str(tmpbeam.IOVlast)
466 elif isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
467 print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+
" IOV: "+str(tmpbeam.IOVfirst) +
" to "+ str(tmpbeam.IOVlast)
469 if (tmpBX
in maplist) ==
False:
470 maplist[tmpBX] = [tmpbeam]
472 maplist[tmpBX].
append(tmpbeam)
474 listbeam.append(tmpbeam)
476 elif int(tmpbeam.IOVfirst) >= int(firstRun)
and int(tmpbeam.IOVlast) <= int(lastRun):
477 if tmpbeam.Type != 2:
478 print "invalid fit, skip Run "+str(tmpbeam.Run)+
" IOV: "+str(tmpbeam.IOVfirst) +
" to "+ str(tmpbeam.IOVlast)
479 elif isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
480 print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+
" IOV: "+str(tmpbeam.IOVfirst) +
" to "+ str(tmpbeam.IOVlast)
482 listbeam.append(tmpbeam)
491 if line.find(
'X0') != -1:
492 tmpbeam.X = line.split()[2]
493 tmpbeam.Xerr = line.split()[4]
496 if line.find(
'Y0') != -1:
497 tmpbeam.Y = line.split()[2]
498 tmpbeam.Yerr = line.split()[4]
501 if line.find(
'Z0') != -1
and line.find(
'Sigma Z0') == -1:
502 tmpbeam.Z = line.split()[2]
503 tmpbeam.Zerr = line.split()[4]
506 if line.find(
'Sigma Z0') !=-1:
507 tmpbeam.sigmaZ = line.split()[3]
508 tmpbeam.sigmaZerr = line.split()[5]
510 if line.find(
'dxdz') != -1:
511 tmpbeam.dxdz = line.split()[2]
512 tmpbeam.dxdzerr = line.split()[4]
514 if line.find(
'dydz') != -1:
515 tmpbeam.dydz = line.split()[2]
516 tmpbeam.dydzerr = line.split()[4]
518 if line.find(
'Beam Width X') != -1:
519 tmpbeam.beamWidthX = line.split()[4]
520 tmpbeam.beamWidthXerr = line.split()[6]
522 if line.find(
'Beam Width Y') != -1:
523 tmpbeam.beamWidthY = line.split()[4]
524 tmpbeam.beamWidthYerr = line.split()[6]
527 if line.find(
'for runs') != -1:
529 tmpbeam.Run = line.split()[2]
530 if IOVbase ==
"runbase":
531 tmpbeam.IOVfirst = line.split()[2]
532 tmpbeam.IOVlast = line.split()[4]
534 if line.find(
'LumiSection') != -1:
535 if IOVbase==
"lumibase":
536 tmpbeam.IOVfirst = line.split()[10]
537 tmpbeam.IOVlast = line.split()[10]
539 if tmpbeamsize == 10:
541 if IOVbase==
"lumibase":
542 tmprunfirst = int(firstRun.split(
":")[0])
543 tmprunlast = int(lastRun.split(
":")[0])
544 tmplumifirst = int(firstRun.split(
":")[1])
545 tmplumilast = int(lastRun.split(
":")[1])
546 acceptiov1 = acceptiov2 =
False
548 if tmprunfirst == tmprunlast
and int(tmpbeam.Run)==tmprunfirst:
549 if int(tmpbeam.IOVfirst) >= tmplumifirst
and int(tmpbeam.IOVlast)<=tmplumilast:
550 acceptiov1 = acceptiov2 =
True
552 elif int(tmpbeam.Run) == tmprunfirst:
553 if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 =
True
554 elif int(tmpbeam.Run) == tmprunlast:
555 if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 =
True
556 elif tmprunfirst <= int(tmpbeam.Run)
and tmprunlast >= int(tmpbeam.Run):
557 acceptiov1 = acceptiov2 =
True
559 if acceptiov1
and acceptiov2:
560 if isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
561 print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+
" IOV: "+str(tmpbeam.IOVfirst) +
" to "+ str(tmpbeam.IOVlast)
563 if (tmpBX
in maplist) ==
False:
564 maplist[tmpBX] = [tmpbeam]
566 maplist[tmpBX].
append(tmpbeam)
568 listbeam.append(tmpbeam)
570 elif int(tmpbeam.IOVfirst) >= int(firstRun)
and int(tmpbeam.IOVlast) <= int(lastRun):
571 if isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
572 print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+
" IOV: "+str(tmpbeam.IOVfirst) +
" to "+ str(tmpbeam.IOVlast)
574 listbeam.append(tmpbeam)
581 print " got total number of IOVs = " + str(len(listbeam)) +
" from file " + fileName
592 if IOVbase ==
"lumibase":
593 listbeam.sort( cmp = cmp_list_lumi )
595 listbeam.sort( cmp = cmp_list_run )
599 for ii
in range(0,len(listbeam)):
601 datax = ibeam.IOVfirst
603 if datax ==
'0' and IOVbase ==
"runbase":
604 print " iov = 0? skip this IOV = "+ str(ibeam.IOVfirst) +
" to " + str(ibeam.IOVlast)
605 tmpremovelist.append(ibeam)
607 if ii < len(listbeam) -1:
609 if IOVbase ==
"lumibase":
610 if ibeam.Run == listbeam[ii+1].Run
and ibeam.IOVfirst == listbeam[ii+1].IOVfirst:
611 print " duplicate IOV = "+datax+
", keep only last duplicate entry"
612 tmpremovelist.append(ibeam)
613 elif datax == listbeam[ii+1].IOVfirst:
614 print " duplicate IOV = "+datax+
", keep only last duplicate entry"
615 tmpremovelist.append(ibeam)
617 for itmp
in tmpremovelist:
618 listbeam.remove(itmp)
630 maxNlumis = 999999999
631 for ii
in range(0,len(listbeam)):
636 tmpbeam.IOVfirst = ibeam.IOVfirst
637 tmpbeam.IOVBeginTime = ibeam.IOVBeginTime
638 tmpbeam.Run = ibeam.Run
645 if ii < len(listbeam) - 1:
646 inextbeam = listbeam[ii+1]
648 if ii < len(listbeam) -2:
649 iNNbeam = listbeam[ii+2]
651 print "close payload because end of data has been reached. Run "+ibeam.Run
654 if ibeam.Run != inextbeam.Run:
655 print "close payload because end of run "+ibeam.Run
658 if countlumi == maxNlumis -1:
659 print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
663 (tmpbeam.X, tmpbeam.Xerr) =
weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
664 (tmpbeam.Y, tmpbeam.Yerr) =
weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
665 (tmpbeam.Z, tmpbeam.Zerr) =
weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
666 (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) =
weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
667 (tmpbeam.dxdz, tmpbeam.dxdzerr) =
weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
668 (tmpbeam.dydz, tmpbeam.dydzerr) =
weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
670 (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) =
weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
671 (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) =
weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
683 limit = float(ibeam.beamWidthX)/2.
684 if limit < min_limit: limit = min_limit
687 adelta1 =
delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr)
689 adelta1dxdz =
delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
690 adelta2dxdz = (0.,1.e9)
691 adelta1dydz =
delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
692 adelta2dydz = (0.,1.e9)
693 adelta1widthx =
delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
694 adelta2widthx = (0.,1.e9)
695 adelta1widthy =
delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
696 adelta2widthy = (0.,1.e9)
697 adelta1z0 =
delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr)
698 adelta1sigmaZ =
delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr)
700 if iNNbeam.Type != -1:
701 adelta2 =
delta(inextbeam.X, inextbeam.Xerr, iNNbeam.X, iNNbeam.Xerr)
702 adelta2dxdz =
delta(inextbeam.dxdz, inextbeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr)
703 adelta2dydz =
delta(inextbeam.dydz, inextbeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr)
704 adelta2widthx =
delta(inextbeam.beamWidthX, inextbeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr)
705 adelta2widthy =
delta(inextbeam.beamWidthY, inextbeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr)
707 deltaX =
deltaSig(adelta1) > 3.5
and adelta1[0] >= limit
708 if ii < len(listbeam) -2:
709 if deltaX==
False and adelta1[0]*adelta2[0] > 0.
and math.fabs(adelta1[0]+adelta2[0]) >= limit:
712 elif deltaX==
True and adelta1[0]*adelta2[0]<=0
and adelta2[0] != 0
and math.fabs(adelta1[0]/adelta2[0]) > 0.33
and math.fabs(adelta1[0]/adelta2[0]) < 3:
719 adelta1 =
delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr)
721 if iNNbeam.Type != -1:
722 adelta2 =
delta(inextbeam.Y, inextbeam.Yerr, iNNbeam.Y, iNNbeam.Yerr)
724 deltaY =
deltaSig(adelta1) > 3.5
and adelta1[0] >= limit
725 if ii < len(listbeam) -2:
726 if deltaY==
False and adelta1[0]*adelta2[0] > 0.
and math.fabs(adelta1[0]+adelta2[0]) >= limit:
728 elif deltaY==
True and adelta1[0]*adelta2[0]<=0
and adelta2[0] != 0
and math.fabs(adelta1[0]/adelta2[0]) > 0.33
and math.fabs(adelta1[0]/adelta2[0]) < 3:
732 limit = float(ibeam.sigmaZ)/2.
733 deltaZ =
deltaSig(adelta1z0) > 3.5
and math.fabs(adelta1z0[0]) >= limit
735 deltasigmaZ =
deltaSig(adelta1sigmaZ) > 5.0
738 adelta =
delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
740 if deltadxdz
and adelta1dxdz[0]*adelta2dxdz[0]<=0
and adelta2dxdz[0] != 0
and math.fabs(adelta1dxdz[0]/adelta2dxdz[0]) > 0.33
and math.fabs(adelta1dxdz[0]/adelta2dxdz[0]) < 3:
743 adelta =
delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
745 if deltadydz
and adelta1dydz[0]*adelta2dydz[0]<=0
and adelta2dydz[0] != 0
and math.fabs(adelta1dydz[0]/adelta2dydz[0]) > 0.33
and math.fabs(adelta1dydz[0]/adelta2dydz[0]) < 3:
748 adelta =
delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
750 if deltawidthX
and adelta1widthx[0]*adelta2widthx[0]<=0
and adelta2widthx[0] != 0
and math.fabs(adelta1widthx[0]/adelta2widthx[0]) > 0.33
and math.fabs(adelta1widthx[0]/adelta2widthx[0]) < 3:
753 adelta =
delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
755 if deltawidthY
and adelta1widthy[0]*adelta2widthy[0]<=0
and adelta2widthy[0] != 0
and math.fabs(adelta1widthy[0]/adelta2widthy[0]) > 0.33
and math.fabs(adelta1widthy[0]/adelta2widthy[0]) < 3:
769 if deltaX
or deltaY
or deltaZ
or deltasigmaZ
or deltadxdz
or deltadydz
or deltawidthX
or deltawidthY:
777 print "close payload because of movement in X= "+str(deltaX)+
", Y= "+str(deltaY) +
", Z= "+str(deltaZ)+
", sigmaZ= "+str(deltasigmaZ)+
", dxdz= "+str(deltadxdz)+
", dydz= "+str(deltadydz)+
", widthX= "+str(deltawidthX)+
", widthY= "+str(deltawidthY)
780 tmpbeam.IOVlast = ibeam.IOVlast
781 tmpbeam.IOVEndTime = ibeam.IOVEndTime
782 print " Run: "+tmpbeam.Run +
" Lumi1: "+str(tmpbeam.IOVfirst) +
" Lumi2: "+str(tmpbeam.IOVlast)
783 newlistbeam.append(tmpbeam)
789 payloadfile = open(fileName,
"w")
790 for iload
in newlistbeam:
791 dump( iload, payloadfile )
799 lastPayload = listbeam[0]
803 for ii
in range(0,len(listbeam)):
806 deltaX =
delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr) > 1.5
807 deltaY =
delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr) > 1.5
808 deltaZ =
delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr) > 2.5
810 deltasigmaZ =
delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr) > 2.5
811 deltadxdz =
delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr) > 2.5
812 deltadydz =
delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr) > 2.5
814 deltawidthX =
delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr) > 3
815 deltawidthY =
delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr) > 3
829 if deltaX
or deltaY
or deltaZ
or deltasigmaZ
or deltadxdz
or deltadydz
or deltawidthX
or deltawidthY:
839 print "close payload because of movement in X= "+str(deltaX)+
", Y= "+str(deltaY) +
", Z= "+str(deltaZ)+
", sigmaZ= "+str(deltasigmaZ)+
", dxdz= "+str(deltadxdz)+
", dydz= "+str(deltadydz)+
", widthX= "+str(deltawidthX)+
", widthY= "+str(deltawidthY)
842 if ii >= len(listbeam) - 1
or listbeam[ii].Run != listbeam[ii+1].Run :
843 print "close payload because end of run has been reached. Run " + listbeam[ii].Run
855 for ibeam
in listbeam[firstToUse:lastToUse]:
856 (tmpbeam.X, tmpbeam.Xerr) =
weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
857 (tmpbeam.Y, tmpbeam.Yerr) =
weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
858 (tmpbeam.Z, tmpbeam.Zerr) =
weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
859 (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) =
weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
860 (tmpbeam.dxdz, tmpbeam.dxdzerr) =
weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
861 (tmpbeam.dydz, tmpbeam.dydzerr) =
weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
863 (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) =
weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
864 (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) =
weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
865 tmpbeam.IOVfirst = listbeam[firstToUse].IOVfirst
866 tmpbeam.IOVBeginTime = listbeam[firstToUse].IOVBeginTime
867 tmpbeam.Run = listbeam[firstToUse].Run
869 tmpbeam.IOVlast = listbeam[lastToUse].IOVlast
870 tmpbeam.IOVEndTime = listbeam[lastToUse].IOVEndTime
871 newlistbeam.append(tmpbeam)
872 firstToUse = lastToUse+1
873 print "Run: " + tmpbeam.Run +
" Lumi1: " + str(tmpbeam.IOVfirst) +
" Lumi2: " + str(tmpbeam.IOVlast)
875 payloadfile = open(fileName,
"w")
876 for iload
in newlistbeam:
877 dump( iload, payloadfile )
881 def writeSqliteFile(sqliteFileName,tagName,timeType,beamSpotFile,sqliteTemplateFile,tmpDir="/tmp/"):
882 writeDBOut = tmpDir +
"write2DB_" + tagName +
".py"
883 wFile = open(sqliteTemplateFile)
884 wNewFile = open(writeDBOut,
'w')
886 writeDBTags = [(
'SQLITEFILE',
'sqlite_file:' + sqliteFileName),
888 (
'TIMETYPE',timeType),
889 (
'BEAMSPOTFILE',beamSpotFile)]
892 for itag
in writeDBTags:
893 line = line.replace(itag[0],itag[1])
897 print "writing sqlite file ..."
898 status_wDB = commands.getstatusoutput(
'cmsRun '+ writeDBOut)
901 os.system(
"rm -f " + writeDBOut)
902 return not status_wDB[0]
906 readDBOut = tmpDir +
"readDB_" + tagName +
".py"
908 rFile = open(sqliteTemplateFile)
909 rNewFile = open(readDBOut,
'w')
911 readDBTags = [(
'SQLITEFILE',
'sqlite_file:' + sqliteFileName),
915 for itag
in readDBTags:
916 line = line.replace(itag[0],itag[1])
920 status_rDB = commands.getstatusoutput(
'cmsRun '+ readDBOut)
922 outtext = status_rDB[1]
924 os.system(
"rm -f " + readDBOut)
925 return not status_rDB[0]
928 def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill ,tmpDir="/tmp/"):
929 aCommand =
"conddb_import -c sqlite_file:" + tmpDir + combinedSqliteFileName +
" -f sqlite_file:" + sqliteFileName +
" -i " + tagName +
" -t " + tagName +
" -b " + IOVSince +
" -e " + IOVTill
931 std = commands.getstatusoutput(aCommand)
938 acmd =
"chmod a+w " + sqliteFileDirName + sqliteFileName +
".txt"
939 outcmd = commands.getstatusoutput(acmd)
943 print "Can't change permission to file: " + sqliteFileDirName + sqliteFileName +
".txt"
946 acmd =
"cp " + sqliteFileDirName + sqliteFileName +
".db " + sqliteFileDirName + sqliteFileName +
".txt ."
948 outcmd = commands.getstatusoutput(acmd)
951 print "Couldn't cd to " + sqliteFileDirName
954 acmd =
"tar -cvjf " + sqliteFileName +
".tar.bz2 " + sqliteFileName +
".db " + sqliteFileName +
".txt"
956 outcmd = commands.getstatusoutput(acmd)
959 print "Couldn't zip the files!"
962 acmd =
"chmod a+w " + sqliteFileName +
".tar.bz2"
963 outcmd = commands.getstatusoutput(acmd)
967 print "Can't change permission to file: " + sqliteFileDirName + sqliteFileName +
".tar.bz2"
970 acmd =
"scp -p " + sqliteFileName +
".tar.bz2" +
" webcondvm.cern.ch:" + dropbox
972 outcmd = commands.getstatusoutput(acmd)
975 print "Couldn't scp the files to DropBox!"
979 acmd =
"mv " + sqliteFileName +
".tar.bz2 " + sqliteFileDirName
981 outcmd = commands.getstatusoutput(acmd)
984 print "Couldn't mv the file to " + sqliteFileDirName
987 acmd =
"rm " + sqliteFileName +
".db " + sqliteFileName +
".txt"
989 outcmd = commands.getstatusoutput(acmd)
992 print "Couldn't rm the db and txt files"
def sendEmail
General utilities.
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
def createWeightedPayloads
CREATE FILE FOR PAYLOADS.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
def createWeightedPayloadsNew
def pack
lumi tools CondCore/Utilities/python/timeUnitHelper.py
return(e1-e2)*(e1-e2)+dp *dp
def sortAndCleanBeamList
Sort and clean list of data for consecutive duplicates and bad fits.
def cmp_list_run
end lumi tools