1 from __future__
import print_function
2 from builtins
import range
3 import math, re, optparse, commands, os, sys, time, datetime
4 from BeamSpotObj
import BeamSpot
14 timeFormat =
"%a,%Y/%m/%d,%H:%M:%S" 15 currentTime = time.gmtime()
16 timeoutLine = type +
' ' + time.strftime(timeFormat, currentTime) +
'\n' 20 fileExist = os.path.isfile(fileName)
30 fields = line.strip(
'\n').
split(
' ')
34 text = text.replace(line,
'')
37 fileTime = time.strptime(fields[1],timeFormat)
38 myTime = time.mktime(fileTime)
39 referenceTime = time.mktime(time.gmtime())
41 if currentTime.tm_isdst == 0:
43 elapsedTime = referenceTime-myTime-daylight
44 if elapsedTime > timeout:
47 print(
"Timeout! " +
str(elapsedTime) +
" seconds passed since the " + type +
" timeout was set and you can't tolerate more than " +
str(timeout) +
" seconds!")
50 print(
"Timeout of type " + type +
" already exist and was generated " +
str(elapsedTime) +
" seconds ago at " + fields[1])
54 if not fileExist
or not alreadyThere
and not reset:
58 if not fileExist
or not alreadyThere
or isTimeout
or (reset
and alreadyThere):
60 commands.getstatusoutput(
"rm -rf " + fileName)
61 file = open(fileName,
'w')
76 if os.path.isfile(lockFile):
84 commands.getstatusoutput(
"touch " + lockFile)
90 commands.getstatusoutput(
"rm " + lockFile)
95 raise SystemExit(msg
or optionstring.replace(
"%prog",sys.argv[0]))
105 USAGE = re.compile(
r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
111 optionstring = docstring
112 match = USAGE.search(optionstring)
113 if not match:
raise ParsingError(
"Cannot find the option string")
114 optlines = match.group(1).splitlines()
116 p = optparse.OptionParser(optlines[0])
117 for line
in optlines[1:]:
118 opt, help=line.split(
':')[:2]
119 short,long=opt.split(
',')[:2]
122 long=long.split(
'=')[0]
125 p.add_option(short.strip(),long.strip(),
126 action = action, help = help.strip())
127 except (IndexError,ValueError):
128 raise ParsingError(
"Cannot parse the option string correctly")
129 return p.parse_args(arglist)
133 "True if options were given" 134 for v
in six.itervalues(self.__dict__):
135 if v
is not None:
return True 139 optparse.Values.__nonzero__ = nonzero
152 print(
"Sending email to " + mailList +
" with body: " + error)
153 list = mailList.split(
',')
155 p = os.popen(
"mail -s \"Automatic workflow error\" " + email ,
"w")
161 if dir.find(
"castor") != -1:
162 lsCommand =
"nsls " + dir
163 output = commands.getstatusoutput( lsCommand )
166 return os.path.exists(dir)
169 def ls(dir,filter=""):
172 if dir.find(
'castor') != -1:
174 elif not os.path.exists(dir):
175 print(
"ERROR: File or directory " + dir +
" doesn't exist")
178 aCommand = lsCommand +
'ls '+ dir
181 aCommand +=
" | grep " + filter
183 tmpStatus = commands.getstatusoutput( aCommand )
184 listOfFiles = tmpStatus[1].
split(
'\n')
185 if len(listOfFiles) == 1:
186 if listOfFiles[0].
find(
'No such file or directory') != -1:
187 exit(
"ERROR: File or directory " + dir +
" doesn't exist")
192 def cp(fromDir,toDir,listOfFiles,overwrite=False,smallList=False):
195 if fromDir.find(
'castor') != -1
or toDir.find(
'castor') != -1 :
197 elif fromDir.find(
'resilient') != -1:
199 if fromDir[len(fromDir)-1] !=
'/':
202 if toDir[len(toDir)-1] !=
'/':
205 for file
in listOfFiles:
206 if os.path.isfile(toDir+file):
208 print(
"File " + file +
" already exists in destination directory. We will overwrite it.")
210 print(
"File " + file +
" already exists in destination directory. We will Keep original file.")
212 copiedFiles.append(file)
215 aCommand = cpCommand +
'cp '+ fromDir + file +
" " + toDir
216 print(
" >> " + aCommand)
217 tmpStatus = commands.getstatusoutput( aCommand )
218 if tmpStatus[0] == 0:
219 copiedFiles.append(file)
221 print(
"[cp()]\tERROR: Can't copy file " + file)
231 """pack high,low 32bit unsigned int to one unsigned 64bit long long 232 Note:the print value of result number may appear signed, if the sign bit is used. 239 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low) 247 """unpack 64bit lumiid to dictionary {'run','lumisection'} 250 return {
'run':j[0],
'lumisection':j[1]}
257 if int(a.IOVfirst) <
int(b.IOVfirst):
return -1
258 if int(a.IOVfirst) ==
int(b.IOVfirst):
return 0
259 if int(a.IOVfirst) >
int(b.IOVfirst):
return 1
263 if int(a.Run) <
int(b.Run):
return -1
264 if int(a.Run) ==
int(b.Run):
265 if int(a.IOVfirst) <
int(b.IOVfirst):
return -1
266 if int(a.IOVfirst) ==
int(b.IOVfirst):
return 0
267 if int(a.IOVfirst) >
int(b.IOVfirst):
return 1
268 if int(a.Run) >
int(b.Run) :
return 1
281 x1 = x2/(x2err * x2err)
282 tmperr = 1/(x2err*x2err)
284 x1 = x1/(x1err*x1err) + x2/(x2err * x2err)
285 tmperr = 1/(x1err*x1err) + 1/(x2err*x2err)
288 x1err = math.sqrt(x1err)
289 return (
str(x1),
str(x1err))
294 file.write(
"Runnumber "+beam.Run+end)
295 file.write(
"BeginTimeOfFit "+
str(beam.IOVBeginTime)+end)
296 file.write(
"EndTimeOfFit "+
str(beam.IOVEndTime)+end)
297 file.write(
"LumiRange "+
str(beam.IOVfirst)+
" - "+
str(beam.IOVlast)+end)
303 file.write(
"Type "+
str(beam.Type)+end)
304 file.write(
"X0 "+
str(beam.X)+end)
305 file.write(
"Y0 "+
str(beam.Y)+end)
306 file.write(
"Z0 "+
str(beam.Z)+end)
307 file.write(
"sigmaZ0 "+
str(beam.sigmaZ)+end)
308 file.write(
"dxdz "+
str(beam.dxdz)+end)
309 file.write(
"dydz "+
str(beam.dydz)+end)
310 file.write(
"BeamWidthX "+beam.beamWidthX+end)
311 file.write(
"BeamWidthY "+beam.beamWidthY+end)
312 file.write(
"Cov(0,j) "+
str(math.pow(
float(beam.Xerr),2))+
" 0 0 0 0 0 0" +end)
313 file.write(
"Cov(1,j) 0 "+
str(math.pow(
float(beam.Yerr),2))+
" 0 0 0 0 0" +end)
314 file.write(
"Cov(2,j) 0 0 "+
str(math.pow(
float(beam.Zerr),2))+
" 0 0 0 0" +end)
315 file.write(
"Cov(3,j) 0 0 0 "+
str(math.pow(
float(beam.sigmaZerr),2))+
" 0 0 0" +end)
316 file.write(
"Cov(4,j) 0 0 0 0 "+
str(math.pow(
float(beam.dxdzerr),2))+
" 0 0" +end)
317 file.write(
"Cov(5,j) 0 0 0 0 0 "+
str(math.pow(
float(beam.dydzerr),2))+
" 0" +end)
318 file.write(
"Cov(6,j) 0 0 0 0 0 0 "+
str(math.pow(
float(beam.beamWidthXerr),2)) +end)
319 file.write(
"EmittanceX 0"+end)
320 file.write(
"EmittanceY 0"+end)
321 file.write(
"BetaStar 0"+end)
326 return (
float(x) -
float(nextx), math.sqrt(math.pow(
float(xerr),2) + math.pow(
float(nextxerr),2)) )
329 return math.fabs(x[0])/x[1]
332 def readBeamSpotFile(fileName,listbeam=[],IOVbase="runbase", firstRun='1',lastRun='4999999999'):
338 if IOVbase ==
"lumibase" and firstRun==
'1' and lastRun==
'4999999999' :
340 lastRun =
"4999999999:4999999999" 350 tmpfile = open(fileName)
351 atmpline = tmpfile.readline()
352 if atmpline.find(
'Runnumber') != -1:
354 if len(atmpline.split()) > 2:
356 print(
" Input data has been calculated as function of BUNCH CROSSINGS.")
360 if inputfiletype ==1:
365 if line.find(
'Type') != -1:
366 tmpbeam.Type =
int(line.split()[1])
368 if line.find(
'X0') != -1:
369 tmpbeam.X = line.split()[1]
373 if line.find(
'Y0') != -1:
374 tmpbeam.Y = line.split()[1]
378 if line.find(
'Z0') != -1
and line.find(
'sigmaZ0') == -1:
379 tmpbeam.Z = line.split()[1]
382 if line.find(
'sigmaZ0') !=-1:
383 tmpbeam.sigmaZ = line.split()[1]
386 if line.find(
'dxdz') != -1:
387 tmpbeam.dxdz = line.split()[1]
390 if line.find(
'dydz') != -1:
391 tmpbeam.dydz = line.split()[1]
394 if line.find(
'BeamWidthX') != -1:
395 tmpbeam.beamWidthX = line.split()[1]
398 if line.find(
'BeamWidthY') != -1:
399 tmpbeam.beamWidthY = line.split()[1]
402 if line.find(
'Cov(0,j)') != -1:
403 tmpbeam.Xerr =
str(math.sqrt(
float( line.split()[1] ) ) )
405 if line.find(
'Cov(1,j)') != -1:
406 tmpbeam.Yerr =
str(math.sqrt(
float( line.split()[2] ) ) )
408 if line.find(
'Cov(2,j)') != -1:
409 tmpbeam.Zerr =
str(math.sqrt(
float( line.split()[3] ) ) )
411 if line.find(
'Cov(3,j)') != -1:
412 tmpbeam.sigmaZerr =
str(math.sqrt(
float( line.split()[4] ) ) )
414 if line.find(
'Cov(4,j)') != -1:
415 tmpbeam.dxdzerr =
str(math.sqrt(
float( line.split()[5] ) ) )
417 if line.find(
'Cov(5,j)') != -1:
418 tmpbeam.dydzerr =
str(math.sqrt(
float( line.split()[6] ) ) )
420 if line.find(
'Cov(6,j)') != -1:
421 tmpbeam.beamWidthXerr =
str(math.sqrt(
float( line.split()[7] ) ) )
422 tmpbeam.beamWidthYerr = tmpbeam.beamWidthXerr
424 if line.find(
'LumiRange') != -1:
425 if IOVbase==
"lumibase":
426 tmpbeam.IOVfirst = line.split()[1]
427 tmpbeam.IOVlast = line.split()[3]
429 if line.find(
'Runnumber') != -1:
430 tmpbeam.Run = line.split()[1]
431 if IOVbase ==
"runbase":
432 tmpbeam.IOVfirst = line.split()[1]
433 tmpbeam.IOVlast = line.split()[1]
435 tmpBX = line.split()[3]
437 if line.find(
'BeginTimeOfFit') != -1:
438 tmpbeam.IOVBeginTime = line.split()[1] +
" "+line.split()[2] +
" "+line.split()[3]
439 if IOVbase ==
"timebase":
440 tmpbeam.IOVfirst = time.mktime( time.strptime(line.split()[1] +
" " + line.split()[2] +
" " + line.split()[3],
"%Y.%m.%d %H:%M:%S %Z") )
442 if line.find(
'EndTimeOfFit') != -1:
443 tmpbeam.IOVEndTime = line.split()[1] +
" "+line.split()[2] +
" "+line.split()[3]
444 if IOVbase ==
"timebase":
445 tmpbeam.IOVlast = time.mktime( time.strptime(line.split()[1] +
" " + line.split()[2] +
" " + line.split()[3],
"%Y.%m.%d %H:%M:%S %Z") )
447 if tmpbeamsize == 20:
448 if IOVbase==
"lumibase":
449 tmprunfirst =
int(firstRun.split(
":")[0])
450 tmprunlast =
int(lastRun.split(
":")[0])
451 tmplumifirst =
int(firstRun.split(
":")[1])
452 tmplumilast =
int(lastRun.split(
":")[1])
453 acceptiov1 = acceptiov2 =
False 455 if tmprunfirst == tmprunlast
and int(tmpbeam.Run)==tmprunfirst:
456 if int(tmpbeam.IOVfirst) >= tmplumifirst
and int(tmpbeam.IOVlast)<=tmplumilast:
457 acceptiov1 = acceptiov2 =
True 459 elif int(tmpbeam.Run) == tmprunfirst:
460 if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 =
True 461 elif int(tmpbeam.Run) == tmprunlast:
462 if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 =
True 463 elif tmprunfirst <=
int(tmpbeam.Run)
and tmprunlast >=
int(tmpbeam.Run):
464 acceptiov1 = acceptiov2 =
True 466 if acceptiov1
and acceptiov2:
467 if tmpbeam.Type != 2:
468 print(
"invalid fit, skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast))
469 elif isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
470 print(
"invalid fit, NaN values!! skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast))
472 if (tmpBX
in maplist) ==
False:
473 maplist[tmpBX] = [tmpbeam]
475 maplist[tmpBX].
append(tmpbeam)
477 listbeam.append(tmpbeam)
479 elif int(tmpbeam.IOVfirst) >=
int(firstRun)
and int(tmpbeam.IOVlast) <=
int(lastRun):
480 if tmpbeam.Type != 2:
481 print(
"invalid fit, skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast))
482 elif isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
483 print(
"invalid fit, NaN values!! skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast))
485 listbeam.append(tmpbeam)
494 if line.find(
'X0') != -1:
495 tmpbeam.X = line.split()[2]
496 tmpbeam.Xerr = line.split()[4]
499 if line.find(
'Y0') != -1:
500 tmpbeam.Y = line.split()[2]
501 tmpbeam.Yerr = line.split()[4]
504 if line.find(
'Z0') != -1
and line.find(
'Sigma Z0') == -1:
505 tmpbeam.Z = line.split()[2]
506 tmpbeam.Zerr = line.split()[4]
509 if line.find(
'Sigma Z0') !=-1:
510 tmpbeam.sigmaZ = line.split()[3]
511 tmpbeam.sigmaZerr = line.split()[5]
513 if line.find(
'dxdz') != -1:
514 tmpbeam.dxdz = line.split()[2]
515 tmpbeam.dxdzerr = line.split()[4]
517 if line.find(
'dydz') != -1:
518 tmpbeam.dydz = line.split()[2]
519 tmpbeam.dydzerr = line.split()[4]
521 if line.find(
'Beam Width X') != -1:
522 tmpbeam.beamWidthX = line.split()[4]
523 tmpbeam.beamWidthXerr = line.split()[6]
525 if line.find(
'Beam Width Y') != -1:
526 tmpbeam.beamWidthY = line.split()[4]
527 tmpbeam.beamWidthYerr = line.split()[6]
530 if line.find(
'for runs') != -1:
532 tmpbeam.Run = line.split()[2]
533 if IOVbase ==
"runbase":
534 tmpbeam.IOVfirst = line.split()[2]
535 tmpbeam.IOVlast = line.split()[4]
537 if line.find(
'LumiSection') != -1:
538 if IOVbase==
"lumibase":
539 tmpbeam.IOVfirst = line.split()[10]
540 tmpbeam.IOVlast = line.split()[10]
542 if tmpbeamsize == 10:
544 if IOVbase==
"lumibase":
545 tmprunfirst =
int(firstRun.split(
":")[0])
546 tmprunlast =
int(lastRun.split(
":")[0])
547 tmplumifirst =
int(firstRun.split(
":")[1])
548 tmplumilast =
int(lastRun.split(
":")[1])
549 acceptiov1 = acceptiov2 =
False 551 if tmprunfirst == tmprunlast
and int(tmpbeam.Run)==tmprunfirst:
552 if int(tmpbeam.IOVfirst) >= tmplumifirst
and int(tmpbeam.IOVlast)<=tmplumilast:
553 acceptiov1 = acceptiov2 =
True 555 elif int(tmpbeam.Run) == tmprunfirst:
556 if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 =
True 557 elif int(tmpbeam.Run) == tmprunlast:
558 if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 =
True 559 elif tmprunfirst <=
int(tmpbeam.Run)
and tmprunlast >=
int(tmpbeam.Run):
560 acceptiov1 = acceptiov2 =
True 562 if acceptiov1
and acceptiov2:
563 if isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
564 print(
"invalid fit, NaN values!! skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast))
566 if (tmpBX
in maplist) ==
False:
567 maplist[tmpBX] = [tmpbeam]
569 maplist[tmpBX].
append(tmpbeam)
571 listbeam.append(tmpbeam)
573 elif int(tmpbeam.IOVfirst) >=
int(firstRun)
and int(tmpbeam.IOVlast) <=
int(lastRun):
574 if isnan(tmpbeam.Z)
or isnan(tmpbeam.Zerr)
or isnan(tmpbeam.sigmaZerr)
or isnan(tmpbeam.beamWidthXerr)
or isnan(tmpbeam.beamWidthYerr):
575 print(
"invalid fit, NaN values!! skip Run "+
str(tmpbeam.Run)+
" IOV: "+
str(tmpbeam.IOVfirst) +
" to "+
str(tmpbeam.IOVlast))
577 listbeam.append(tmpbeam)
584 print(
" got total number of IOVs = " +
str(len(listbeam)) +
" from file " + fileName)
595 if IOVbase ==
"lumibase":
596 listbeam.sort( cmp = cmp_list_lumi )
598 listbeam.sort( cmp = cmp_list_run )
602 for ii
in range(0,len(listbeam)):
604 datax = ibeam.IOVfirst
606 if datax ==
'0' and IOVbase ==
"runbase":
607 print(
" iov = 0? skip this IOV = "+
str(ibeam.IOVfirst) +
" to " +
str(ibeam.IOVlast))
608 tmpremovelist.append(ibeam)
610 if ii < len(listbeam) -1:
612 if IOVbase ==
"lumibase":
613 if ibeam.Run == listbeam[ii+1].Run
and ibeam.IOVfirst == listbeam[ii+1].IOVfirst:
614 print(
" duplicate IOV = "+datax+
", keep only last duplicate entry")
615 tmpremovelist.append(ibeam)
616 elif datax == listbeam[ii+1].IOVfirst:
617 print(
" duplicate IOV = "+datax+
", keep only last duplicate entry")
618 tmpremovelist.append(ibeam)
620 for itmp
in tmpremovelist:
621 listbeam.remove(itmp)
633 maxNlumis = 999999999
634 for ii
in range(0,len(listbeam)):
639 tmpbeam.IOVfirst = ibeam.IOVfirst
640 tmpbeam.IOVBeginTime = ibeam.IOVBeginTime
641 tmpbeam.Run = ibeam.Run
648 if ii < len(listbeam) - 1:
649 inextbeam = listbeam[ii+1]
651 if ii < len(listbeam) -2:
652 iNNbeam = listbeam[ii+2]
654 print(
"close payload because end of data has been reached. Run "+ibeam.Run)
657 if ibeam.Run != inextbeam.Run:
658 print(
"close payload because end of run "+ibeam.Run)
661 if countlumi == maxNlumis -1:
662 print(
"close payload because maximum lumi sections accumulated within run "+ibeam.Run)
666 (tmpbeam.X, tmpbeam.Xerr) =
weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
667 (tmpbeam.Y, tmpbeam.Yerr) =
weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
668 (tmpbeam.Z, tmpbeam.Zerr) =
weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
669 (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) =
weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
670 (tmpbeam.dxdz, tmpbeam.dxdzerr) =
weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
671 (tmpbeam.dydz, tmpbeam.dydzerr) =
weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
673 (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) =
weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
674 (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) =
weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
686 limit =
float(ibeam.beamWidthX)/2.
687 if limit < min_limit: limit = min_limit
690 adelta1 =
delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr)
692 adelta1dxdz =
delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
693 adelta2dxdz = (0.,1.e9)
694 adelta1dydz =
delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
695 adelta2dydz = (0.,1.e9)
696 adelta1widthx =
delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
697 adelta2widthx = (0.,1.e9)
698 adelta1widthy =
delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
699 adelta2widthy = (0.,1.e9)
700 adelta1z0 =
delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr)
701 adelta1sigmaZ =
delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr)
703 if iNNbeam.Type != -1:
704 adelta2 =
delta(inextbeam.X, inextbeam.Xerr, iNNbeam.X, iNNbeam.Xerr)
705 adelta2dxdz =
delta(inextbeam.dxdz, inextbeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr)
706 adelta2dydz =
delta(inextbeam.dydz, inextbeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr)
707 adelta2widthx =
delta(inextbeam.beamWidthX, inextbeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr)
708 adelta2widthy =
delta(inextbeam.beamWidthY, inextbeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr)
710 deltaX =
deltaSig(adelta1) > 3.5
and adelta1[0] >= limit
711 if ii < len(listbeam) -2:
712 if deltaX==
False and adelta1[0]*adelta2[0] > 0.
and math.fabs(adelta1[0]+adelta2[0]) >= limit:
715 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:
722 adelta1 =
delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr)
724 if iNNbeam.Type != -1:
725 adelta2 =
delta(inextbeam.Y, inextbeam.Yerr, iNNbeam.Y, iNNbeam.Yerr)
727 deltaY =
deltaSig(adelta1) > 3.5
and adelta1[0] >= limit
728 if ii < len(listbeam) -2:
729 if deltaY==
False and adelta1[0]*adelta2[0] > 0.
and math.fabs(adelta1[0]+adelta2[0]) >= limit:
731 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:
735 limit =
float(ibeam.sigmaZ)/2.
736 deltaZ =
deltaSig(adelta1z0) > 3.5
and math.fabs(adelta1z0[0]) >= limit
738 deltasigmaZ =
deltaSig(adelta1sigmaZ) > 5.0
741 adelta =
delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
743 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:
746 adelta =
delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
748 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:
751 adelta =
delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
753 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:
756 adelta =
delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
758 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:
772 if deltaX
or deltaY
or deltaZ
or deltasigmaZ
or deltadxdz
or deltadydz
or deltawidthX
or deltawidthY:
780 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))
783 tmpbeam.IOVlast = ibeam.IOVlast
784 tmpbeam.IOVEndTime = ibeam.IOVEndTime
785 print(
" Run: "+tmpbeam.Run +
" Lumi1: "+
str(tmpbeam.IOVfirst) +
" Lumi2: "+
str(tmpbeam.IOVlast))
786 newlistbeam.append(tmpbeam)
792 payloadfile = open(fileName,
"w")
793 for iload
in newlistbeam:
794 dump( iload, payloadfile )
802 lastPayload = listbeam[0]
806 for ii
in range(0,len(listbeam)):
809 deltaX =
delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr) > 1.5
810 deltaY =
delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr) > 1.5
811 deltaZ =
delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr) > 2.5
813 deltasigmaZ =
delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr) > 2.5
814 deltadxdz =
delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr) > 2.5
815 deltadydz =
delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr) > 2.5
817 deltawidthX =
delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr) > 3
818 deltawidthY =
delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr) > 3
832 if deltaX
or deltaY
or deltaZ
or deltasigmaZ
or deltadxdz
or deltadydz
or deltawidthX
or deltawidthY:
842 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))
845 if ii >= len(listbeam) - 1
or listbeam[ii].Run != listbeam[ii+1].Run :
846 print(
"close payload because end of run has been reached. Run " + listbeam[ii].Run)
858 for ibeam
in listbeam[firstToUse:lastToUse]:
859 (tmpbeam.X, tmpbeam.Xerr) =
weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
860 (tmpbeam.Y, tmpbeam.Yerr) =
weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
861 (tmpbeam.Z, tmpbeam.Zerr) =
weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
862 (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) =
weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
863 (tmpbeam.dxdz, tmpbeam.dxdzerr) =
weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
864 (tmpbeam.dydz, tmpbeam.dydzerr) =
weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
866 (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) =
weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
867 (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) =
weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
868 tmpbeam.IOVfirst = listbeam[firstToUse].IOVfirst
869 tmpbeam.IOVBeginTime = listbeam[firstToUse].IOVBeginTime
870 tmpbeam.Run = listbeam[firstToUse].Run
872 tmpbeam.IOVlast = listbeam[lastToUse].IOVlast
873 tmpbeam.IOVEndTime = listbeam[lastToUse].IOVEndTime
874 newlistbeam.append(tmpbeam)
875 firstToUse = lastToUse+1
876 print(
"Run: " + tmpbeam.Run +
" Lumi1: " +
str(tmpbeam.IOVfirst) +
" Lumi2: " +
str(tmpbeam.IOVlast))
878 payloadfile = open(fileName,
"w")
879 for iload
in newlistbeam:
880 dump( iload, payloadfile )
884 def writeSqliteFile(sqliteFileName,tagName,timeType,beamSpotFile,sqliteTemplateFile,tmpDir="/tmp/"):
885 writeDBOut = tmpDir +
"write2DB_" + tagName +
".py" 886 wFile = open(sqliteTemplateFile)
887 wNewFile = open(writeDBOut,
'w')
889 writeDBTags = [(
'SQLITEFILE',
'sqlite_file:' + sqliteFileName),
891 (
'TIMETYPE',timeType),
892 (
'BEAMSPOTFILE',beamSpotFile)]
895 for itag
in writeDBTags:
896 line = line.replace(itag[0],itag[1])
900 print(
"writing sqlite file ...")
901 status_wDB = commands.getstatusoutput(
'cmsRun '+ writeDBOut)
904 os.system(
"rm -f " + writeDBOut)
905 return not status_wDB[0]
909 readDBOut = tmpDir +
"readDB_" + tagName +
".py" 911 rFile = open(sqliteTemplateFile)
912 rNewFile = open(readDBOut,
'w')
914 readDBTags = [(
'SQLITEFILE',
'sqlite_file:' + sqliteFileName),
918 for itag
in readDBTags:
919 line = line.replace(itag[0],itag[1])
923 status_rDB = commands.getstatusoutput(
'cmsRun '+ readDBOut)
925 outtext = status_rDB[1]
927 os.system(
"rm -f " + readDBOut)
928 return not status_rDB[0]
931 def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill ,tmpDir="/tmp/"):
932 aCommand =
"conddb_import -c sqlite_file:" + tmpDir + combinedSqliteFileName +
" -f sqlite_file:" + sqliteFileName +
" -i " + tagName +
" -t " + tagName +
" -b " + IOVSince +
" -e " + IOVTill
934 std = commands.getstatusoutput(aCommand)
941 acmd =
"chmod a+w " + sqliteFileDirName + sqliteFileName +
".txt" 942 outcmd = commands.getstatusoutput(acmd)
946 print(
"Can't change permission to file: " + sqliteFileDirName + sqliteFileName +
".txt")
949 acmd =
"cp " + sqliteFileDirName + sqliteFileName +
".db " + sqliteFileDirName + sqliteFileName +
".txt ." 951 outcmd = commands.getstatusoutput(acmd)
954 print(
"Couldn't cd to " + sqliteFileDirName)
957 acmd =
"tar -cvjf " + sqliteFileName +
".tar.bz2 " + sqliteFileName +
".db " + sqliteFileName +
".txt" 959 outcmd = commands.getstatusoutput(acmd)
962 print(
"Couldn't zip the files!")
965 acmd =
"chmod a+w " + sqliteFileName +
".tar.bz2" 966 outcmd = commands.getstatusoutput(acmd)
970 print(
"Can't change permission to file: " + sqliteFileDirName + sqliteFileName +
".tar.bz2")
973 acmd =
"scp -p " + sqliteFileName +
".tar.bz2" +
" webcondvm.cern.ch:" + dropbox
975 outcmd = commands.getstatusoutput(acmd)
978 print(
"Couldn't scp the files to DropBox!")
982 acmd =
"mv " + sqliteFileName +
".tar.bz2 " + sqliteFileDirName
984 outcmd = commands.getstatusoutput(acmd)
987 print(
"Couldn't mv the file to " + sqliteFileDirName)
990 acmd =
"rm " + sqliteFileName +
".db " + sqliteFileName +
".txt" 992 outcmd = commands.getstatusoutput(acmd)
995 print(
"Couldn't rm the db and txt files")
std::vector< std::string_view > split(std::string_view, const char *)
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
S & print(S &os, JobReport::InputFile const &f)
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)