1 import math, re, optparse, commands, os, sys, time, datetime
2 from BeamSpotObj
import BeamSpot
12 timeFormat =
"%a,%Y/%m/%d,%H:%M:%S" 13 currentTime = time.gmtime()
14 timeoutLine = type +
' ' + time.strftime(timeFormat, currentTime) +
'\n' 18 fileExist = os.path.isfile(fileName)
28 fields = line.strip(
'\n').
split(
' ')
32 text = text.replace(line,
'')
35 fileTime = time.strptime(fields[1],timeFormat)
36 myTime = time.mktime(fileTime)
37 referenceTime = time.mktime(time.gmtime())
39 if currentTime.tm_isdst == 0:
41 elapsedTime = referenceTime-myTime-daylight
42 if elapsedTime > timeout:
45 print "Timeout! " +
str(elapsedTime) +
" seconds passed since the " + type +
" timeout was set and you can't tolerate more than " +
str(timeout) +
" seconds!" 48 print "Timeout of type " + type +
" already exist and was generated " +
str(elapsedTime) +
" seconds ago at " + fields[1]
52 if not fileExist
or not alreadyThere
and not reset:
56 if not fileExist
or not alreadyThere
or isTimeout
or (reset
and alreadyThere):
58 commands.getstatusoutput(
"rm -rf " + fileName)
59 file = open(fileName,
'w')
74 if os.path.isfile(lockFile):
82 commands.getstatusoutput(
"touch " + lockFile)
88 commands.getstatusoutput(
"rm " + lockFile)
93 raise SystemExit(msg
or optionstring.replace(
"%prog",sys.argv[0]))
103 USAGE = re.compile(
r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
109 optionstring = docstring
110 match = USAGE.search(optionstring)
111 if not match:
raise ParsingError(
"Cannot find the option string")
112 optlines = match.group(1).splitlines()
114 p = optparse.OptionParser(optlines[0])
115 for line
in optlines[1:]:
116 opt, help=line.split(
':')[:2]
117 short,long=opt.split(
',')[:2]
120 long=long.split(
'=')[0]
123 p.add_option(short.strip(),long.strip(),
124 action = action, help = help.strip())
125 except (IndexError,ValueError):
126 raise ParsingError(
"Cannot parse the option string correctly")
127 return p.parse_args(arglist)
131 "True if options were given" 132 for v
in six.itervalues(self.__dict__):
133 if v
is not None:
return True 137 optparse.Values.__nonzero__ = nonzero
150 print "Sending email to " + mailList +
" with body: " + error
151 list = mailList.split(
',')
153 p = os.popen(
"mail -s \"Automatic workflow error\" " + email ,
"w")
159 if dir.find(
"castor") != -1:
160 lsCommand =
"nsls " + dir
161 output = commands.getstatusoutput( lsCommand )
164 return os.path.exists(dir)
167 def ls(dir,filter=""):
170 if dir.find(
'castor') != -1:
172 elif not os.path.exists(dir):
173 print "ERROR: File or directory " + dir +
" doesn't exist" 176 aCommand = lsCommand +
'ls '+ dir
179 aCommand +=
" | grep " + filter
181 tmpStatus = commands.getstatusoutput( aCommand )
182 listOfFiles = tmpStatus[1].
split(
'\n')
183 if len(listOfFiles) == 1:
184 if listOfFiles[0].
find(
'No such file or directory') != -1:
185 exit(
"ERROR: File or directory " + dir +
" doesn't exist")
190 def cp(fromDir,toDir,listOfFiles,overwrite=False,smallList=False):
193 if fromDir.find(
'castor') != -1
or toDir.find(
'castor') != -1 :
195 elif fromDir.find(
'resilient') != -1:
197 if fromDir[len(fromDir)-1] !=
'/':
200 if toDir[len(toDir)-1] !=
'/':
203 for file
in listOfFiles:
204 if os.path.isfile(toDir+file):
206 print "File " + file +
" already exists in destination directory. We will overwrite it." 208 print "File " + file +
" already exists in destination directory. We will Keep original file." 210 copiedFiles.append(file)
213 aCommand = cpCommand +
'cp '+ fromDir + file +
" " + toDir
214 print " >> " + aCommand
215 tmpStatus = commands.getstatusoutput( aCommand )
216 if tmpStatus[0] == 0:
217 copiedFiles.append(file)
219 print "[cp()]\tERROR: Can't copy file " + file
229 """pack high,low 32bit unsigned int to one unsigned 64bit long long 230 Note:the print value of result number may appear signed, if the sign bit is used. 237 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low) 245 """unpack 64bit lumiid to dictionary {'run','lumisection'} 248 return {
'run':j[0],
'lumisection':j[1]}
255 if int(a.IOVfirst) <
int(b.IOVfirst):
return -1
256 if int(a.IOVfirst) ==
int(b.IOVfirst):
return 0
257 if int(a.IOVfirst) >
int(b.IOVfirst):
return 1
261 if int(a.Run) <
int(b.Run):
return -1
262 if int(a.Run) ==
int(b.Run):
263 if int(a.IOVfirst) <
int(b.IOVfirst):
return -1
264 if int(a.IOVfirst) ==
int(b.IOVfirst):
return 0
265 if int(a.IOVfirst) >
int(b.IOVfirst):
return 1
266 if int(a.Run) >
int(b.Run) :
return 1
279 x1 = x2/(x2err * x2err)
280 tmperr = 1/(x2err*x2err)
282 x1 = x1/(x1err*x1err) + x2/(x2err * x2err)
283 tmperr = 1/(x1err*x1err) + 1/(x2err*x2err)
286 x1err = math.sqrt(x1err)
287 return (
str(x1),
str(x1err))
292 file.write(
"Runnumber "+beam.Run+end)
293 file.write(
"BeginTimeOfFit "+
str(beam.IOVBeginTime)+end)
294 file.write(
"EndTimeOfFit "+
str(beam.IOVEndTime)+end)
295 file.write(
"LumiRange "+
str(beam.IOVfirst)+
" - "+
str(beam.IOVlast)+end)
301 file.write(
"Type "+
str(beam.Type)+end)
302 file.write(
"X0 "+
str(beam.X)+end)
303 file.write(
"Y0 "+
str(beam.Y)+end)
304 file.write(
"Z0 "+
str(beam.Z)+end)
305 file.write(
"sigmaZ0 "+
str(beam.sigmaZ)+end)
306 file.write(
"dxdz "+
str(beam.dxdz)+end)
307 file.write(
"dydz "+
str(beam.dydz)+end)
308 file.write(
"BeamWidthX "+beam.beamWidthX+end)
309 file.write(
"BeamWidthY "+beam.beamWidthY+end)
310 file.write(
"Cov(0,j) "+
str(math.pow(
float(beam.Xerr),2))+
" 0 0 0 0 0 0" +end)
311 file.write(
"Cov(1,j) 0 "+
str(math.pow(
float(beam.Yerr),2))+
" 0 0 0 0 0" +end)
312 file.write(
"Cov(2,j) 0 0 "+
str(math.pow(
float(beam.Zerr),2))+
" 0 0 0 0" +end)
313 file.write(
"Cov(3,j) 0 0 0 "+
str(math.pow(
float(beam.sigmaZerr),2))+
" 0 0 0" +end)
314 file.write(
"Cov(4,j) 0 0 0 0 "+
str(math.pow(
float(beam.dxdzerr),2))+
" 0 0" +end)
315 file.write(
"Cov(5,j) 0 0 0 0 0 "+
str(math.pow(
float(beam.dydzerr),2))+
" 0" +end)
316 file.write(
"Cov(6,j) 0 0 0 0 0 0 "+
str(math.pow(
float(beam.beamWidthXerr),2)) +end)
317 file.write(
"EmittanceX 0"+end)
318 file.write(
"EmittanceY 0"+end)
319 file.write(
"BetaStar 0"+end)
324 return (
float(x) -
float(nextx), math.sqrt(math.pow(
float(xerr),2) + math.pow(
float(nextxerr),2)) )
327 return math.fabs(x[0])/x[1]
330 def readBeamSpotFile(fileName,listbeam=[],IOVbase="runbase", firstRun='1',lastRun='4999999999'):
336 if IOVbase ==
"lumibase" and firstRun==
'1' and lastRun==
'4999999999' :
338 lastRun =
"4999999999:4999999999" 348 tmpfile = open(fileName)
349 atmpline = tmpfile.readline()
350 if atmpline.find(
'Runnumber') != -1:
352 if len(atmpline.split()) > 2:
354 print " Input data has been calculated as function of BUNCH CROSSINGS." 358 if inputfiletype ==1:
363 if line.find(
'Type') != -1:
364 tmpbeam.Type =
int(line.split()[1])
366 if line.find(
'X0') != -1:
367 tmpbeam.X = line.split()[1]
371 if line.find(
'Y0') != -1:
372 tmpbeam.Y = line.split()[1]
376 if line.find(
'Z0') != -1
and line.find(
'sigmaZ0') == -1:
377 tmpbeam.Z = line.split()[1]
380 if line.find(
'sigmaZ0') !=-1:
381 tmpbeam.sigmaZ = line.split()[1]
384 if line.find(
'dxdz') != -1:
385 tmpbeam.dxdz = line.split()[1]
388 if line.find(
'dydz') != -1:
389 tmpbeam.dydz = line.split()[1]
392 if line.find(
'BeamWidthX') != -1:
393 tmpbeam.beamWidthX = line.split()[1]
396 if line.find(
'BeamWidthY') != -1:
397 tmpbeam.beamWidthY = line.split()[1]
400 if line.find(
'Cov(0,j)') != -1:
401 tmpbeam.Xerr =
str(math.sqrt(
float( line.split()[1] ) ) )
403 if line.find(
'Cov(1,j)') != -1:
404 tmpbeam.Yerr =
str(math.sqrt(
float( line.split()[2] ) ) )
406 if line.find(
'Cov(2,j)') != -1:
407 tmpbeam.Zerr =
str(math.sqrt(
float( line.split()[3] ) ) )
409 if line.find(
'Cov(3,j)') != -1:
410 tmpbeam.sigmaZerr =
str(math.sqrt(
float( line.split()[4] ) ) )
412 if line.find(
'Cov(4,j)') != -1:
413 tmpbeam.dxdzerr =
str(math.sqrt(
float( line.split()[5] ) ) )
415 if line.find(
'Cov(5,j)') != -1:
416 tmpbeam.dydzerr =
str(math.sqrt(
float( line.split()[6] ) ) )
418 if line.find(
'Cov(6,j)') != -1:
419 tmpbeam.beamWidthXerr =
str(math.sqrt(
float( line.split()[7] ) ) )
420 tmpbeam.beamWidthYerr = tmpbeam.beamWidthXerr
422 if line.find(
'LumiRange') != -1:
423 if IOVbase==
"lumibase":
424 tmpbeam.IOVfirst = line.split()[1]
425 tmpbeam.IOVlast = line.split()[3]
427 if line.find(
'Runnumber') != -1:
428 tmpbeam.Run = line.split()[1]
429 if IOVbase ==
"runbase":
430 tmpbeam.IOVfirst = line.split()[1]
431 tmpbeam.IOVlast = line.split()[1]
433 tmpBX = line.split()[3]
435 if line.find(
'BeginTimeOfFit') != -1:
436 tmpbeam.IOVBeginTime = line.split()[1] +
" "+line.split()[2] +
" "+line.split()[3]
437 if IOVbase ==
"timebase":
438 tmpbeam.IOVfirst = time.mktime( time.strptime(line.split()[1] +
" " + line.split()[2] +
" " + line.split()[3],
"%Y.%m.%d %H:%M:%S %Z") )
440 if line.find(
'EndTimeOfFit') != -1:
441 tmpbeam.IOVEndTime = line.split()[1] +
" "+line.split()[2] +
" "+line.split()[3]
442 if IOVbase ==
"timebase":
443 tmpbeam.IOVlast = time.mktime( time.strptime(line.split()[1] +
" " + line.split()[2] +
" " + line.split()[3],
"%Y.%m.%d %H:%M:%S %Z") )
445 if tmpbeamsize == 20:
446 if IOVbase==
"lumibase":
447 tmprunfirst =
int(firstRun.split(
":")[0])
448 tmprunlast =
int(lastRun.split(
":")[0])
449 tmplumifirst =
int(firstRun.split(
":")[1])
450 tmplumilast =
int(lastRun.split(
":")[1])
451 acceptiov1 = acceptiov2 =
False 453 if tmprunfirst == tmprunlast
and int(tmpbeam.Run)==tmprunfirst:
454 if int(tmpbeam.IOVfirst) >= tmplumifirst
and int(tmpbeam.IOVlast)<=tmplumilast:
455 acceptiov1 = acceptiov2 =
True 457 elif int(tmpbeam.Run) == tmprunfirst:
458 if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 =
True 459 elif int(tmpbeam.Run) == tmprunlast:
460 if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 =
True 461 elif tmprunfirst <=
int(tmpbeam.Run)
and tmprunlast >=
int(tmpbeam.Run):
462 acceptiov1 = acceptiov2 =
True 464 if acceptiov1
and acceptiov2:
465 if tmpbeam.Type != 2:
466 print "invalid fit, skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast)
467 elif isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
468 print "invalid fit, NaN values!! skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast)
470 if (tmpBX
in maplist) ==
False:
471 maplist[tmpBX] = [tmpbeam]
473 maplist[tmpBX].
append(tmpbeam)
475 listbeam.append(tmpbeam)
477 elif int(tmpbeam.IOVfirst) >=
int(firstRun)
and int(tmpbeam.IOVlast) <=
int(lastRun):
478 if tmpbeam.Type != 2:
479 print "invalid fit, skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast)
480 elif isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
481 print "invalid fit, NaN values!! skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast)
483 listbeam.append(tmpbeam)
492 if line.find(
'X0') != -1:
493 tmpbeam.X = line.split()[2]
494 tmpbeam.Xerr = line.split()[4]
497 if line.find(
'Y0') != -1:
498 tmpbeam.Y = line.split()[2]
499 tmpbeam.Yerr = line.split()[4]
502 if line.find(
'Z0') != -1
and line.find(
'Sigma Z0') == -1:
503 tmpbeam.Z = line.split()[2]
504 tmpbeam.Zerr = line.split()[4]
507 if line.find(
'Sigma Z0') !=-1:
508 tmpbeam.sigmaZ = line.split()[3]
509 tmpbeam.sigmaZerr = line.split()[5]
511 if line.find(
'dxdz') != -1:
512 tmpbeam.dxdz = line.split()[2]
513 tmpbeam.dxdzerr = line.split()[4]
515 if line.find(
'dydz') != -1:
516 tmpbeam.dydz = line.split()[2]
517 tmpbeam.dydzerr = line.split()[4]
519 if line.find(
'Beam Width X') != -1:
520 tmpbeam.beamWidthX = line.split()[4]
521 tmpbeam.beamWidthXerr = line.split()[6]
523 if line.find(
'Beam Width Y') != -1:
524 tmpbeam.beamWidthY = line.split()[4]
525 tmpbeam.beamWidthYerr = line.split()[6]
528 if line.find(
'for runs') != -1:
530 tmpbeam.Run = line.split()[2]
531 if IOVbase ==
"runbase":
532 tmpbeam.IOVfirst = line.split()[2]
533 tmpbeam.IOVlast = line.split()[4]
535 if line.find(
'LumiSection') != -1:
536 if IOVbase==
"lumibase":
537 tmpbeam.IOVfirst = line.split()[10]
538 tmpbeam.IOVlast = line.split()[10]
540 if tmpbeamsize == 10:
542 if IOVbase==
"lumibase":
543 tmprunfirst =
int(firstRun.split(
":")[0])
544 tmprunlast =
int(lastRun.split(
":")[0])
545 tmplumifirst =
int(firstRun.split(
":")[1])
546 tmplumilast =
int(lastRun.split(
":")[1])
547 acceptiov1 = acceptiov2 =
False 549 if tmprunfirst == tmprunlast
and int(tmpbeam.Run)==tmprunfirst:
550 if int(tmpbeam.IOVfirst) >= tmplumifirst
and int(tmpbeam.IOVlast)<=tmplumilast:
551 acceptiov1 = acceptiov2 =
True 553 elif int(tmpbeam.Run) == tmprunfirst:
554 if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 =
True 555 elif int(tmpbeam.Run) == tmprunlast:
556 if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 =
True 557 elif tmprunfirst <=
int(tmpbeam.Run)
and tmprunlast >=
int(tmpbeam.Run):
558 acceptiov1 = acceptiov2 =
True 560 if acceptiov1
and acceptiov2:
561 if isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
562 print "invalid fit, NaN values!! skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast)
564 if (tmpBX
in maplist) ==
False:
565 maplist[tmpBX] = [tmpbeam]
567 maplist[tmpBX].
append(tmpbeam)
569 listbeam.append(tmpbeam)
571 elif int(tmpbeam.IOVfirst) >=
int(firstRun)
and int(tmpbeam.IOVlast) <=
int(lastRun):
572 if isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
573 print "invalid fit, NaN values!! skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast)
575 listbeam.append(tmpbeam)
582 print " got total number of IOVs = " +
str(len(listbeam)) +
" from file " + fileName
593 if IOVbase ==
"lumibase":
594 listbeam.sort( cmp = cmp_list_lumi )
596 listbeam.sort( cmp = cmp_list_run )
600 for ii
in range(0,len(listbeam)):
602 datax = ibeam.IOVfirst
604 if datax ==
'0' and IOVbase ==
"runbase":
605 print " iov = 0? skip this IOV = "+
str(ibeam.IOVfirst) +
" to " +
str(ibeam.IOVlast)
606 tmpremovelist.append(ibeam)
608 if ii < len(listbeam) -1:
610 if IOVbase ==
"lumibase":
611 if ibeam.Run == listbeam[ii+1].Run
and ibeam.IOVfirst == listbeam[ii+1].IOVfirst:
612 print " duplicate IOV = "+datax+
", keep only last duplicate entry" 613 tmpremovelist.append(ibeam)
614 elif datax == listbeam[ii+1].IOVfirst:
615 print " duplicate IOV = "+datax+
", keep only last duplicate entry" 616 tmpremovelist.append(ibeam)
618 for itmp
in tmpremovelist:
619 listbeam.remove(itmp)
631 maxNlumis = 999999999
632 for ii
in range(0,len(listbeam)):
637 tmpbeam.IOVfirst = ibeam.IOVfirst
638 tmpbeam.IOVBeginTime = ibeam.IOVBeginTime
639 tmpbeam.Run = ibeam.Run
646 if ii < len(listbeam) - 1:
647 inextbeam = listbeam[ii+1]
649 if ii < len(listbeam) -2:
650 iNNbeam = listbeam[ii+2]
652 print "close payload because end of data has been reached. Run "+ibeam.Run
655 if ibeam.Run != inextbeam.Run:
656 print "close payload because end of run "+ibeam.Run
659 if countlumi == maxNlumis -1:
660 print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
664 (tmpbeam.X, tmpbeam.Xerr) =
weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
665 (tmpbeam.Y, tmpbeam.Yerr) =
weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
666 (tmpbeam.Z, tmpbeam.Zerr) =
weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
667 (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) =
weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
668 (tmpbeam.dxdz, tmpbeam.dxdzerr) =
weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
669 (tmpbeam.dydz, tmpbeam.dydzerr) =
weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
671 (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) =
weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
672 (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) =
weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
684 limit =
float(ibeam.beamWidthX)/2.
685 if limit < min_limit: limit = min_limit
688 adelta1 =
delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr)
690 adelta1dxdz =
delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
691 adelta2dxdz = (0.,1.e9)
692 adelta1dydz =
delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
693 adelta2dydz = (0.,1.e9)
694 adelta1widthx =
delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
695 adelta2widthx = (0.,1.e9)
696 adelta1widthy =
delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
697 adelta2widthy = (0.,1.e9)
698 adelta1z0 =
delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr)
699 adelta1sigmaZ =
delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr)
701 if iNNbeam.Type != -1:
702 adelta2 =
delta(inextbeam.X, inextbeam.Xerr, iNNbeam.X, iNNbeam.Xerr)
703 adelta2dxdz =
delta(inextbeam.dxdz, inextbeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr)
704 adelta2dydz =
delta(inextbeam.dydz, inextbeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr)
705 adelta2widthx =
delta(inextbeam.beamWidthX, inextbeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr)
706 adelta2widthy =
delta(inextbeam.beamWidthY, inextbeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr)
708 deltaX =
deltaSig(adelta1) > 3.5
and adelta1[0] >= limit
709 if ii < len(listbeam) -2:
710 if deltaX==
False and adelta1[0]*adelta2[0] > 0.
and math.fabs(adelta1[0]+adelta2[0]) >= limit:
713 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:
720 adelta1 =
delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr)
722 if iNNbeam.Type != -1:
723 adelta2 =
delta(inextbeam.Y, inextbeam.Yerr, iNNbeam.Y, iNNbeam.Yerr)
725 deltaY =
deltaSig(adelta1) > 3.5
and adelta1[0] >= limit
726 if ii < len(listbeam) -2:
727 if deltaY==
False and adelta1[0]*adelta2[0] > 0.
and math.fabs(adelta1[0]+adelta2[0]) >= limit:
729 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:
733 limit =
float(ibeam.sigmaZ)/2.
734 deltaZ =
deltaSig(adelta1z0) > 3.5
and math.fabs(adelta1z0[0]) >= limit
736 deltasigmaZ =
deltaSig(adelta1sigmaZ) > 5.0
739 adelta =
delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
741 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:
744 adelta =
delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
746 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:
749 adelta =
delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
751 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:
754 adelta =
delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
756 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:
770 if deltaX
or deltaY
or deltaZ
or deltasigmaZ
or deltadxdz
or deltadydz
or deltawidthX
or deltawidthY:
778 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)
781 tmpbeam.IOVlast = ibeam.IOVlast
782 tmpbeam.IOVEndTime = ibeam.IOVEndTime
783 print " Run: "+tmpbeam.Run +
" Lumi1: "+
str(tmpbeam.IOVfirst) +
" Lumi2: "+
str(tmpbeam.IOVlast)
784 newlistbeam.append(tmpbeam)
790 payloadfile = open(fileName,
"w")
791 for iload
in newlistbeam:
792 dump( iload, payloadfile )
800 lastPayload = listbeam[0]
804 for ii
in range(0,len(listbeam)):
807 deltaX =
delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr) > 1.5
808 deltaY =
delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr) > 1.5
809 deltaZ =
delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr) > 2.5
811 deltasigmaZ =
delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr) > 2.5
812 deltadxdz =
delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr) > 2.5
813 deltadydz =
delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr) > 2.5
815 deltawidthX =
delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr) > 3
816 deltawidthY =
delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr) > 3
830 if deltaX
or deltaY
or deltaZ
or deltasigmaZ
or deltadxdz
or deltadydz
or deltawidthX
or deltawidthY:
840 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)
843 if ii >= len(listbeam) - 1
or listbeam[ii].Run != listbeam[ii+1].Run :
844 print "close payload because end of run has been reached. Run " + listbeam[ii].Run
856 for ibeam
in listbeam[firstToUse:lastToUse]:
857 (tmpbeam.X, tmpbeam.Xerr) =
weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
858 (tmpbeam.Y, tmpbeam.Yerr) =
weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
859 (tmpbeam.Z, tmpbeam.Zerr) =
weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
860 (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) =
weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
861 (tmpbeam.dxdz, tmpbeam.dxdzerr) =
weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
862 (tmpbeam.dydz, tmpbeam.dydzerr) =
weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
864 (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) =
weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
865 (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) =
weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
866 tmpbeam.IOVfirst = listbeam[firstToUse].IOVfirst
867 tmpbeam.IOVBeginTime = listbeam[firstToUse].IOVBeginTime
868 tmpbeam.Run = listbeam[firstToUse].Run
870 tmpbeam.IOVlast = listbeam[lastToUse].IOVlast
871 tmpbeam.IOVEndTime = listbeam[lastToUse].IOVEndTime
872 newlistbeam.append(tmpbeam)
873 firstToUse = lastToUse+1
874 print "Run: " + tmpbeam.Run +
" Lumi1: " +
str(tmpbeam.IOVfirst) +
" Lumi2: " +
str(tmpbeam.IOVlast)
876 payloadfile = open(fileName,
"w")
877 for iload
in newlistbeam:
878 dump( iload, payloadfile )
882 def writeSqliteFile(sqliteFileName,tagName,timeType,beamSpotFile,sqliteTemplateFile,tmpDir="/tmp/"):
883 writeDBOut = tmpDir +
"write2DB_" + tagName +
".py" 884 wFile = open(sqliteTemplateFile)
885 wNewFile = open(writeDBOut,
'w')
887 writeDBTags = [(
'SQLITEFILE',
'sqlite_file:' + sqliteFileName),
889 (
'TIMETYPE',timeType),
890 (
'BEAMSPOTFILE',beamSpotFile)]
893 for itag
in writeDBTags:
894 line = line.replace(itag[0],itag[1])
898 print "writing sqlite file ..." 899 status_wDB = commands.getstatusoutput(
'cmsRun '+ writeDBOut)
902 os.system(
"rm -f " + writeDBOut)
903 return not status_wDB[0]
907 readDBOut = tmpDir +
"readDB_" + tagName +
".py" 909 rFile = open(sqliteTemplateFile)
910 rNewFile = open(readDBOut,
'w')
912 readDBTags = [(
'SQLITEFILE',
'sqlite_file:' + sqliteFileName),
916 for itag
in readDBTags:
917 line = line.replace(itag[0],itag[1])
921 status_rDB = commands.getstatusoutput(
'cmsRun '+ readDBOut)
923 outtext = status_rDB[1]
925 os.system(
"rm -f " + readDBOut)
926 return not status_rDB[0]
929 def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill ,tmpDir="/tmp/"):
930 aCommand =
"conddb_import -c sqlite_file:" + tmpDir + combinedSqliteFileName +
" -f sqlite_file:" + sqliteFileName +
" -i " + tagName +
" -t " + tagName +
" -b " + IOVSince +
" -e " + IOVTill
932 std = commands.getstatusoutput(aCommand)
939 acmd =
"chmod a+w " + sqliteFileDirName + sqliteFileName +
".txt" 940 outcmd = commands.getstatusoutput(acmd)
944 print "Can't change permission to file: " + sqliteFileDirName + sqliteFileName +
".txt" 947 acmd =
"cp " + sqliteFileDirName + sqliteFileName +
".db " + sqliteFileDirName + sqliteFileName +
".txt ." 949 outcmd = commands.getstatusoutput(acmd)
952 print "Couldn't cd to " + sqliteFileDirName
955 acmd =
"tar -cvjf " + sqliteFileName +
".tar.bz2 " + sqliteFileName +
".db " + sqliteFileName +
".txt" 957 outcmd = commands.getstatusoutput(acmd)
960 print "Couldn't zip the files!" 963 acmd =
"chmod a+w " + sqliteFileName +
".tar.bz2" 964 outcmd = commands.getstatusoutput(acmd)
968 print "Can't change permission to file: " + sqliteFileDirName + sqliteFileName +
".tar.bz2" 971 acmd =
"scp -p " + sqliteFileName +
".tar.bz2" +
" webcondvm.cern.ch:" + dropbox
973 outcmd = commands.getstatusoutput(acmd)
976 print "Couldn't scp the files to DropBox!" 980 acmd =
"mv " + sqliteFileName +
".tar.bz2 " + sqliteFileDirName
982 outcmd = commands.getstatusoutput(acmd)
985 print "Couldn't mv the file to " + sqliteFileDirName
988 acmd =
"rm " + sqliteFileName +
".db " + sqliteFileName +
".txt" 990 outcmd = commands.getstatusoutput(acmd)
993 print "Couldn't rm the db and txt files"
def readBeamSpotFile(fileName, listbeam=[], IOVbase="runbase", firstRun='1', lastRun='4999999999')
def dumpValues(beam, file)
def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill, tmpDir="/tmp/")
def cmp_list_run(a, b)
end lumi tools
def createWeightedPayloads(fileName, listbeam=[], weighted=True)
CREATE FILE FOR PAYLOADS.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
def uploadSqliteFile(sqliteFileDirName, sqliteFileName, dropbox="/DropBox")
def weight(x1, x1err, x2, x2err)
def parse(docstring, arglist=None)
def sortAndCleanBeamList(listbeam=[], IOVbase="lumibase")
Sort and clean list of data for consecutive duplicates and bad fits.
def readSqliteFile(sqliteFileName, tagName, sqliteTemplateFile, tmpDir="/tmp/")
def delta(x, xerr, nextx, nextxerr)
def timeoutManager(type, timeout=-1, fileName=".timeout")
def writeSqliteFile(sqliteFileName, tagName, timeType, beamSpotFile, sqliteTemplateFile, tmpDir="/tmp/")
def sendEmail(mailList, error)
General utilities.
def pack(high, low)
lumi tools CondCore/Utilities/python/timeUnitHelper.py
def createWeightedPayloadsNew(fileName, listbeam=[], weighted=True)
def cp(fromDir, toDir, listOfFiles, overwrite=False, smallList=False)