CMS 3D CMS Logo

Classes | Functions | Variables
CommonMethods Namespace Reference

Classes

class  ParsingError
 

Functions

def appendSqliteFile (combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill, tmpDir="/tmp/")
 
def checkLock ()
 
def cmp_list_lumi (a, b)
 
def cmp_list_run (a, b)
 end lumi tools More...
 
def cp (fromDir, toDir, listOfFiles, overwrite=False, smallList=False)
 
def createWeightedPayloads (fileName, listbeam=[], weighted=True)
 CREATE FILE FOR PAYLOADS. More...
 
def createWeightedPayloadsNew (fileName, listbeam=[], weighted=True)
 
def delta (x, xerr, nextx, nextxerr)
 
def deltaSig (x)
 
def dirExists (dir)
 
def dump (beam, file)
 
def dumpValues (beam, file)
 
def exit (msg="")
 
def isnan (num)
 
def lock ()
 
def ls (dir, filter="")
 
def nonzero (self)
 
def pack (high, low)
 lumi tools CondCore/Utilities/python/timeUnitHelper.py More...
 
def parse (docstring, arglist=None)
 
def readBeamSpotFile (fileName, listbeam=[], IOVbase="runbase", firstRun='1', lastRun='4999999999')
 
def readSqliteFile (sqliteFileName, tagName, sqliteTemplateFile, tmpDir="/tmp/")
 
def rmLock ()
 
def sendEmail (mailList, error)
 General utilities. More...
 
def setLockName (name)
 
def sortAndCleanBeamList (listbeam=[], IOVbase="lumibase")
 Sort and clean list of data for consecutive duplicates and bad fits. More...
 
def timeoutManager (type, timeout=-1, fileName=".timeout")
 
def unpack (i)
 
def unpackLumiid (i)
 
def uploadSqliteFile (sqliteFileDirName, sqliteFileName, dropbox="/DropBox")
 
def weight (x1, x1err, x2, x2err)
 
def writeSqliteFile (sqliteFileName, tagName, timeType, beamSpotFile, sqliteTemplateFile, tmpDir="/tmp/")
 

Variables

 __nonzero__
 
 lockFile
 
 USAGE
 OPTIONS. More...
 

Function Documentation

def CommonMethods.appendSqliteFile (   combinedSqliteFileName,
  sqliteFileName,
  tagName,
  IOVSince,
  IOVTill,
  tmpDir = "/tmp/" 
)

Definition at line 928 of file CommonMethods.py.

Referenced by uploader.main(), and BeamSpotWorkflow.main().

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
930  print aCommand
931  std = commands.getstatusoutput(aCommand)
932  print std[1]
933  return not std[0]
934 
def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill, tmpDir="/tmp/")
def CommonMethods.checkLock ( )

Definition at line 71 of file CommonMethods.py.

Referenced by BeamSpotWorkflow.main(), and rmLock().

71 def checkLock():
72  global lockFile
73  if os.path.isfile(lockFile):
74  return True
75  else:
76  return False
77 
def CommonMethods.cmp_list_lumi (   a,
  b 
)

Definition at line 259 of file CommonMethods.py.

References createfilelist.int.

259 def cmp_list_lumi(a,b):
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
266 
def cmp_list_lumi(a, b)
def CommonMethods.cmp_list_run (   a,
  b 
)

end lumi tools

Definition at line 253 of file CommonMethods.py.

References createfilelist.int.

253 def cmp_list_run(a,b):
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
257 
def cmp_list_run(a, b)
end lumi tools
def CommonMethods.cp (   fromDir,
  toDir,
  listOfFiles,
  overwrite = False,
  smallList = False 
)

Definition at line 189 of file CommonMethods.py.

189 def cp(fromDir,toDir,listOfFiles,overwrite=False,smallList=False):
190  cpCommand = ''
191  copiedFiles = []
192  if fromDir.find('castor') != -1 or toDir.find('castor') != -1 :
193  cpCommand = 'rf'
194  elif fromDir.find('resilient') != -1:
195  cpCommand = 'dc'
196  if fromDir[len(fromDir)-1] != '/':
197  fromDir += '/'
198 
199  if toDir[len(toDir)-1] != '/':
200  toDir += '/'
201 
202  for file in listOfFiles:
203  if os.path.isfile(toDir+file):
204  if overwrite:
205  print "File " + file + " already exists in destination directory. We will overwrite it."
206  else:
207  print "File " + file + " already exists in destination directory. We will Keep original file."
208  if not smallList:
209  copiedFiles.append(file)
210  continue
211  # copy to local disk
212  aCommand = cpCommand + 'cp '+ fromDir + file + " " + toDir
213  print " >> " + aCommand
214  tmpStatus = commands.getstatusoutput( aCommand )
215  if tmpStatus[0] == 0:
216  copiedFiles.append(file)
217  else:
218  print "[cp()]\tERROR: Can't copy file " + file
219  return copiedFiles
220 
def cp(fromDir, toDir, listOfFiles, overwrite=False, smallList=False)
def CommonMethods.createWeightedPayloads (   fileName,
  listbeam = [],
  weighted = True 
)

CREATE FILE FOR PAYLOADS.

Definition at line 622 of file CommonMethods.py.

References delta(), deltaSig(), dump(), objects.autophobj.float, and harvestTrackValidationPlots.str.

Referenced by BeamSpotWorkflow.main().

622 def createWeightedPayloads(fileName,listbeam=[],weighted=True):
623  newlistbeam = []
624  tmpbeam = BeamSpot()
625  docreate = True
626  countlumi = 0
627  tmprun = ""
628  maxNlumis = 60
629  if weighted:
630  maxNlumis = 999999999
631  for ii in range(0,len(listbeam)):
632  ibeam = listbeam[ii]
633  inextbeam = BeamSpot()
634  iNNbeam = BeamSpot()
635  if docreate:
636  tmpbeam.IOVfirst = ibeam.IOVfirst
637  tmpbeam.IOVBeginTime = ibeam.IOVBeginTime
638  tmpbeam.Run = ibeam.Run
639  tmpbeam.Type = 2
640  docheck = False
641  docreate = False
642  #print "Currently testing ii="+str(ii)+" Lumi1: "+str(ibeam.IOVfirst)
643 
644  # check last iov
645  if ii < len(listbeam) - 1:
646  inextbeam = listbeam[ii+1]
647  docheck = True
648  if ii < len(listbeam) -2:
649  iNNbeam = listbeam[ii+2]
650  else:
651  print "close payload because end of data has been reached. Run "+ibeam.Run
652  docreate = True
653  # check we run over the same run
654  if ibeam.Run != inextbeam.Run:
655  print "close payload because end of run "+ibeam.Run
656  docreate = True
657  # check maximum lumi counts
658  if countlumi == maxNlumis -1:
659  print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
660  docreate = True
661  countlumi = 0
662  # weighted average position
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)
669  #print "wx = " + ibeam.beamWidthX + " err= "+ ibeam.beamWidthXerr
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)
672 
673  if weighted:
674  docheck = False
675  # check offsets
676  #if False:
677  if docheck:
678 
679  # define minimum limit
680  min_limit = 0.0025
681 
682  # limit for x and y
683  limit = float(ibeam.beamWidthX)/2.
684  if limit < min_limit: limit = min_limit
685 
686  # check movements in X
687  adelta1 = delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr)
688  adelta2 = (0.,1.e9)
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)
699 
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)
706 
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:
710  #print " positive, "+str(adelta1[0]+adelta2[0])+ " limit="+str(limit)
711  deltaX = True
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:
713  deltaX = False
714  #print " negative, "+str(adelta1[0]/adelta2[0])
715  #else:
716  # print str(adelta1[0]/adelta2[0])
717 
718  # check movemnts in Y
719  adelta1 = delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr)
720  adelta2 = (0.,1.e9)
721  if iNNbeam.Type != -1:
722  adelta2 = delta(inextbeam.Y, inextbeam.Yerr, iNNbeam.Y, iNNbeam.Yerr)
723 
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:
727  deltaY = True
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:
729  deltaY = False
730  # check movements in Z
731 
732  limit = float(ibeam.sigmaZ)/2.
733  deltaZ = deltaSig(adelta1z0) > 3.5 and math.fabs(adelta1z0[0]) >= limit
734 
735  deltasigmaZ = deltaSig(adelta1sigmaZ) > 5.0
736 
737  # check dxdz
738  adelta = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
739  deltadxdz = deltaSig(adelta) > 5.0
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:
741  deltadxdz = False
742  # check dydz
743  adelta = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
744  deltadydz = deltaSig(adelta) > 5.0
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:
746  deltadydz = False
747 
748  adelta = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
749  deltawidthX = deltaSig(adelta) > 5
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:
751  deltawidthX = False
752 
753  adelta = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
754  deltawidthY = deltaSig(adelta) > 5
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:
756  deltawidthY = False
757  #if iNNbeam.Type != -1:
758  # deltaX = deltaX and delta(ibeam.X, ibeam.Xerr, iNNbeam.X, iNNbeam.Xerr) > 1.5
759  # deltaY = deltaY and delta(ibeam.Y, ibeam.Yerr, iNNbeam.Y, iNNbeam.Yerr) > 1.5
760  # deltaZ = deltaZ and delta(ibeam.Z, ibeam.Zerr, iNNbeam.Z, iNNbeam.Zerr) > 1.5
761  #
762  # deltasigmaZ = deltasigmaZ and delta(ibeam.sigmaZ, ibeam.sigmaZerr, iNNbeam.sigmaZ, iNNbeam.sigmaZerr) > 2.5
763  # deltadxdz = deltadxdz and delta(ibeam.dxdz, ibeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr) > 2.5
764  # deltadydz = deltadydz and delta(ibeam.dydz, ibeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr) > 2.5
765  #
766  # deltawidthX = deltawidthX and delta(ibeam.beamWidthX, ibeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr) > 3
767  # deltawidthY = deltawidthY and delta(ibeam.beamWidthY, ibeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr) > 3
768 
769  if deltaX or deltaY or deltaZ or deltasigmaZ or deltadxdz or deltadydz or deltawidthX or deltawidthY:
770  docreate = True
771  #print "shift here: x="+str(deltaX)+" y="+str(deltaY)
772  #print "x1 = "+ibeam.X + " x1err = "+ibeam.Xerr
773  #print "x2 = "+inextbeam.X + " x2err = "+inextbeam.Xerr
774  #print "Lumi1: "+str(ibeam.IOVfirst) + " Lumi2: "+str(inextbeam.IOVfirst)
775  #print " x= "+ibeam.X+" +/- "+ibeam.Xerr
776  #print "weighted average x = "+tmpbeam.X +" +//- "+tmpbeam.Xerr
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)
778  if docreate:
779  #if ii == len(listbeam)-1:
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)
784  tmpbeam = BeamSpot()
785  countlumi = 0
786  tmprun = ibeam.Run
787  countlumi += 1
788 
789  payloadfile = open(fileName,"w")
790  for iload in newlistbeam:
791  dump( iload, payloadfile )
792  payloadfile.close()
793  return newlistbeam
Definition: weight.py:1
def createWeightedPayloads(fileName, listbeam=[], weighted=True)
CREATE FILE FOR PAYLOADS.
def delta(x, xerr, nextx, nextxerr)
def dump(beam, file)
def CommonMethods.createWeightedPayloadsNew (   fileName,
  listbeam = [],
  weighted = True 
)

Definition at line 795 of file CommonMethods.py.

References delta(), dump(), and harvestTrackValidationPlots.str.

795 def createWeightedPayloadsNew(fileName,listbeam=[],weighted=True):
796  newlistbeam = []
797  docreate = False
798  docheck = False
799  lastPayload = listbeam[0]
800 
801  firstToUse = 0
802  lastToUse = 0
803  for ii in range(0,len(listbeam)):
804  docreate = False
805  if docheck:
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
809 
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
813 
814  deltawidthX = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr) > 3
815  deltawidthY = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr) > 3
816 
817  #if iNNbeam.Type != -1:
818  # deltaX = deltaX and delta(ibeam.X, ibeam.Xerr, iNNbeam.X, iNNbeam.Xerr) > 1.5
819  # deltaY = deltaY and delta(ibeam.Y, ibeam.Yerr, iNNbeam.Y, iNNbeam.Yerr) > 1.5
820  # deltaZ = deltaZ and delta(ibeam.Z, ibeam.Zerr, iNNbeam.Z, iNNbeam.Zerr) > 1.5
821  #
822  # deltasigmaZ = deltasigmaZ and delta(ibeam.sigmaZ, ibeam.sigmaZerr, iNNbeam.sigmaZ, iNNbeam.sigmaZerr) > 2.5
823  # deltadxdz = deltadxdz and delta(ibeam.dxdz, ibeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr) > 2.5
824  # deltadydz = deltadydz and delta(ibeam.dydz, ibeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr) > 2.5
825  #
826  # deltawidthX = deltawidthX and delta(ibeam.beamWidthX, ibeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr) > 3
827  # deltawidthY = deltawidthY and delta(ibeam.beamWidthY, ibeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr) > 3
828 
829  if deltaX or deltaY or deltaZ or deltasigmaZ or deltadxdz or deltadydz or deltawidthX or deltawidthY:
830  if ii != 0:
831  docreate = True
832  lastToUse = ii-1
833  #print "shift here: x="+str(deltaX)+" y="+str(deltaY)
834  #print "x1 = "+ibeam.X + " x1err = "+ibeam.Xerr
835  #print "x2 = "+inextbeam.X + " x2err = "+inextbeam.Xerr
836  #print "Lumi1: "+str(ibeam.IOVfirst) + " Lumi2: "+str(inextbeam.IOVfirst)
837  #print " x= "+ibeam.X+" +/- "+ibeam.Xerr
838  #print "weighted average x = "+tmpbeam.X +" +//- "+tmpbeam.Xerr
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)
840 
841  #WARNING this will only be fine for Run based IOVs
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
844  docreate = True
845  lastToUse = ii
846 
847 
848  # check maximum lumi counts
849 #? if countlumi == maxNlumis:
850 #? print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
851 #? docreate = True
852 #? countlumi = 0
853  if docreate:
854  tmpbeam = BeamSpot()
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)
862  #print "wx = " + ibeam.beamWidthX + " err= "+ ibeam.beamWidthXerr
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
868  tmpbeam.Type = 2
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)
874 
875  payloadfile = open(fileName,"w")
876  for iload in newlistbeam:
877  dump( iload, payloadfile )
878  payloadfile.close()
879 
Definition: weight.py:1
def delta(x, xerr, nextx, nextxerr)
def dump(beam, file)
def createWeightedPayloadsNew(fileName, listbeam=[], weighted=True)
def CommonMethods.delta (   x,
  xerr,
  nextx,
  nextxerr 
)

Definition at line 321 of file CommonMethods.py.

References objects.autophobj.float.

Referenced by createWeightedPayloads(), and createWeightedPayloadsNew().

321 def delta(x,xerr,nextx,nextxerr):
322  #return math.fabs( float(x) - float(nextx) )/math.sqrt(math.pow(float(xerr),2) + math.pow(float(nextxerr),2))
323  return ( float(x) - float(nextx), math.sqrt(math.pow(float(xerr),2) + math.pow(float(nextxerr),2)) )
324 
def delta(x, xerr, nextx, nextxerr)
def CommonMethods.deltaSig (   x)

Definition at line 325 of file CommonMethods.py.

Referenced by createWeightedPayloads().

325 def deltaSig( x ):
326  return math.fabs(x[0])/x[1]
327 
def CommonMethods.dirExists (   dir)

Definition at line 157 of file CommonMethods.py.

Referenced by rename.main(), BeamSpotWorkflow.main(), DQMStore.meGetter(), SiStripCommissioningSource.remove(), and DQMStore::IGetter.removeElement().

157 def dirExists(dir):
158  if dir.find("castor") != -1:
159  lsCommand = "nsls " + dir
160  output = commands.getstatusoutput( lsCommand )
161  return not output[0]
162  else:
163  return os.path.exists(dir)
164 
def dirExists(dir)
def CommonMethods.dump (   beam,
  file 
)

Definition at line 289 of file CommonMethods.py.

References dumpValues(), and harvestTrackValidationPlots.str.

Referenced by createWeightedPayloads(), and createWeightedPayloadsNew().

289 def dump( beam, file):
290  end = "\n"
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)
295  dumpValues(beam, file)
296 
def dumpValues(beam, file)
def dump(beam, file)
def CommonMethods.dumpValues (   beam,
  file 
)

Definition at line 298 of file CommonMethods.py.

References objects.autophobj.float, and harvestTrackValidationPlots.str.

Referenced by dump(), and BeamSpotWorkflow.main().

298 def dumpValues( beam, file):
299  end = "\n"
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)
319 
def dumpValues(beam, file)
def CommonMethods.exit (   msg = "")

Definition at line 90 of file CommonMethods.py.

References rmLock().

Referenced by ls().

90 def exit(msg=""):
91  rmLock()
92  raise SystemExit(msg or optionstring.replace("%prog",sys.argv[0]))
93 
def exit(msg="")
def CommonMethods.isnan (   num)

Definition at line 95 of file CommonMethods.py.

References objects.autophobj.float.

Referenced by readBeamSpotFile().

95 def isnan(num):
96  fnum = float(num)
97  return fnum != fnum
98 
def isnan(num)
def CommonMethods.lock ( )

Definition at line 79 of file CommonMethods.py.

Referenced by evf::FastMonitoringService.accumulateFileSize(), cond::service::PoolDBOutputService.appendSinceTime(), dqm::DQMFileSaverOnline.appendSnapshot(), cscdqm::Collection.book(), cscdqm::EventProcessor.calcEMUFractionHisto(), ecaldqm.checkElectronicsMap(), ecaldqm.checkGeometry(), ecaldqm.checkTopology(), ecaldqm.checkTrigTowerMap(), cond::service::PoolDBOutputService.closeIOV(), lumi::service::DBService.connectReadOnly(), cond::service::PoolDBOutputService.createNewIOV(), cond::XMLAuthenticationService::XMLAuthenticationService.credentials(), evf::FastMonitoringService.dowork(), TMVAEvaluator.evaluateTMVA(), CSCMonitorObject.Fill(), cond::service::PoolDBOutputService.forceInit(), evf::FastMonitoringService.getAbortFlagForLumi(), CSCMonitorObject.GetBinContent(), CSCMonitorObject.GetBinError(), CSCMonitorObject.GetEntries(), FedRawDataInputSource.getEventReport(), evf::FastMonitoringService.getEventsProcessedForLumi(), CSCMonitorObject.GetMaximumBin(), XrdAdaptor::XrdSiteStatisticsInformation.getStatisticsForSite(), cond::service::PoolDBOutputService.initDB(), edm::JobReport.inputFileClosed(), cond::service::PoolDBOutputService.lookUpRecord(), BeamSpotWorkflow.main(), DQMNet.onPeerConnect(), DQMNet.onPeerData(), evf::FastMonitoringService.postBeginJob(), evf::FastMonitoringService.postGlobalEndLumi(), evf::FastMonitoringService.preGlobalBeginLumi(), evf::FastMonitoringService.preGlobalEarlyTermination(), evf::FastMonitoringService.preGlobalEndLumi(), evf::FastMonitoringService.preModuleBeginJob(), evf::FastMonitoringService.prePathEvent(), evf::FastMonitoringService.preSourceEarlyTermination(), evf::FastMonitoringService.preStreamBeginLumi(), evf::FastMonitoringService.preStreamEarlyTermination(), evf::FastMonitoringService.preStreamEndLumi(), cscdqm::Dispatcher.processStandby(), cms::CkfTrackCandidateMakerBase.produceBase(), edm::JobReport.reportAnalysisFile(), edm::JobReport.reportError(), FedRawDataInputSource.reportEventsThisLumiInSource(), edm::JobReport.reportFallbackAttempt(), evf::FastMonitoringService.reportLockWait(), edm::JobReport.reportRandomStateFile(), edm::JobReport.reportSkippedEvent(), edm::JobReport.reportSkippedFile(), CSCMonitorObject.SetAxisRange(), CSCMonitorObject.setAxisTitle(), CSCMonitorObject.SetBinContent(), CSCMonitorObject.SetBinError(), ecaldqm.setElectronicsMap(), CSCMonitorObject.SetEntries(), ecaldqm.setGeometry(), CSCMonitorObject.SetMaximum(), CSCMonitorObject.SetNormFactor(), ecaldqm.setTopology(), ecaldqm.setTrigTowerMap(), cscdqm::EventProcessor.standbyEfficiencyHistos(), edm::ZombieKillerService.startThread(), evf::FastMonitoringService.stoppedLookingForFile(), cond::service::PoolDBOutputService.tagInfo(), cscdqm::EventProcessor.updateEfficiencyHistos(), cscdqm::EventProcessorMutex.updateFractionAndEfficiencyHistos(), cscdqm::Dispatcher.updateFractionAndEfficiencyHistos(), cscdqm::EventProcessor.updateFractionHistos(), cond::service::PoolDBOutputService.writeOne(), and cscdqm::EventProcessor.writeShifterHistograms().

79 def lock():
80  global lockFile
81  commands.getstatusoutput( "touch " + lockFile)
82 
def CommonMethods.ls (   dir,
  filter = "" 
)

Definition at line 166 of file CommonMethods.py.

References exit(), spr.find(), and split.

166 def ls(dir,filter=""):
167  lsCommand = ''
168  listOfFiles = []
169  if dir.find('castor') != -1:
170  lsCommand = 'ns'
171  elif not os.path.exists(dir):
172  print "ERROR: File or directory " + dir + " doesn't exist"
173  return listOfFiles
174 
175  aCommand = lsCommand + 'ls '+ dir
176  #aCommand = lsCommand + 'ls '+ dir + " | grep .txt"
177  if filter != "":
178  aCommand += " | grep " + filter
179 
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")
185 
186  return listOfFiles
187 
def exit(msg="")
def ls(dir, filter="")
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
double split
Definition: MVATrainer.cc:139
def CommonMethods.nonzero (   self)

Definition at line 129 of file CommonMethods.py.

129 def nonzero(self): # will become the nonzero method of optparse.Values
130  "True if options were given"
131  for v in self.__dict__.itervalues():
132  if v is not None: return True
133  return False
134 
def nonzero(self)
def CommonMethods.pack (   high,
  low 
)

lumi tools CondCore/Utilities/python/timeUnitHelper.py

pack high,low 32bit unsigned int to one unsigned 64bit long long
   Note:the print value of result number may appear signed, if the sign bit is used.

Definition at line 227 of file CommonMethods.py.

227 def pack(high,low):
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.
230  """
231  h=high<<32
232  return (h|low)
233 
def pack(high, low)
lumi tools CondCore/Utilities/python/timeUnitHelper.py
def CommonMethods.parse (   docstring,
  arglist = None 
)

Definition at line 105 of file CommonMethods.py.

105 def parse(docstring, arglist=None):
106  global optionstring
107  global tagType
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()
112  try:
113  p = optparse.OptionParser(optlines[0])
114  for line in optlines[1:]:
115  opt, help=line.split(':')[:2]
116  short,long=opt.split(',')[:2]
117  if '=' in opt:
118  action='store'
119  long=long.split('=')[0]
120  else:
121  action='store_true'
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)
127 
def parse(docstring, arglist=None)
def CommonMethods.readBeamSpotFile (   fileName,
  listbeam = [],
  IOVbase = "runbase",
  firstRun = '1',
  lastRun = '4999999999' 
)

Definition at line 329 of file CommonMethods.py.

References mps_alisetup.append, objects.autophobj.float, createfilelist.int, isnan(), and harvestTrackValidationPlots.str.

Referenced by BeamSpotWorkflow.main().

329 def readBeamSpotFile(fileName,listbeam=[],IOVbase="runbase", firstRun='1',lastRun='4999999999'):
330  tmpbeam = BeamSpot()
331  tmpbeamsize = 0
332 
333  #firstRun = "1"
334  #lastRun = "4999999999"
335  if IOVbase == "lumibase" and firstRun=='1' and lastRun=='4999999999' :
336  firstRun = "1:1"
337  lastRun = "4999999999:4999999999"
338 
339  inputfiletype = 0
340  #print "first = " +firstRun
341  #print "last = " +lastRun
342 
343  # for bx
344  maplist = {}
345  hasBX = False
346 
347  tmpfile = open(fileName)
348  atmpline = tmpfile.readline()
349  if atmpline.find('Runnumber') != -1:
350  inputfiletype = 1
351  if len(atmpline.split()) > 2:
352  hasBX = True
353  print " Input data has been calculated as function of BUNCH CROSSINGS."
354  tmpfile.seek(0)
355 
356 
357  if inputfiletype ==1:
358 
359  tmpBX = 0
360  for line in tmpfile:
361 
362  if line.find('Type') != -1:
363  tmpbeam.Type = int(line.split()[1])
364  tmpbeamsize += 1
365  if line.find('X0') != -1:
366  tmpbeam.X = line.split()[1]
367  #tmpbeam.Xerr = line.split()[4]
368  tmpbeamsize += 1
369  #print " x = " + str(tmpbeam.X)
370  if line.find('Y0') != -1:
371  tmpbeam.Y = line.split()[1]
372  #tmpbeam.Yerr = line.split()[4]
373  tmpbeamsize += 1
374  #print " y =" + str(tmpbeam.Y)
375  if line.find('Z0') != -1 and line.find('sigmaZ0') == -1:
376  tmpbeam.Z = line.split()[1]
377  #tmpbeam.Zerr = line.split()[4]
378  tmpbeamsize += 1
379  if line.find('sigmaZ0') !=-1:
380  tmpbeam.sigmaZ = line.split()[1]
381  #tmpbeam.sigmaZerr = line.split()[5]
382  tmpbeamsize += 1
383  if line.find('dxdz') != -1:
384  tmpbeam.dxdz = line.split()[1]
385  #tmpbeam.dxdzerr = line.split()[4]
386  tmpbeamsize += 1
387  if line.find('dydz') != -1:
388  tmpbeam.dydz = line.split()[1]
389  #tmpbeam.dydzerr = line.split()[4]
390  tmpbeamsize += 1
391  if line.find('BeamWidthX') != -1:
392  tmpbeam.beamWidthX = line.split()[1]
393  #tmpbeam.beamWidthXerr = line.split()[6]
394  tmpbeamsize += 1
395  if line.find('BeamWidthY') != -1:
396  tmpbeam.beamWidthY = line.split()[1]
397  #tmpbeam.beamWidthYerr = line.split()[6]
398  tmpbeamsize += 1
399  if line.find('Cov(0,j)') != -1:
400  tmpbeam.Xerr = str(math.sqrt( float( line.split()[1] ) ) )
401  tmpbeamsize += 1
402  if line.find('Cov(1,j)') != -1:
403  tmpbeam.Yerr = str(math.sqrt( float( line.split()[2] ) ) )
404  tmpbeamsize += 1
405  if line.find('Cov(2,j)') != -1:
406  tmpbeam.Zerr = str(math.sqrt( float( line.split()[3] ) ) )
407  tmpbeamsize += 1
408  if line.find('Cov(3,j)') != -1:
409  tmpbeam.sigmaZerr = str(math.sqrt( float( line.split()[4] ) ) )
410  tmpbeamsize += 1
411  if line.find('Cov(4,j)') != -1:
412  tmpbeam.dxdzerr = str(math.sqrt( float( line.split()[5] ) ) )
413  tmpbeamsize += 1
414  if line.find('Cov(5,j)') != -1:
415  tmpbeam.dydzerr = str(math.sqrt( float( line.split()[6] ) ) )
416  tmpbeamsize += 1
417  if line.find('Cov(6,j)') != -1:
418  tmpbeam.beamWidthXerr = str(math.sqrt( float( line.split()[7] ) ) )
419  tmpbeam.beamWidthYerr = tmpbeam.beamWidthXerr
420  tmpbeamsize += 1
421  if line.find('LumiRange') != -1:
422  if IOVbase=="lumibase":
423  tmpbeam.IOVfirst = line.split()[1]
424  tmpbeam.IOVlast = line.split()[3]
425  tmpbeamsize += 1
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]
431  if hasBX:
432  tmpBX = line.split()[3]
433  tmpbeamsize += 1
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") )
438  tmpbeamsize += 1
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") )
443  tmpbeamsize += 1
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
451  # check lumis in the same run
452  if tmprunfirst == tmprunlast and int(tmpbeam.Run)==tmprunfirst:
453  if int(tmpbeam.IOVfirst) >= tmplumifirst and int(tmpbeam.IOVlast)<=tmplumilast:
454  acceptiov1 = acceptiov2 = True
455  # if different runs make sure you select the correct range of lumis
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
462 
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)
468  elif hasBX:
469  if (tmpBX in maplist) == False:
470  maplist[tmpBX] = [tmpbeam]
471  else:
472  maplist[tmpBX].append(tmpbeam)
473  else:
474  listbeam.append(tmpbeam)
475 
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)
481  else:
482  listbeam.append(tmpbeam)
483 
484  tmpbeamsize = 0
485  tmpbeam = BeamSpot()
486  tmpBX = 0
487  else:
488 
489  for line in tmpfile:
490 
491  if line.find('X0') != -1:
492  tmpbeam.X = line.split()[2]
493  tmpbeam.Xerr = line.split()[4]
494  tmpbeamsize += 1
495  #print " x = " + str(tmpbeam.X)
496  if line.find('Y0') != -1:
497  tmpbeam.Y = line.split()[2]
498  tmpbeam.Yerr = line.split()[4]
499  tmpbeamsize += 1
500  #print " y =" + str(tmpbeam.Y)
501  if line.find('Z0') != -1 and line.find('Sigma Z0') == -1:
502  tmpbeam.Z = line.split()[2]
503  tmpbeam.Zerr = line.split()[4]
504  tmpbeamsize += 1
505  #print " z =" + str(tmpbeam.Z)
506  if line.find('Sigma Z0') !=-1:
507  tmpbeam.sigmaZ = line.split()[3]
508  tmpbeam.sigmaZerr = line.split()[5]
509  tmpbeamsize += 1
510  if line.find('dxdz') != -1:
511  tmpbeam.dxdz = line.split()[2]
512  tmpbeam.dxdzerr = line.split()[4]
513  tmpbeamsize += 1
514  if line.find('dydz') != -1:
515  tmpbeam.dydz = line.split()[2]
516  tmpbeam.dydzerr = line.split()[4]
517  tmpbeamsize += 1
518  if line.find('Beam Width X') != -1:
519  tmpbeam.beamWidthX = line.split()[4]
520  tmpbeam.beamWidthXerr = line.split()[6]
521  tmpbeamsize += 1
522  if line.find('Beam Width Y') != -1:
523  tmpbeam.beamWidthY = line.split()[4]
524  tmpbeam.beamWidthYerr = line.split()[6]
525  tmpbeamsize += 1
526  #if line.find('Run ') != -1:
527  if line.find('for runs') != -1:
528  #tmpbeam.IOVfirst = line.split()[6].strip(',')
529  tmpbeam.Run = line.split()[2]
530  if IOVbase == "runbase":
531  tmpbeam.IOVfirst = line.split()[2]
532  tmpbeam.IOVlast = line.split()[4]
533  tmpbeamsize += 1
534  if line.find('LumiSection') != -1:
535  if IOVbase=="lumibase":
536  tmpbeam.IOVfirst = line.split()[10]
537  tmpbeam.IOVlast = line.split()[10]
538  tmpbeamsize += 1
539  if tmpbeamsize == 10:
540 
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
547  # check lumis in the same run
548  if tmprunfirst == tmprunlast and int(tmpbeam.Run)==tmprunfirst:
549  if int(tmpbeam.IOVfirst) >= tmplumifirst and int(tmpbeam.IOVlast)<=tmplumilast:
550  acceptiov1 = acceptiov2 = True
551  # if different runs make sure you select the correct range of lumis
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
558 
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)
562  elif hasBX:
563  if (tmpBX in maplist) == False:
564  maplist[tmpBX] = [tmpbeam]
565  else:
566  maplist[tmpBX].append(tmpbeam)
567  else:
568  listbeam.append(tmpbeam)
569 
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)
573  else:
574  listbeam.append(tmpbeam)
575 
576  tmpbeamsize = 0
577  tmpbeam = BeamSpot()
578  tmpBX = 0
579 
580  tmpfile.close()
581  print " got total number of IOVs = " + str(len(listbeam)) + " from file " + fileName
582  #print " run " + str(listbeam[3].IOVfirst ) + " " + str( listbeam[3].X )
583  if hasBX:
584  return maplist
585  else:
586  return listbeam
587 
def isnan(num)
def readBeamSpotFile(fileName, listbeam=[], IOVbase="runbase", firstRun='1', lastRun='4999999999')
def CommonMethods.readSqliteFile (   sqliteFileName,
  tagName,
  sqliteTemplateFile,
  tmpDir = "/tmp/" 
)

Definition at line 905 of file CommonMethods.py.

Referenced by BeamSpotWorkflow.main().

905 def readSqliteFile(sqliteFileName,tagName,sqliteTemplateFile,tmpDir="/tmp/"):
906  readDBOut = tmpDir + "readDB_" + tagName + ".py"
907 
908  rFile = open(sqliteTemplateFile)
909  rNewFile = open(readDBOut,'w')
910 
911  readDBTags = [('SQLITEFILE','sqlite_file:' + sqliteFileName),
912  ('TAGNAME',tagName)]
913 
914  for line in rFile:
915  for itag in readDBTags:
916  line = line.replace(itag[0],itag[1])
917  rNewFile.write(line)
918 
919  rNewFile.close()
920  status_rDB = commands.getstatusoutput('cmsRun '+ readDBOut)
921 
922  outtext = status_rDB[1]
923  print outtext
924  os.system("rm -f " + readDBOut)
925  return not status_rDB[0]
926 
def readSqliteFile(sqliteFileName, tagName, sqliteTemplateFile, tmpDir="/tmp/")
def CommonMethods.rmLock ( )

Definition at line 84 of file CommonMethods.py.

References checkLock().

Referenced by exit(), and BeamSpotWorkflow.main().

84 def rmLock():
85  global lockFile
86  if checkLock():
87  commands.getstatusoutput( "rm " + lockFile)
88 
def CommonMethods.sendEmail (   mailList,
  error 
)

General utilities.

Definition at line 148 of file CommonMethods.py.

Referenced by BeamSpotWorkflow.main(), and BeamSpotWorkflow.selectFilesToProcess().

148 def sendEmail(mailList,error):
149  print "Sending email to " + mailList + " with body: " + error
150  list = mailList.split(',')
151  for email in list:
152  p = os.popen("mail -s \"Automatic workflow error\" " + email ,"w")
153  p.write(error)
154  status = p.close()
155 
def sendEmail(mailList, error)
General utilities.
def CommonMethods.setLockName (   name)

Definition at line 66 of file CommonMethods.py.

Referenced by BeamSpotWorkflow.main().

66 def setLockName(name):
67  global lockFile
68  lockFile = name
69 
def setLockName(name)
def CommonMethods.sortAndCleanBeamList (   listbeam = [],
  IOVbase = "lumibase" 
)

Sort and clean list of data for consecutive duplicates and bad fits.

Definition at line 590 of file CommonMethods.py.

References harvestTrackValidationPlots.str.

Referenced by BeamSpotWorkflow.main().

590 def sortAndCleanBeamList(listbeam=[],IOVbase="lumibase"):
591  # sort the list
592  if IOVbase == "lumibase":
593  listbeam.sort( cmp = cmp_list_lumi )
594  else:
595  listbeam.sort( cmp = cmp_list_run )
596 
597  # first clean list of data for consecutive duplicates and bad fits
598  tmpremovelist = []
599  for ii in range(0,len(listbeam)):
600  ibeam = listbeam[ii]
601  datax = ibeam.IOVfirst
602  #print str(ii) + " " +datax
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)
606 
607  if ii < len(listbeam) -1:
608  #print listbeam[ii+1].IOVfirst
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)
616 
617  for itmp in tmpremovelist:
618  listbeam.remove(itmp)
619 
def sortAndCleanBeamList(listbeam=[], IOVbase="lumibase")
Sort and clean list of data for consecutive duplicates and bad fits.
def CommonMethods.timeoutManager (   type,
  timeout = -1,
  fileName = ".timeout" 
)

Definition at line 8 of file CommonMethods.py.

References split, and harvestTrackValidationPlots.str.

Referenced by BeamSpotWorkflow.selectFilesToProcess().

8 def timeoutManager(type,timeout=-1,fileName=".timeout"):
9  if timeout == 0:
10  return 1
11  timeFormat = "%a,%Y/%m/%d,%H:%M:%S"
12  currentTime = time.gmtime()
13  timeoutLine = type + ' ' + time.strftime(timeFormat, currentTime) + '\n'
14  isTimeout = False
15  alreadyThere = False
16  timeoutType = -1;
17  fileExist = os.path.isfile(fileName)
18  text = ''
19  fields = []
20  reset = False
21  if timeout == -1:
22  reset = True
23  if fileExist:
24  file = open(fileName)
25  for line in file:
26  text += line
27  fields = line.strip('\n').split(' ')
28  if fields[0] == type:
29  alreadyThere = True
30  if reset:
31  text = text.replace(line,'')
32  continue
33 
34  fileTime = time.strptime(fields[1],timeFormat)
35  myTime = time.mktime(fileTime)
36  referenceTime = time.mktime(time.gmtime())
37  daylight = 0
38  if currentTime.tm_isdst == 0:
39  daylight = 3600
40  elapsedTime = referenceTime-myTime-daylight
41  if elapsedTime > timeout:
42  isTimeout = True
43  timeoutType = 1
44  print "Timeout! " + str(elapsedTime) + " seconds passed since the " + type + " timeout was set and you can't tolerate more than " + str(timeout) + " seconds!"
45  else:
46  timeoutType = 0
47  print "Timeout of type " + type + " already exist and was generated " + str(elapsedTime) + " seconds ago at " + fields[1]
48 
49  file.close()
50 
51  if not fileExist or not alreadyThere and not reset:
52  timeoutType = -1
53  text += timeoutLine
54 
55  if not fileExist or not alreadyThere or isTimeout or (reset and alreadyThere):
56  if fileExist:
57  commands.getstatusoutput("rm -rf " + fileName)
58  file = open(fileName,'w')
59  file.write(text)
60  file.close()
61 
62  return timeoutType
63 
64 
def timeoutManager(type, timeout=-1, fileName=".timeout")
Definition: CommonMethods.py:8
double split
Definition: MVATrainer.cc:139
def CommonMethods.unpack (   i)
unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)

Definition at line 235 of file CommonMethods.py.

References reco.return().

Referenced by unpackLumiid().

235 def unpack(i):
236  """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
237  """
238  high=i>>32
239  low=i&0xFFFFFFFF
240  return(high,low)
241 
return(e1-e2)*(e1-e2)+dp *dp
def CommonMethods.unpackLumiid (   i)
unpack 64bit lumiid to dictionary {'run','lumisection'}

Definition at line 243 of file CommonMethods.py.

References unpack().

244  """unpack 64bit lumiid to dictionary {'run','lumisection'}
245  """
246  j=unpack(i)
247  return {'run':j[0],'lumisection':j[1]}
def unpackLumiid(i)
def CommonMethods.uploadSqliteFile (   sqliteFileDirName,
  sqliteFileName,
  dropbox = "/DropBox" 
)

Definition at line 936 of file CommonMethods.py.

Referenced by uploadPayloads.main(), and BeamSpotWorkflow.main().

936 def uploadSqliteFile(sqliteFileDirName, sqliteFileName, dropbox="/DropBox"):
937  # Changing permissions to metadata
938  acmd = "chmod a+w " + sqliteFileDirName + sqliteFileName + ".txt"
939  outcmd = commands.getstatusoutput(acmd)
940  print acmd
941 # print outcmd[1]
942  if outcmd[0]:
943  print "Can't change permission to file: " + sqliteFileDirName + sqliteFileName + ".txt"
944  return False
945 
946  acmd = "cp " + sqliteFileDirName + sqliteFileName + ".db " + sqliteFileDirName + sqliteFileName + ".txt ."
947  print acmd
948  outcmd = commands.getstatusoutput(acmd)
949  print outcmd[1]
950  if outcmd[0]:
951  print "Couldn't cd to " + sqliteFileDirName
952  return False
953 
954  acmd = "tar -cvjf " + sqliteFileName + ".tar.bz2 " + sqliteFileName + ".db " + sqliteFileName + ".txt"
955  print acmd
956  outcmd = commands.getstatusoutput(acmd)
957  print outcmd[1]
958  if outcmd[0]:
959  print "Couldn't zip the files!"
960  return False
961 
962  acmd = "chmod a+w " + sqliteFileName + ".tar.bz2"
963  outcmd = commands.getstatusoutput(acmd)
964  print acmd
965 # print outcmd[1]
966  if outcmd[0]:
967  print "Can't change permission to file: " + sqliteFileDirName + sqliteFileName + ".tar.bz2"
968  return False
969 
970  acmd = "scp -p " + sqliteFileName + ".tar.bz2" + " webcondvm.cern.ch:" + dropbox
971  print acmd
972  outcmd = commands.getstatusoutput(acmd)
973  print outcmd[1]
974  if outcmd[0]:
975  print "Couldn't scp the files to DropBox!"
976  return False
977 
978 
979  acmd = "mv " + sqliteFileName + ".tar.bz2 " + sqliteFileDirName
980  print acmd
981  outcmd = commands.getstatusoutput(acmd)
982  print outcmd[1]
983  if outcmd[0]:
984  print "Couldn't mv the file to " + sqliteFileDirName
985  return False
986 
987  acmd = "rm " + sqliteFileName + ".db " + sqliteFileName + ".txt"
988  print acmd
989  outcmd = commands.getstatusoutput(acmd)
990  print outcmd[1]
991  if outcmd[0]:
992  print "Couldn't rm the db and txt files"
993  return False
994 
995 # acmd = "scp -p " + sqliteFileDirName + sqliteFileName + ".txt webcondvm.cern.ch:/tmp"
996 # outcmd = commands.getstatusoutput(acmd)
997 # print acmd
998 # print outcmd[1]
999 # if outcmd[0]:
1000 # print "Can't change permission to file: " + sqliteFileName + ".txt"
1001 # return False
1002 
1003 # acmd = "ssh webcondvm.cern.ch \"mv /tmp/" + sqliteFileName + ".db /tmp/" + sqliteFileName + ".txt " + dropbox +"\""
1004 # print acmd
1005 # outcmd = commands.getstatusoutput(acmd)
1006 # print outcmd[1]
1007 # if outcmd[0]:
1008 # print "Can't move files from tmp to dropbox!"
1009  return False
1010 
1011 # acmd = "ssh webcondvm.cern.ch \"mv /tmp/" + final_sqlite_file_name + ".txt "+dropbox +"\""
1012 # outcmd = commands.getstatusoutput(acmd)
1013 # print acmd
1014 # print outcmd[1]
1015 # if outcmd[0]:
1016 # print "Can't change permission to file: " + sqliteFileName + ".txt"
1017 # return False
1018 
1019  return True
1020 
1021 
def uploadSqliteFile(sqliteFileDirName, sqliteFileName, dropbox="/DropBox")
def CommonMethods.weight (   x1,
  x1err,
  x2,
  x2err 
)

Definition at line 268 of file CommonMethods.py.

References objects.autophobj.float, and harvestTrackValidationPlots.str.

268 def weight(x1, x1err,x2,x2err):
269  #print "x1 = "+str(x1)+" +/- "+str(x1err)+" x2 = "+str(x2)+" +/- "+str(x2err)
270  x1 = float(x1)
271  x1err = float(x1err)
272  x2 = float(x2)
273  x2err = float(x2err)
274  tmperr = 0.
275  if x2err < 1e-6 :
276  x2err = 1e-6
277  if x1err < 1e-6:
278  x1 = x2/(x2err * x2err)
279  tmperr = 1/(x2err*x2err)
280  else:
281  x1 = x1/(x1err*x1err) + x2/(x2err * x2err)
282  tmperr = 1/(x1err*x1err) + 1/(x2err*x2err)
283  x1 = x1/tmperr
284  x1err = 1/tmperr
285  x1err = math.sqrt(x1err)
286  return (str(x1), str(x1err))
287 
def weight(x1, x1err, x2, x2err)
def CommonMethods.writeSqliteFile (   sqliteFileName,
  tagName,
  timeType,
  beamSpotFile,
  sqliteTemplateFile,
  tmpDir = "/tmp/" 
)

Definition at line 881 of file CommonMethods.py.

Referenced by BeamSpotWorkflow.main().

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')
885 
886  writeDBTags = [('SQLITEFILE','sqlite_file:' + sqliteFileName),
887  ('TAGNAME',tagName),
888  ('TIMETYPE',timeType),
889  ('BEAMSPOTFILE',beamSpotFile)]
890 
891  for line in wFile:
892  for itag in writeDBTags:
893  line = line.replace(itag[0],itag[1])
894  wNewFile.write(line)
895 
896  wNewFile.close()
897  print "writing sqlite file ..."
898  status_wDB = commands.getstatusoutput('cmsRun '+ writeDBOut)
899  print status_wDB[1]
900 
901  os.system("rm -f " + writeDBOut)
902  return not status_wDB[0]
903 
def writeSqliteFile(sqliteFileName, tagName, timeType, beamSpotFile, sqliteTemplateFile, tmpDir="/tmp/")

Variable Documentation

CommonMethods.__nonzero__
private

Definition at line 136 of file CommonMethods.py.

CommonMethods.lockFile

Definition at line 5 of file CommonMethods.py.

CommonMethods.USAGE

OPTIONS.

Definition at line 102 of file CommonMethods.py.