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

◆ appendSqliteFile()

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

Definition at line 931 of file CommonMethods.py.

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
933  print(aCommand)
934  std = commands.getstatusoutput(aCommand)
935  print(std[1])
936  return not std[0]
937 

References print().

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

◆ checkLock()

def CommonMethods.checkLock ( )

Definition at line 74 of file CommonMethods.py.

74 def checkLock():
75  global lockFile
76  if os.path.isfile(lockFile):
77  return True
78  else:
79  return False
80 

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

◆ cmp_list_lumi()

def CommonMethods.cmp_list_lumi (   a,
  b 
)

Definition at line 262 of file CommonMethods.py.

262 def cmp_list_lumi(a,b):
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
269 

References createfilelist.int.

◆ cmp_list_run()

def CommonMethods.cmp_list_run (   a,
  b 
)

end lumi tools

Definition at line 256 of file CommonMethods.py.

256 def cmp_list_run(a,b):
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
260 

References createfilelist.int.

◆ cp()

def CommonMethods.cp (   fromDir,
  toDir,
  listOfFiles,
  overwrite = False,
  smallList = False 
)

Definition at line 192 of file CommonMethods.py.

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

References print().

Referenced by btagbtvdeep::TrackPairInfoBuilder.buildTrackPairInfo(), PixelCPEFast.fillParamsForGpu(), MTDCPEBase.getParameters(), HGCalGeomParameters.loadGeometryHexagon(), PixelCPEFast.localPosition(), LayerClusterAssociatorByEnergyScoreImpl.makeConnections(), PreshowerClusterAlgo.makeOneCluster(), TracksClusteringFromDisplacedSeed.nearTracks(), edm::soa::Table< edm::soa::col::Pt, edm::soa::col::Eta, edm::soa::col::Phi, edm::soa::col::Vz >.operator=(), Phase2TrackerClusterizer.produce(), BarrelDetLayer.setSurface(), ForwardDetLayer.setSurface(), and TotemVFATStatus.TotemVFATStatus().

◆ createWeightedPayloads()

def CommonMethods.createWeightedPayloads (   fileName,
  listbeam = [],
  weighted = True 
)

CREATE FILE FOR PAYLOADS.

Definition at line 625 of file CommonMethods.py.

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

References delta(), deltaSig(), dump(), dqmMemoryStats.float, print(), FastTimerService_cff.range, and str.

Referenced by BeamSpotWorkflow.main().

◆ createWeightedPayloadsNew()

def CommonMethods.createWeightedPayloadsNew (   fileName,
  listbeam = [],
  weighted = True 
)

Definition at line 798 of file CommonMethods.py.

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

References delta(), dump(), print(), FastTimerService_cff.range, and str.

◆ delta()

def CommonMethods.delta (   x,
  xerr,
  nextx,
  nextxerr 
)

Definition at line 324 of file CommonMethods.py.

324 def delta(x,xerr,nextx,nextxerr):
325  #return math.fabs( float(x) - float(nextx) )/math.sqrt(math.pow(float(xerr),2) + math.pow(float(nextxerr),2))
326  return ( float(x) - float(nextx), math.sqrt(math.pow(float(xerr),2) + math.pow(float(nextxerr),2)) )
327 

References dqmMemoryStats.float.

Referenced by createWeightedPayloads(), and createWeightedPayloadsNew().

◆ deltaSig()

def CommonMethods.deltaSig (   x)

Definition at line 328 of file CommonMethods.py.

328 def deltaSig( x ):
329  return math.fabs(x[0])/x[1]
330 

Referenced by createWeightedPayloads().

◆ dirExists()

def CommonMethods.dirExists (   dir)

Definition at line 160 of file CommonMethods.py.

160 def dirExists(dir):
161  if dir.find("castor") != -1:
162  lsCommand = "nsls " + dir
163  output = commands.getstatusoutput( lsCommand )
164  return not output[0]
165  else:
166  return os.path.exists(dir)
167 

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

◆ dump()

def CommonMethods.dump (   beam,
  file 
)

Definition at line 292 of file CommonMethods.py.

292 def dump( beam, file):
293  end = "\n"
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)
298  dumpValues(beam, file)
299 

References dumpValues(), and str.

Referenced by createWeightedPayloads(), and createWeightedPayloadsNew().

◆ dumpValues()

def CommonMethods.dumpValues (   beam,
  file 
)

Definition at line 301 of file CommonMethods.py.

301 def dumpValues( beam, file):
302  end = "\n"
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)
322 

References dqmMemoryStats.float, and str.

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

◆ exit()

def CommonMethods.exit (   msg = "")

Definition at line 93 of file CommonMethods.py.

93 def exit(msg=""):
94  rmLock()
95  raise SystemExit(msg or optionstring.replace("%prog",sys.argv[0]))
96 

References rmLock().

Referenced by ls().

◆ isnan()

def CommonMethods.isnan (   num)

◆ lock()

def CommonMethods.lock ( )

Definition at line 82 of file CommonMethods.py.

82 def lock():
83  global lockFile
84  commands.getstatusoutput( "touch " + lockFile)
85 

Referenced by evf::FastMonitoringService.accumulateFileSize(), cond::service::PoolDBOutputService.appendSinceTime(), dqm::DQMFileSaverOnline.appendSnapshot(), DQMEDAnalyzer.beginStream(), mxnet::cpp::Predictor.bind_executor(), cscdqm::Collection.book(), dqm::implementation::DQMStore.bookTransaction(), cscdqm::EventProcessor.calcEMUFractionHisto(), dqm::implementation::DQMStore.cleanupLumi(), cond::service::PoolDBOutputService.closeIOV(), cond::persistency::SessionImpl.commitTransaction(), cond::service::PoolDBOutputService.commitTransaction(), XrdAdaptor::XrdStatisticsService.condorUpdate(), lumi::service::DBService.connectReadOnly(), cond::service::PoolDBOutputService.createNewIOV(), cond::XMLAuthenticationService::XMLAuthenticationService.credentials(), edm::shared_memory::ControllerChannel.doTransition(), dqm::implementation::DQMStore.enterLumi(), cond::service::PoolDBOutputService.eraseSinceTime(), TMVAEvaluator.evaluateTMVA(), CSCMonitorObject.Fill(), dqm::implementation::DQMStore.findME(), dqm::implementation::DQMStore.findOrRecycle(), cond::service::PoolDBOutputService.forceInit(), evf::FastMonitoringService.getAbortFlagForLumi(), dqm::implementation::IGetter.getAllContents(), CSCMonitorObject.GetBinContent(), CSCMonitorObject.GetBinError(), dqm::implementation::IGetter.getContents(), CSCMonitorObject.GetEntries(), FedRawDataInputSource.getEventReport(), evf::FastMonitoringService.getEventsProcessedForLumi(), CSCMonitorObject.GetMaximumBin(), XrdAdaptor::XrdSiteStatisticsInformation.getStatisticsForSite(), RawPCCProducer.globalEndLuminosityBlockProduce(), dqm::implementation::DQMStore.initLumi(), edm::JobReport.inputFileClosed(), dqm::implementation::DQMStore.leaveLumi(), cond::service::PoolDBOutputService.lockRecords(), BeamSpotWorkflow.main(), dqm::implementation::DQMStore.meBookerGetter(), DQMNet.onPeerConnect(), DQMNet.onPeerData(), evf::FastMonitoringService.postBeginJob(), evf::FastMonitoringService.postGlobalEndLumi(), evf::FastMonitoringService.preGlobalBeginLumi(), evf::FastMonitoringService.preGlobalEarlyTermination(), evf::FastMonitoringService.preGlobalEndLumi(), evf::FastMonitoringService.preModuleBeginJob(), evf::FastMonitoringService.preSourceEarlyTermination(), evf::FastMonitoringService.preStreamBeginLumi(), evf::FastMonitoringService.preStreamEarlyTermination(), evf::FastMonitoringService.preStreamEndLumi(), PixelClusterShapeExtractor.processRec(), cscdqm::Dispatcher.processStandby(), cms::CkfTrackCandidateMakerBase.produceBase(), dqm::implementation::DQMStore.putME(), cond::service::PoolDBOutputService.releaseLocks(), cond::persistency::CoralMsgReporter.report(), edm::JobReport.reportAnalysisFile(), edm::JobReport.reportError(), FedRawDataInputSource.reportEventsThisLumiInSource(), edm::JobReport.reportFallbackAttempt(), evf::FastMonitoringService.reportLockWait(), edm::JobReport.reportRandomStateFile(), edm::JobReport.reportSkippedEvent(), edm::JobReport.reportSkippedFile(), cond::persistency::SessionImpl.rollbackTransaction(), CSCMonitorObject.SetAxisRange(), CSCMonitorObject.setAxisTitle(), CSCMonitorObject.SetBinContent(), CSCMonitorObject.SetBinError(), CSCMonitorObject.SetEntries(), CSCMonitorObject.SetMaximum(), CSCMonitorObject.SetNormFactor(), edm::shared_memory::ControllerChannel.setupWorker(), evf::FastMonitoringService.snapshotRunner(), cscdqm::EventProcessor.standbyEfficiencyHistos(), edm::ZombieKillerService.startThread(), cond::service::PoolDBOutputService.startTransaction(), cond::persistency::SessionImpl.startTransaction(), evf::FastMonitoringService.stoppedLookingForFile(), edm::shared_memory::ControllerChannel.stopWorker(), cond::service::PoolDBOutputService.tagInfo(), cscdqm::EventProcessor.updateEfficiencyHistos(), cscdqm::EventProcessorMutex.updateFractionAndEfficiencyHistos(), cscdqm::Dispatcher.updateFractionAndEfficiencyHistos(), cscdqm::EventProcessor.updateFractionHistos(), edm::shared_memory::ControllerChannel.wait(), cond::service::PoolDBOutputService.writeOne(), and cscdqm::EventProcessor.writeShifterHistograms().

◆ ls()

def CommonMethods.ls (   dir,
  filter = "" 
)

Definition at line 169 of file CommonMethods.py.

169 def ls(dir,filter=""):
170  lsCommand = ''
171  listOfFiles = []
172  if dir.find('castor') != -1:
173  lsCommand = 'ns'
174  elif not os.path.exists(dir):
175  print("ERROR: File or directory " + dir + " doesn't exist")
176  return listOfFiles
177 
178  aCommand = lsCommand + 'ls '+ dir
179  #aCommand = lsCommand + 'ls '+ dir + " | grep .txt"
180  if filter != "":
181  aCommand += " | grep " + filter
182 
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")
188 
189  return listOfFiles
190 

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

◆ nonzero()

def CommonMethods.nonzero (   self)

Definition at line 132 of file CommonMethods.py.

132 def nonzero(self): # will become the nonzero method of optparse.Values
133  "True if options were given"
134  for v in six.itervalues(self.__dict__):
135  if v is not None: return True
136  return False
137 

◆ pack()

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 230 of file CommonMethods.py.

230 def pack(high,low):
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.
233  """
234  h=high<<32
235  return (h|low)
236 

◆ parse()

def CommonMethods.parse (   docstring,
  arglist = None 
)

Definition at line 108 of file CommonMethods.py.

108 def parse(docstring, arglist=None):
109  global optionstring
110  global tagType
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()
115  try:
116  p = optparse.OptionParser(optlines[0])
117  for line in optlines[1:]:
118  opt, help=line.split(':')[:2]
119  short,long=opt.split(',')[:2]
120  if '=' in opt:
121  action='store'
122  long=long.split('=')[0]
123  else:
124  action='store_true'
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)
130 

◆ readBeamSpotFile()

def CommonMethods.readBeamSpotFile (   fileName,
  listbeam = [],
  IOVbase = "runbase",
  firstRun = '1',
  lastRun = '4999999999' 
)

Definition at line 332 of file CommonMethods.py.

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

References mps_setup.append, dqmMemoryStats.float, createfilelist.int, isnan(), print(), and str.

Referenced by BeamSpotWorkflow.main().

◆ readSqliteFile()

def CommonMethods.readSqliteFile (   sqliteFileName,
  tagName,
  sqliteTemplateFile,
  tmpDir = "/tmp/" 
)

Definition at line 908 of file CommonMethods.py.

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

References print().

Referenced by BeamSpotWorkflow.main().

◆ rmLock()

def CommonMethods.rmLock ( )

Definition at line 87 of file CommonMethods.py.

87 def rmLock():
88  global lockFile
89  if checkLock():
90  commands.getstatusoutput( "rm " + lockFile)
91 

References checkLock().

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

◆ sendEmail()

def CommonMethods.sendEmail (   mailList,
  error 
)

General utilities.

Definition at line 151 of file CommonMethods.py.

151 def sendEmail(mailList,error):
152  print("Sending email to " + mailList + " with body: " + error)
153  list = mailList.split(',')
154  for email in list:
155  p = os.popen("mail -s \"Automatic workflow error\" " + email ,"w")
156  p.write(error)
157  status = p.close()
158 

References print().

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

◆ setLockName()

def CommonMethods.setLockName (   name)

Definition at line 69 of file CommonMethods.py.

69 def setLockName(name):
70  global lockFile
71  lockFile = name
72 

Referenced by BeamSpotWorkflow.main().

◆ sortAndCleanBeamList()

def CommonMethods.sortAndCleanBeamList (   listbeam = [],
  IOVbase = "lumibase" 
)

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

Definition at line 593 of file CommonMethods.py.

593 def sortAndCleanBeamList(listbeam=[],IOVbase="lumibase"):
594  # sort the list
595  if IOVbase == "lumibase":
596  listbeam.sort( cmp = cmp_list_lumi )
597  else:
598  listbeam.sort( cmp = cmp_list_run )
599 
600  # first clean list of data for consecutive duplicates and bad fits
601  tmpremovelist = []
602  for ii in range(0,len(listbeam)):
603  ibeam = listbeam[ii]
604  datax = ibeam.IOVfirst
605  #print str(ii) + " " +datax
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)
609 
610  if ii < len(listbeam) -1:
611  #print listbeam[ii+1].IOVfirst
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)
619 
620  for itmp in tmpremovelist:
621  listbeam.remove(itmp)
622 

References print(), FastTimerService_cff.range, and str.

Referenced by BeamSpotWorkflow.main().

◆ timeoutManager()

def CommonMethods.timeoutManager (   type,
  timeout = -1,
  fileName = ".timeout" 
)

Definition at line 11 of file CommonMethods.py.

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

References print(), submitPVValidationJobs.split(), and str.

Referenced by BeamSpotWorkflow.selectFilesToProcess().

◆ unpack()

def CommonMethods.unpack (   i)
unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)

Definition at line 238 of file CommonMethods.py.

238 def unpack(i):
239  """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
240  """
241  high=i>>32
242  low=i&0xFFFFFFFF
243  return(high,low)
244 

References mathSSE.return().

Referenced by unpackLumiid().

◆ unpackLumiid()

def CommonMethods.unpackLumiid (   i)
unpack 64bit lumiid to dictionary {'run','lumisection'}

Definition at line 246 of file CommonMethods.py.

246 def unpackLumiid(i):
247  """unpack 64bit lumiid to dictionary {'run','lumisection'}
248  """
249  j=unpack(i)
250  return {'run':j[0],'lumisection':j[1]}

References unpack().

◆ uploadSqliteFile()

def CommonMethods.uploadSqliteFile (   sqliteFileDirName,
  sqliteFileName,
  dropbox = "/DropBox" 
)

Definition at line 939 of file CommonMethods.py.

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

References print().

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

◆ weight()

def CommonMethods.weight (   x1,
  x1err,
  x2,
  x2err 
)

Definition at line 271 of file CommonMethods.py.

271 def weight(x1, x1err,x2,x2err):
272  #print "x1 = "+str(x1)+" +/- "+str(x1err)+" x2 = "+str(x2)+" +/- "+str(x2err)
273  x1 = float(x1)
274  x1err = float(x1err)
275  x2 = float(x2)
276  x2err = float(x2err)
277  tmperr = 0.
278  if x2err < 1e-6 :
279  x2err = 1e-6
280  if x1err < 1e-6:
281  x1 = x2/(x2err * x2err)
282  tmperr = 1/(x2err*x2err)
283  else:
284  x1 = x1/(x1err*x1err) + x2/(x2err * x2err)
285  tmperr = 1/(x1err*x1err) + 1/(x2err*x2err)
286  x1 = x1/tmperr
287  x1err = 1/tmperr
288  x1err = math.sqrt(x1err)
289  return (str(x1), str(x1err))
290 

References dqmMemoryStats.float, and str.

◆ writeSqliteFile()

def CommonMethods.writeSqliteFile (   sqliteFileName,
  tagName,
  timeType,
  beamSpotFile,
  sqliteTemplateFile,
  tmpDir = "/tmp/" 
)

Definition at line 884 of file CommonMethods.py.

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

References print().

Referenced by BeamSpotWorkflow.main().

Variable Documentation

◆ __nonzero__

CommonMethods.__nonzero__
private

Definition at line 139 of file CommonMethods.py.

◆ lockFile

CommonMethods.lockFile

Definition at line 8 of file CommonMethods.py.

◆ USAGE

CommonMethods.USAGE

OPTIONS.

Definition at line 105 of file CommonMethods.py.

FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
CommonMethods.nonzero
def nonzero(self)
Definition: CommonMethods.py:132
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
CommonMethods.sendEmail
def sendEmail(mailList, error)
General utilities.
Definition: CommonMethods.py:151
align::BeamSpot
Definition: StructureType.h:95
CommonMethods.dirExists
def dirExists(dir)
Definition: CommonMethods.py:160
CommonMethods.parse
def parse(docstring, arglist=None)
Definition: CommonMethods.py:108
mathSSE::return
return((rh ^ lh) &mask)
CommonMethods.timeoutManager
def timeoutManager(type, timeout=-1, fileName=".timeout")
Definition: CommonMethods.py:11
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
CommonMethods.cmp_list_run
def cmp_list_run(a, b)
end lumi tools
Definition: CommonMethods.py:256
CommonMethods.rmLock
def rmLock()
Definition: CommonMethods.py:87
CommonMethods.uploadSqliteFile
def uploadSqliteFile(sqliteFileDirName, sqliteFileName, dropbox="/DropBox")
Definition: CommonMethods.py:939
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
str
#define str(s)
Definition: TestProcessor.cc:52
CommonMethods.isnan
def isnan(num)
Definition: CommonMethods.py:98
CommonMethods.createWeightedPayloadsNew
def createWeightedPayloadsNew(fileName, listbeam=[], weighted=True)
Definition: CommonMethods.py:798
CommonMethods.readSqliteFile
def readSqliteFile(sqliteFileName, tagName, sqliteTemplateFile, tmpDir="/tmp/")
Definition: CommonMethods.py:908
CommonMethods.readBeamSpotFile
def readBeamSpotFile(fileName, listbeam=[], IOVbase="runbase", firstRun='1', lastRun='4999999999')
Definition: CommonMethods.py:332
CommonMethods.ls
def ls(dir, filter="")
Definition: CommonMethods.py:169
CommonMethods.lock
def lock()
Definition: CommonMethods.py:82
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
mps_setup.append
append
Definition: mps_setup.py:85
CommonMethods.cmp_list_lumi
def cmp_list_lumi(a, b)
Definition: CommonMethods.py:262
CommonMethods.checkLock
def checkLock()
Definition: CommonMethods.py:74
createfilelist.int
int
Definition: createfilelist.py:10
CommonMethods.dump
def dump(beam, file)
Definition: CommonMethods.py:292
CommonMethods.writeSqliteFile
def writeSqliteFile(sqliteFileName, tagName, timeType, beamSpotFile, sqliteTemplateFile, tmpDir="/tmp/")
Definition: CommonMethods.py:884
CommonMethods.createWeightedPayloads
def createWeightedPayloads(fileName, listbeam=[], weighted=True)
CREATE FILE FOR PAYLOADS.
Definition: CommonMethods.py:625
CommonMethods.exit
def exit(msg="")
Definition: CommonMethods.py:93
CommonMethods.pack
def pack(high, low)
lumi tools CondCore/Utilities/python/timeUnitHelper.py
Definition: CommonMethods.py:230
CommonMethods.sortAndCleanBeamList
def sortAndCleanBeamList(listbeam=[], IOVbase="lumibase")
Sort and clean list of data for consecutive duplicates and bad fits.
Definition: CommonMethods.py:593
CommonMethods.setLockName
def setLockName(name)
Definition: CommonMethods.py:69
CommonMethods.weight
def weight(x1, x1err, x2, x2err)
Definition: CommonMethods.py:271
CommonMethods.delta
def delta(x, xerr, nextx, nextxerr)
Definition: CommonMethods.py:324
CommonMethods.unpackLumiid
def unpackLumiid(i)
Definition: CommonMethods.py:246
CommonMethods.appendSqliteFile
def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill, tmpDir="/tmp/")
Definition: CommonMethods.py:931
CommonMethods.deltaSig
def deltaSig(x)
Definition: CommonMethods.py:328
CommonMethods.cp
def cp(fromDir, toDir, listOfFiles, overwrite=False, smallList=False)
Definition: CommonMethods.py:192
CommonMethods.unpack
def unpack(i)
Definition: CommonMethods.py:238
weight
Definition: weight.py:1
CommonMethods.dumpValues
def dumpValues(beam, file)
Definition: CommonMethods.py:301