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

References print().

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

930 def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill ,tmpDir="/tmp/"):
931  aCommand = "conddb_import -c sqlite_file:" + tmpDir + combinedSqliteFileName + " -f sqlite_file:" + sqliteFileName + " -i " + tagName + " -t " + tagName + " -b " + IOVSince + " -e " + IOVTill
932  print(aCommand)
933  std = subprocess.getstatusoutput(aCommand)
934  print(std[1])
935  return not std[0]
936 
def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill, tmpDir="/tmp/")
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ checkLock()

def CommonMethods.checkLock ( )

Definition at line 73 of file CommonMethods.py.

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

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

◆ cmp_list_lumi()

def CommonMethods.cmp_list_lumi (   a,
  b 
)

Definition at line 261 of file CommonMethods.py.

References createfilelist.int.

261 def cmp_list_lumi(a,b):
262  if int(a.Run) < int(b.Run): return -1
263  if int(a.Run) == int(b.Run):
264  if int(a.IOVfirst) < int(b.IOVfirst): return -1
265  if int(a.IOVfirst) == int(b.IOVfirst): return 0
266  if int(a.IOVfirst) > int(b.IOVfirst): return 1
267  if int(a.Run) > int(b.Run) : return 1
268 
def cmp_list_lumi(a, b)

◆ cmp_list_run()

def CommonMethods.cmp_list_run (   a,
  b 
)

Definition at line 255 of file CommonMethods.py.

References createfilelist.int.

255 def cmp_list_run(a,b):
256  if int(a.IOVfirst) < int(b.IOVfirst): return -1
257  if int(a.IOVfirst) == int(b.IOVfirst): return 0
258  if int(a.IOVfirst) > int(b.IOVfirst): return 1
259 
def cmp_list_run(a, b)

◆ cp()

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

Definition at line 191 of file CommonMethods.py.

References print().

Referenced by btagbtvdeep::TrackPairInfoBuilder.buildTrackPairInfo(), pixelCPEforGPU.errorFromDB< pixelTopology::Phase2 >(), PixelCPEFast< TrackerTraits >.fillParamsForGpu(), MTDCPEBase.getParameters(), HGCalTBGeomParameters.loadGeometryHexagon(), HGCalGeomParameters.loadGeometryHexagon(), PixelCPEFast< TrackerTraits >.localPosition(), MultiClusterAssociatorByEnergyScoreImpl.makeConnections(), LCToCPAssociatorByEnergyScoreImpl.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(), TotemVFATStatus.setChipPosition(), BarrelDetLayer.setSurface(), ForwardDetLayer.setSurface(), and evf::FastMonitoringThread.start().

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

◆ createWeightedPayloads()

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

CREATE FILE FOR PAYLOADS.

Definition at line 624 of file CommonMethods.py.

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

Referenced by BeamSpotWorkflow.main().

624 def createWeightedPayloads(fileName,listbeam=[],weighted=True):
625  newlistbeam = []
626  tmpbeam = BeamSpot()
627  docreate = True
628  countlumi = 0
629  tmprun = ""
630  maxNlumis = 60
631  if weighted:
632  maxNlumis = 999999999
633  for ii in range(0,len(listbeam)):
634  ibeam = listbeam[ii]
635  inextbeam = BeamSpot()
636  iNNbeam = BeamSpot()
637  if docreate:
638  tmpbeam.IOVfirst = ibeam.IOVfirst
639  tmpbeam.IOVBeginTime = ibeam.IOVBeginTime
640  tmpbeam.Run = ibeam.Run
641  tmpbeam.Type = 2
642  docheck = False
643  docreate = False
644  #print "Currently testing ii="+str(ii)+" Lumi1: "+str(ibeam.IOVfirst)
645 
646  # check last iov
647  if ii < len(listbeam) - 1:
648  inextbeam = listbeam[ii+1]
649  docheck = True
650  if ii < len(listbeam) -2:
651  iNNbeam = listbeam[ii+2]
652  else:
653  print("close payload because end of data has been reached. Run "+ibeam.Run)
654  docreate = True
655  # check we run over the same run
656  if ibeam.Run != inextbeam.Run:
657  print("close payload because end of run "+ibeam.Run)
658  docreate = True
659  # check maximum lumi counts
660  if countlumi == maxNlumis -1:
661  print("close payload because maximum lumi sections accumulated within run "+ibeam.Run)
662  docreate = True
663  countlumi = 0
664  # weighted average position
665  (tmpbeam.X, tmpbeam.Xerr) = weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
666  (tmpbeam.Y, tmpbeam.Yerr) = weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
667  (tmpbeam.Z, tmpbeam.Zerr) = weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
668  (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) = weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
669  (tmpbeam.dxdz, tmpbeam.dxdzerr) = weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
670  (tmpbeam.dydz, tmpbeam.dydzerr) = weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
671  #print "wx = " + ibeam.beamWidthX + " err= "+ ibeam.beamWidthXerr
672  (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) = weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
673  (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) = weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
674 
675  if weighted:
676  docheck = False
677  # check offsets
678  #if False:
679  if docheck:
680 
681  # define minimum limit
682  min_limit = 0.0025
683 
684  # limit for x and y
685  limit = float(ibeam.beamWidthX)/2.
686  if limit < min_limit: limit = min_limit
687 
688  # check movements in X
689  adelta1 = delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr)
690  adelta2 = (0.,1.e9)
691  adelta1dxdz = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
692  adelta2dxdz = (0.,1.e9)
693  adelta1dydz = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
694  adelta2dydz = (0.,1.e9)
695  adelta1widthx = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
696  adelta2widthx = (0.,1.e9)
697  adelta1widthy = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
698  adelta2widthy = (0.,1.e9)
699  adelta1z0 = delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr)
700  adelta1sigmaZ = delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr)
701 
702  if iNNbeam.Type != -1:
703  adelta2 = delta(inextbeam.X, inextbeam.Xerr, iNNbeam.X, iNNbeam.Xerr)
704  adelta2dxdz = delta(inextbeam.dxdz, inextbeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr)
705  adelta2dydz = delta(inextbeam.dydz, inextbeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr)
706  adelta2widthx = delta(inextbeam.beamWidthX, inextbeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr)
707  adelta2widthy = delta(inextbeam.beamWidthY, inextbeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr)
708 
709  deltaX = deltaSig(adelta1) > 3.5 and adelta1[0] >= limit
710  if ii < len(listbeam) -2:
711  if deltaX==False and adelta1[0]*adelta2[0] > 0. and math.fabs(adelta1[0]+adelta2[0]) >= limit:
712  #print " positive, "+str(adelta1[0]+adelta2[0])+ " limit="+str(limit)
713  deltaX = True
714  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:
715  deltaX = False
716  #print " negative, "+str(adelta1[0]/adelta2[0])
717  #else:
718  # print str(adelta1[0]/adelta2[0])
719 
720  # check movemnts in Y
721  adelta1 = delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr)
722  adelta2 = (0.,1.e9)
723  if iNNbeam.Type != -1:
724  adelta2 = delta(inextbeam.Y, inextbeam.Yerr, iNNbeam.Y, iNNbeam.Yerr)
725 
726  deltaY = deltaSig(adelta1) > 3.5 and adelta1[0] >= limit
727  if ii < len(listbeam) -2:
728  if deltaY==False and adelta1[0]*adelta2[0] > 0. and math.fabs(adelta1[0]+adelta2[0]) >= limit:
729  deltaY = True
730  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:
731  deltaY = False
732  # check movements in Z
733 
734  limit = float(ibeam.sigmaZ)/2.
735  deltaZ = deltaSig(adelta1z0) > 3.5 and math.fabs(adelta1z0[0]) >= limit
736 
737  deltasigmaZ = deltaSig(adelta1sigmaZ) > 5.0
738 
739  # check dxdz
740  adelta = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
741  deltadxdz = deltaSig(adelta) > 5.0
742  if deltadxdz and adelta1dxdz[0]*adelta2dxdz[0]<=0 and adelta2dxdz[0] != 0 and math.fabs(adelta1dxdz[0]/adelta2dxdz[0]) > 0.33 and math.fabs(adelta1dxdz[0]/adelta2dxdz[0]) < 3:
743  deltadxdz = False
744  # check dydz
745  adelta = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
746  deltadydz = deltaSig(adelta) > 5.0
747  if deltadydz and adelta1dydz[0]*adelta2dydz[0]<=0 and adelta2dydz[0] != 0 and math.fabs(adelta1dydz[0]/adelta2dydz[0]) > 0.33 and math.fabs(adelta1dydz[0]/adelta2dydz[0]) < 3:
748  deltadydz = False
749 
750  adelta = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
751  deltawidthX = deltaSig(adelta) > 5
752  if deltawidthX and adelta1widthx[0]*adelta2widthx[0]<=0 and adelta2widthx[0] != 0 and math.fabs(adelta1widthx[0]/adelta2widthx[0]) > 0.33 and math.fabs(adelta1widthx[0]/adelta2widthx[0]) < 3:
753  deltawidthX = False
754 
755  adelta = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
756  deltawidthY = deltaSig(adelta) > 5
757  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:
758  deltawidthY = False
759  #if iNNbeam.Type != -1:
760  # deltaX = deltaX and delta(ibeam.X, ibeam.Xerr, iNNbeam.X, iNNbeam.Xerr) > 1.5
761  # deltaY = deltaY and delta(ibeam.Y, ibeam.Yerr, iNNbeam.Y, iNNbeam.Yerr) > 1.5
762  # deltaZ = deltaZ and delta(ibeam.Z, ibeam.Zerr, iNNbeam.Z, iNNbeam.Zerr) > 1.5
763  #
764  # deltasigmaZ = deltasigmaZ and delta(ibeam.sigmaZ, ibeam.sigmaZerr, iNNbeam.sigmaZ, iNNbeam.sigmaZerr) > 2.5
765  # deltadxdz = deltadxdz and delta(ibeam.dxdz, ibeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr) > 2.5
766  # deltadydz = deltadydz and delta(ibeam.dydz, ibeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr) > 2.5
767  #
768  # deltawidthX = deltawidthX and delta(ibeam.beamWidthX, ibeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr) > 3
769  # deltawidthY = deltawidthY and delta(ibeam.beamWidthY, ibeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr) > 3
770 
771  if deltaX or deltaY or deltaZ or deltasigmaZ or deltadxdz or deltadydz or deltawidthX or deltawidthY:
772  docreate = True
773  #print "shift here: x="+str(deltaX)+" y="+str(deltaY)
774  #print "x1 = "+ibeam.X + " x1err = "+ibeam.Xerr
775  #print "x2 = "+inextbeam.X + " x2err = "+inextbeam.Xerr
776  #print "Lumi1: "+str(ibeam.IOVfirst) + " Lumi2: "+str(inextbeam.IOVfirst)
777  #print " x= "+ibeam.X+" +/- "+ibeam.Xerr
778  #print "weighted average x = "+tmpbeam.X +" +//- "+tmpbeam.Xerr
779  print("close payload because of movement in X= "+str(deltaX)+", Y= "+str(deltaY) + ", Z= "+str(deltaZ)+", sigmaZ= "+str(deltasigmaZ)+", dxdz= "+str(deltadxdz)+", dydz= "+str(deltadydz)+", widthX= "+str(deltawidthX)+", widthY= "+str(deltawidthY))
780  if docreate:
781  #if ii == len(listbeam)-1:
782  tmpbeam.IOVlast = ibeam.IOVlast
783  tmpbeam.IOVEndTime = ibeam.IOVEndTime
784  print(" Run: "+tmpbeam.Run +" Lumi1: "+str(tmpbeam.IOVfirst) + " Lumi2: "+str(tmpbeam.IOVlast))
785  newlistbeam.append(tmpbeam)
786  tmpbeam = BeamSpot()
787  countlumi = 0
788  tmprun = ibeam.Run
789  countlumi += 1
790 
791  payloadfile = open(fileName,"w")
792  for iload in newlistbeam:
793  dump( iload, payloadfile )
794  payloadfile.close()
795  return newlistbeam
Definition: weight.py:1
def createWeightedPayloads(fileName, listbeam=[], weighted=True)
CREATE FILE FOR PAYLOADS.
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def delta(x, xerr, nextx, nextxerr)
def dump(beam, file)
#define str(s)

◆ createWeightedPayloadsNew()

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

Definition at line 797 of file CommonMethods.py.

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

797 def createWeightedPayloadsNew(fileName,listbeam=[],weighted=True):
798  newlistbeam = []
799  docreate = False
800  docheck = False
801  lastPayload = listbeam[0]
802 
803  firstToUse = 0
804  lastToUse = 0
805  for ii in range(0,len(listbeam)):
806  docreate = False
807  if docheck:
808  deltaX = delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr) > 1.5
809  deltaY = delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr) > 1.5
810  deltaZ = delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr) > 2.5
811 
812  deltasigmaZ = delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr) > 2.5
813  deltadxdz = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr) > 2.5
814  deltadydz = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr) > 2.5
815 
816  deltawidthX = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr) > 3
817  deltawidthY = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr) > 3
818 
819  #if iNNbeam.Type != -1:
820  # deltaX = deltaX and delta(ibeam.X, ibeam.Xerr, iNNbeam.X, iNNbeam.Xerr) > 1.5
821  # deltaY = deltaY and delta(ibeam.Y, ibeam.Yerr, iNNbeam.Y, iNNbeam.Yerr) > 1.5
822  # deltaZ = deltaZ and delta(ibeam.Z, ibeam.Zerr, iNNbeam.Z, iNNbeam.Zerr) > 1.5
823  #
824  # deltasigmaZ = deltasigmaZ and delta(ibeam.sigmaZ, ibeam.sigmaZerr, iNNbeam.sigmaZ, iNNbeam.sigmaZerr) > 2.5
825  # deltadxdz = deltadxdz and delta(ibeam.dxdz, ibeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr) > 2.5
826  # deltadydz = deltadydz and delta(ibeam.dydz, ibeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr) > 2.5
827  #
828  # deltawidthX = deltawidthX and delta(ibeam.beamWidthX, ibeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr) > 3
829  # deltawidthY = deltawidthY and delta(ibeam.beamWidthY, ibeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr) > 3
830 
831  if deltaX or deltaY or deltaZ or deltasigmaZ or deltadxdz or deltadydz or deltawidthX or deltawidthY:
832  if ii != 0:
833  docreate = True
834  lastToUse = ii-1
835  #print "shift here: x="+str(deltaX)+" y="+str(deltaY)
836  #print "x1 = "+ibeam.X + " x1err = "+ibeam.Xerr
837  #print "x2 = "+inextbeam.X + " x2err = "+inextbeam.Xerr
838  #print "Lumi1: "+str(ibeam.IOVfirst) + " Lumi2: "+str(inextbeam.IOVfirst)
839  #print " x= "+ibeam.X+" +/- "+ibeam.Xerr
840  #print "weighted average x = "+tmpbeam.X +" +//- "+tmpbeam.Xerr
841  print("close payload because of movement in X= "+str(deltaX)+", Y= "+str(deltaY) + ", Z= "+str(deltaZ)+", sigmaZ= "+str(deltasigmaZ)+", dxdz= "+str(deltadxdz)+", dydz= "+str(deltadydz)+", widthX= "+str(deltawidthX)+", widthY= "+str(deltawidthY))
842 
843  #WARNING this will only be fine for Run based IOVs
844  if ii >= len(listbeam) - 1 or listbeam[ii].Run != listbeam[ii+1].Run :
845  print("close payload because end of run has been reached. Run " + listbeam[ii].Run)
846  docreate = True
847  lastToUse = ii
848 
849 
850  # check maximum lumi counts
851 #? if countlumi == maxNlumis:
852 #? print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
853 #? docreate = True
854 #? countlumi = 0
855  if docreate:
856  tmpbeam = BeamSpot()
857  for ibeam in listbeam[firstToUse:lastToUse]:
858  (tmpbeam.X, tmpbeam.Xerr) = weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
859  (tmpbeam.Y, tmpbeam.Yerr) = weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
860  (tmpbeam.Z, tmpbeam.Zerr) = weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
861  (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) = weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
862  (tmpbeam.dxdz, tmpbeam.dxdzerr) = weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
863  (tmpbeam.dydz, tmpbeam.dydzerr) = weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
864  #print "wx = " + ibeam.beamWidthX + " err= "+ ibeam.beamWidthXerr
865  (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) = weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
866  (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) = weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
867  tmpbeam.IOVfirst = listbeam[firstToUse].IOVfirst
868  tmpbeam.IOVBeginTime = listbeam[firstToUse].IOVBeginTime
869  tmpbeam.Run = listbeam[firstToUse].Run
870  tmpbeam.Type = 2
871  tmpbeam.IOVlast = listbeam[lastToUse].IOVlast
872  tmpbeam.IOVEndTime = listbeam[lastToUse].IOVEndTime
873  newlistbeam.append(tmpbeam)
874  firstToUse = lastToUse+1
875  print("Run: " + tmpbeam.Run + " Lumi1: " + str(tmpbeam.IOVfirst) + " Lumi2: " + str(tmpbeam.IOVlast))
876 
877  payloadfile = open(fileName,"w")
878  for iload in newlistbeam:
879  dump( iload, payloadfile )
880  payloadfile.close()
881 
Definition: weight.py:1
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def delta(x, xerr, nextx, nextxerr)
def dump(beam, file)
#define str(s)
def createWeightedPayloadsNew(fileName, listbeam=[], weighted=True)

◆ delta()

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

Definition at line 323 of file CommonMethods.py.

References dqmMemoryStats.float.

Referenced by createWeightedPayloads(), and createWeightedPayloadsNew().

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

◆ deltaSig()

def CommonMethods.deltaSig (   x)

Definition at line 327 of file CommonMethods.py.

Referenced by createWeightedPayloads().

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

◆ dirExists()

def CommonMethods.dirExists (   dir)

Definition at line 159 of file CommonMethods.py.

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

◆ dump()

def CommonMethods.dump (   beam,
  file 
)

Definition at line 291 of file CommonMethods.py.

References dumpValues(), and str.

Referenced by createWeightedPayloads(), and createWeightedPayloadsNew().

291 def dump( beam, file):
292  end = "\n"
293  file.write("Runnumber "+beam.Run+end)
294  file.write("BeginTimeOfFit "+str(beam.IOVBeginTime)+end)
295  file.write("EndTimeOfFit "+str(beam.IOVEndTime)+end)
296  file.write("LumiRange "+str(beam.IOVfirst)+" - "+str(beam.IOVlast)+end)
297  dumpValues(beam, file)
298 
def dumpValues(beam, file)
def dump(beam, file)
#define str(s)

◆ dumpValues()

def CommonMethods.dumpValues (   beam,
  file 
)

Definition at line 300 of file CommonMethods.py.

References dqmMemoryStats.float, and str.

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

300 def dumpValues( beam, file):
301  end = "\n"
302  file.write("Type "+str(beam.Type)+end)
303  file.write("X0 "+str(beam.X)+end)
304  file.write("Y0 "+str(beam.Y)+end)
305  file.write("Z0 "+str(beam.Z)+end)
306  file.write("sigmaZ0 "+str(beam.sigmaZ)+end)
307  file.write("dxdz "+str(beam.dxdz)+end)
308  file.write("dydz "+str(beam.dydz)+end)
309  file.write("BeamWidthX "+beam.beamWidthX+end)
310  file.write("BeamWidthY "+beam.beamWidthY+end)
311  file.write("Cov(0,j) "+str(math.pow(float(beam.Xerr),2))+" 0 0 0 0 0 0" +end)
312  file.write("Cov(1,j) 0 "+str(math.pow(float(beam.Yerr),2))+" 0 0 0 0 0" +end)
313  file.write("Cov(2,j) 0 0 "+str(math.pow(float(beam.Zerr),2))+" 0 0 0 0" +end)
314  file.write("Cov(3,j) 0 0 0 "+str(math.pow(float(beam.sigmaZerr),2))+" 0 0 0" +end)
315  file.write("Cov(4,j) 0 0 0 0 "+str(math.pow(float(beam.dxdzerr),2))+" 0 0" +end)
316  file.write("Cov(5,j) 0 0 0 0 0 "+str(math.pow(float(beam.dydzerr),2))+" 0" +end)
317  file.write("Cov(6,j) 0 0 0 0 0 0 "+str(math.pow(float(beam.beamWidthXerr),2)) +end)
318  file.write("EmittanceX 0"+end)
319  file.write("EmittanceY 0"+end)
320  file.write("BetaStar 0"+end)
321 
def dumpValues(beam, file)
#define str(s)

◆ exit()

def CommonMethods.exit (   msg = "")

Definition at line 92 of file CommonMethods.py.

References rmLock().

Referenced by ls().

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

◆ isnan()

def CommonMethods.isnan (   num)

◆ lock()

def CommonMethods.lock ( )

Definition at line 81 of file CommonMethods.py.

Referenced by evf::FastMonitoringService.accumulateFileSize(), cms::alpakatools::CachingAllocator< TDev, TQueue, typename >.allocateNewBlock(), cond::service::PoolDBOutputService.appendOneIOV(), cond::service::PoolDBOutputService.appendSinceTime(), dqm::DQMFileSaverOnline.appendSnapshot(), DQMEDAnalyzer.beginStream(), mxnet::cpp::Predictor.bind_executor(), cscdqm::Collection.book(), dqm::implementation::DQMStore.bookTransaction(), cms::alpakatools::CachingAllocator< TDev, TQueue, typename >.cacheStatus(), cscdqm::EventProcessor.calcEMUFractionHisto(), CAHitNtupletGeneratorKernelsCPU< TrackerTraits >.classifyTuples(), dqm::implementation::DQMStore.cleanupLumi(), cond::service::PoolDBOutputService.closeIOV(), cond::persistency::SessionImpl.commitTransaction(), cond::service::PoolDBOutputService.commitTransaction(), XrdAdaptor::XrdStatisticsService.condorUpdate(), lumi::service::DBService.connectReadOnly(), edm::shared_memory::ControllerChannel.continueWait(), cond::service::PoolDBOutputService.createNewIOV(), cond::service::PoolDBOutputService.createOneIOV(), cond::XMLAuthenticationService::XMLAuthenticationService.credentials(), edm::shared_memory::ControllerChannel.doTransition(), edm::shared_memory::ControllerChannel.doTransitionWithRetry(), dqm::implementation::DQMStore.enterLumi(), cond::service::PoolDBOutputService.eraseSinceTime(), TMVAEvaluator.evaluateTMVA(), CSCMonitorObject.Fill(), dqm::implementation::DQMStore.findME(), dqm::implementation::DQMStore.findOrRecycle(), cond::service::PoolDBOutputService.forceInit(), cms::alpakatools::CachingAllocator< TDev, TQueue, typename >.free(), cms::alpakatools::CachingAllocator< TDev, TQueue, typename >.freeAllCached(), 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(), evf::FastMonitoringService.isExceptionOnData(), cond::service::PoolDBOutputService.isNewTagRequest(), dqm::implementation::DQMStore.leaveLumi(), cond::service::PoolDBOutputService.lockRecords(), BeamSpotWorkflow.main(), dqm::implementation::DQMStore.meBookerGetter(), DQMNet.onPeerConnect(), DQMNet.onPeerData(), edm::JobReport.outputFileClosed(), 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.reportMemoryInfo(), edm::JobReport.reportMessageInfo(), edm::JobReport.reportRandomStateFile(), edm::JobReport.reportReadBranches(), edm::JobReport.reportSkippedEvent(), edm::JobReport.reportSkippedFile(), cond::persistency::SessionImpl.rollbackTransaction(), CSCMonitorObject.SetAxisRange(), CSCMonitorObject.setAxisTitle(), CSCMonitorObject.SetBinContent(), CSCMonitorObject.SetBinError(), CSCMonitorObject.SetEntries(), evf::FastMonitoringService.setExceptionDetected(), CSCMonitorObject.SetMaximum(), CSCMonitorObject.SetNormFactor(), edm::shared_memory::ControllerChannel.setupWorker(), edm::shared_memory::ControllerChannel.setupWorkerWithRetry(), 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(), cms::alpakatools::CachingAllocator< TDev, TQueue, typename >.tryReuseCachedBlock(), cscdqm::EventProcessor.updateEfficiencyHistos(), cscdqm::EventProcessorMutex.updateFractionAndEfficiencyHistos(), cscdqm::Dispatcher.updateFractionAndEfficiencyHistos(), cscdqm::EventProcessor.updateFractionHistos(), cond::service::PoolDBOutputService.writeMany(), cond::service::PoolDBOutputService.writeOneIOV(), cscdqm::EventProcessor.writeShifterHistograms(), and cms::alpakatools::CachingAllocator< TDev, TQueue, typename >.~CachingAllocator().

81 def lock():
82  global lockFile
83  subprocess.getstatusoutput( "touch " + lockFile)
84 

◆ ls()

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

Definition at line 168 of file CommonMethods.py.

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

168 def ls(dir,filter=""):
169  lsCommand = ''
170  listOfFiles = []
171  if dir.find('castor') != -1:
172  lsCommand = 'ns'
173  elif not os.path.exists(dir):
174  print("ERROR: File or directory " + dir + " doesn't exist")
175  return listOfFiles
176 
177  aCommand = lsCommand + 'ls '+ dir
178  #aCommand = lsCommand + 'ls '+ dir + " | grep .txt"
179  if filter != "":
180  aCommand += " | grep " + filter
181 
182  tmpStatus = subprocess.getstatusoutput( aCommand )
183  listOfFiles = tmpStatus[1].split('\n')
184  if len(listOfFiles) == 1:
185  if listOfFiles[0].find('No such file or directory') != -1:
186  exit("ERROR: File or directory " + dir + " doesn't exist")
187 
188  return listOfFiles
189 
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:19
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ nonzero()

def CommonMethods.nonzero (   self)

Definition at line 131 of file CommonMethods.py.

References contentValuesCheck.values.

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

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

229 def pack(high,low):
230  """pack high,low 32bit unsigned int to one unsigned 64bit long long
231  Note:the print value of result number may appear signed, if the sign bit is used.
232  """
233  h=high<<32
234  return (h|low)
235 
def pack(high, low)
lumi tools CondCore/Utilities/python/timeUnitHelper.py

◆ parse()

def CommonMethods.parse (   docstring,
  arglist = None 
)

Definition at line 107 of file CommonMethods.py.

107 def parse(docstring, arglist=None):
108  global optionstring
109  global tagType
110  optionstring = docstring
111  match = USAGE.search(optionstring)
112  if not match: raise ParsingError("Cannot find the option string")
113  optlines = match.group(1).splitlines()
114  try:
115  p = optparse.OptionParser(optlines[0])
116  for line in optlines[1:]:
117  opt, help=line.split(':')[:2]
118  short,long=opt.split(',')[:2]
119  if '=' in opt:
120  action='store'
121  long=long.split('=')[0]
122  else:
123  action='store_true'
124  p.add_option(short.strip(),long.strip(),
125  action = action, help = help.strip())
126  except (IndexError,ValueError):
127  raise ParsingError("Cannot parse the option string correctly")
128  return p.parse_args(arglist)
129 
vector< string > parse(string line, const string &delimiter)

◆ readBeamSpotFile()

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

Definition at line 331 of file CommonMethods.py.

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

Referenced by BeamSpotWorkflow.main().

331 def readBeamSpotFile(fileName,listbeam=[],IOVbase="runbase", firstRun='1',lastRun='4999999999'):
332  tmpbeam = BeamSpot()
333  tmpbeamsize = 0
334 
335  #firstRun = "1"
336  #lastRun = "4999999999"
337  if IOVbase == "lumibase" and firstRun=='1' and lastRun=='4999999999' :
338  firstRun = "1:1"
339  lastRun = "4999999999:4999999999"
340 
341  inputfiletype = 0
342  #print "first = " +firstRun
343  #print "last = " +lastRun
344 
345  # for bx
346  maplist = {}
347  hasBX = False
348 
349  tmpfile = open(fileName)
350  atmpline = tmpfile.readline()
351  if atmpline.find('Runnumber') != -1:
352  inputfiletype = 1
353  if len(atmpline.split()) > 2:
354  hasBX = True
355  print(" Input data has been calculated as function of BUNCH CROSSINGS.")
356  tmpfile.seek(0)
357 
358 
359  if inputfiletype ==1:
360 
361  tmpBX = 0
362  for line in tmpfile:
363 
364  if line.find('Type') != -1:
365  tmpbeam.Type = int(line.split()[1])
366  tmpbeamsize += 1
367  if line.find('X0') != -1:
368  tmpbeam.X = line.split()[1]
369  #tmpbeam.Xerr = line.split()[4]
370  tmpbeamsize += 1
371  #print " x = " + str(tmpbeam.X)
372  if line.find('Y0') != -1:
373  tmpbeam.Y = line.split()[1]
374  #tmpbeam.Yerr = line.split()[4]
375  tmpbeamsize += 1
376  #print " y =" + str(tmpbeam.Y)
377  if line.find('Z0') != -1 and line.find('sigmaZ0') == -1:
378  tmpbeam.Z = line.split()[1]
379  #tmpbeam.Zerr = line.split()[4]
380  tmpbeamsize += 1
381  if line.find('sigmaZ0') !=-1:
382  tmpbeam.sigmaZ = line.split()[1]
383  #tmpbeam.sigmaZerr = line.split()[5]
384  tmpbeamsize += 1
385  if line.find('dxdz') != -1:
386  tmpbeam.dxdz = line.split()[1]
387  #tmpbeam.dxdzerr = line.split()[4]
388  tmpbeamsize += 1
389  if line.find('dydz') != -1:
390  tmpbeam.dydz = line.split()[1]
391  #tmpbeam.dydzerr = line.split()[4]
392  tmpbeamsize += 1
393  if line.find('BeamWidthX') != -1:
394  tmpbeam.beamWidthX = line.split()[1]
395  #tmpbeam.beamWidthXerr = line.split()[6]
396  tmpbeamsize += 1
397  if line.find('BeamWidthY') != -1:
398  tmpbeam.beamWidthY = line.split()[1]
399  #tmpbeam.beamWidthYerr = line.split()[6]
400  tmpbeamsize += 1
401  if line.find('Cov(0,j)') != -1:
402  tmpbeam.Xerr = str(math.sqrt( float( line.split()[1] ) ) )
403  tmpbeamsize += 1
404  if line.find('Cov(1,j)') != -1:
405  tmpbeam.Yerr = str(math.sqrt( float( line.split()[2] ) ) )
406  tmpbeamsize += 1
407  if line.find('Cov(2,j)') != -1:
408  tmpbeam.Zerr = str(math.sqrt( float( line.split()[3] ) ) )
409  tmpbeamsize += 1
410  if line.find('Cov(3,j)') != -1:
411  tmpbeam.sigmaZerr = str(math.sqrt( float( line.split()[4] ) ) )
412  tmpbeamsize += 1
413  if line.find('Cov(4,j)') != -1:
414  tmpbeam.dxdzerr = str(math.sqrt( float( line.split()[5] ) ) )
415  tmpbeamsize += 1
416  if line.find('Cov(5,j)') != -1:
417  tmpbeam.dydzerr = str(math.sqrt( float( line.split()[6] ) ) )
418  tmpbeamsize += 1
419  if line.find('Cov(6,j)') != -1:
420  tmpbeam.beamWidthXerr = str(math.sqrt( float( line.split()[7] ) ) )
421  tmpbeam.beamWidthYerr = tmpbeam.beamWidthXerr
422  tmpbeamsize += 1
423  if line.find('LumiRange') != -1:
424  if IOVbase=="lumibase":
425  tmpbeam.IOVfirst = line.split()[1]
426  tmpbeam.IOVlast = line.split()[3]
427  tmpbeamsize += 1
428  if line.find('Runnumber') != -1:
429  tmpbeam.Run = line.split()[1]
430  if IOVbase == "runbase":
431  tmpbeam.IOVfirst = line.split()[1]
432  tmpbeam.IOVlast = line.split()[1]
433  if hasBX:
434  tmpBX = line.split()[3]
435  tmpbeamsize += 1
436  if line.find('BeginTimeOfFit') != -1:
437  tmpbeam.IOVBeginTime = line.split()[1] +" "+line.split()[2] +" "+line.split()[3]
438  if IOVbase =="timebase":
439  tmpbeam.IOVfirst = time.mktime( time.strptime(line.split()[1] + " " + line.split()[2] + " " + line.split()[3],"%Y.%m.%d %H:%M:%S %Z") )
440  tmpbeamsize += 1
441  if line.find('EndTimeOfFit') != -1:
442  tmpbeam.IOVEndTime = line.split()[1] +" "+line.split()[2] +" "+line.split()[3]
443  if IOVbase =="timebase":
444  tmpbeam.IOVlast = time.mktime( time.strptime(line.split()[1] + " " + line.split()[2] + " " + line.split()[3],"%Y.%m.%d %H:%M:%S %Z") )
445  tmpbeamsize += 1
446  if tmpbeamsize == 20:
447  if IOVbase=="lumibase":
448  tmprunfirst = int(firstRun.split(":")[0])
449  tmprunlast = int(lastRun.split(":")[0])
450  tmplumifirst = int(firstRun.split(":")[1])
451  tmplumilast = int(lastRun.split(":")[1])
452  acceptiov1 = acceptiov2 = False
453  # check lumis in the same run
454  if tmprunfirst == tmprunlast and int(tmpbeam.Run)==tmprunfirst:
455  if int(tmpbeam.IOVfirst) >= tmplumifirst and int(tmpbeam.IOVlast)<=tmplumilast:
456  acceptiov1 = acceptiov2 = True
457  # if different runs make sure you select the correct range of lumis
458  elif int(tmpbeam.Run) == tmprunfirst:
459  if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 = True
460  elif int(tmpbeam.Run) == tmprunlast:
461  if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 = True
462  elif tmprunfirst <= int(tmpbeam.Run) and tmprunlast >= int(tmpbeam.Run):
463  acceptiov1 = acceptiov2 = True
464 
465  if acceptiov1 and acceptiov2:
466  if tmpbeam.Type != 2:
467  print("invalid fit, skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast))
468  elif isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
469  print("invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast))
470  elif hasBX:
471  if (tmpBX in maplist) == False:
472  maplist[tmpBX] = [tmpbeam]
473  else:
474  maplist[tmpBX].append(tmpbeam)
475  else:
476  listbeam.append(tmpbeam)
477 
478  elif int(tmpbeam.IOVfirst) >= int(firstRun) and int(tmpbeam.IOVlast) <= int(lastRun):
479  if tmpbeam.Type != 2:
480  print("invalid fit, skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast))
481  elif isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
482  print("invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast))
483  else:
484  listbeam.append(tmpbeam)
485 
486  tmpbeamsize = 0
487  tmpbeam = BeamSpot()
488  tmpBX = 0
489  else:
490 
491  for line in tmpfile:
492 
493  if line.find('X0') != -1:
494  tmpbeam.X = line.split()[2]
495  tmpbeam.Xerr = line.split()[4]
496  tmpbeamsize += 1
497  #print " x = " + str(tmpbeam.X)
498  if line.find('Y0') != -1:
499  tmpbeam.Y = line.split()[2]
500  tmpbeam.Yerr = line.split()[4]
501  tmpbeamsize += 1
502  #print " y =" + str(tmpbeam.Y)
503  if line.find('Z0') != -1 and line.find('Sigma Z0') == -1:
504  tmpbeam.Z = line.split()[2]
505  tmpbeam.Zerr = line.split()[4]
506  tmpbeamsize += 1
507  #print " z =" + str(tmpbeam.Z)
508  if line.find('Sigma Z0') !=-1:
509  tmpbeam.sigmaZ = line.split()[3]
510  tmpbeam.sigmaZerr = line.split()[5]
511  tmpbeamsize += 1
512  if line.find('dxdz') != -1:
513  tmpbeam.dxdz = line.split()[2]
514  tmpbeam.dxdzerr = line.split()[4]
515  tmpbeamsize += 1
516  if line.find('dydz') != -1:
517  tmpbeam.dydz = line.split()[2]
518  tmpbeam.dydzerr = line.split()[4]
519  tmpbeamsize += 1
520  if line.find('Beam Width X') != -1:
521  tmpbeam.beamWidthX = line.split()[4]
522  tmpbeam.beamWidthXerr = line.split()[6]
523  tmpbeamsize += 1
524  if line.find('Beam Width Y') != -1:
525  tmpbeam.beamWidthY = line.split()[4]
526  tmpbeam.beamWidthYerr = line.split()[6]
527  tmpbeamsize += 1
528  #if line.find('Run ') != -1:
529  if line.find('for runs') != -1:
530  #tmpbeam.IOVfirst = line.split()[6].strip(',')
531  tmpbeam.Run = line.split()[2]
532  if IOVbase == "runbase":
533  tmpbeam.IOVfirst = line.split()[2]
534  tmpbeam.IOVlast = line.split()[4]
535  tmpbeamsize += 1
536  if line.find('LumiSection') != -1:
537  if IOVbase=="lumibase":
538  tmpbeam.IOVfirst = line.split()[10]
539  tmpbeam.IOVlast = line.split()[10]
540  tmpbeamsize += 1
541  if tmpbeamsize == 10:
542 
543  if IOVbase=="lumibase":
544  tmprunfirst = int(firstRun.split(":")[0])
545  tmprunlast = int(lastRun.split(":")[0])
546  tmplumifirst = int(firstRun.split(":")[1])
547  tmplumilast = int(lastRun.split(":")[1])
548  acceptiov1 = acceptiov2 = False
549  # check lumis in the same run
550  if tmprunfirst == tmprunlast and int(tmpbeam.Run)==tmprunfirst:
551  if int(tmpbeam.IOVfirst) >= tmplumifirst and int(tmpbeam.IOVlast)<=tmplumilast:
552  acceptiov1 = acceptiov2 = True
553  # if different runs make sure you select the correct range of lumis
554  elif int(tmpbeam.Run) == tmprunfirst:
555  if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 = True
556  elif int(tmpbeam.Run) == tmprunlast:
557  if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 = True
558  elif tmprunfirst <= int(tmpbeam.Run) and tmprunlast >= int(tmpbeam.Run):
559  acceptiov1 = acceptiov2 = True
560 
561  if acceptiov1 and acceptiov2:
562  if isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
563  print("invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast))
564  elif hasBX:
565  if (tmpBX in maplist) == False:
566  maplist[tmpBX] = [tmpbeam]
567  else:
568  maplist[tmpBX].append(tmpbeam)
569  else:
570  listbeam.append(tmpbeam)
571 
572  elif int(tmpbeam.IOVfirst) >= int(firstRun) and int(tmpbeam.IOVlast) <= int(lastRun):
573  if isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
574  print("invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast))
575  else:
576  listbeam.append(tmpbeam)
577 
578  tmpbeamsize = 0
579  tmpbeam = BeamSpot()
580  tmpBX = 0
581 
582  tmpfile.close()
583  print(" got total number of IOVs = " + str(len(listbeam)) + " from file " + fileName)
584  #print " run " + str(listbeam[3].IOVfirst ) + " " + str( listbeam[3].X )
585  if hasBX:
586  return maplist
587  else:
588  return listbeam
589 
def isnan(num)
def readBeamSpotFile(fileName, listbeam=[], IOVbase="runbase", firstRun='1', lastRun='4999999999')
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)

◆ readSqliteFile()

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

Definition at line 907 of file CommonMethods.py.

References print().

Referenced by BeamSpotWorkflow.main().

907 def readSqliteFile(sqliteFileName,tagName,sqliteTemplateFile,tmpDir="/tmp/"):
908  readDBOut = tmpDir + "readDB_" + tagName + ".py"
909 
910  rFile = open(sqliteTemplateFile)
911  rNewFile = open(readDBOut,'w')
912 
913  readDBTags = [('SQLITEFILE','sqlite_file:' + sqliteFileName),
914  ('TAGNAME',tagName)]
915 
916  for line in rFile:
917  for itag in readDBTags:
918  line = line.replace(itag[0],itag[1])
919  rNewFile.write(line)
920 
921  rNewFile.close()
922  status_rDB = subprocess.getstatusoutput('cmsRun '+ readDBOut)
923 
924  outtext = status_rDB[1]
925  print(outtext)
926  os.system("rm -f " + readDBOut)
927  return not status_rDB[0]
928 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def readSqliteFile(sqliteFileName, tagName, sqliteTemplateFile, tmpDir="/tmp/")

◆ rmLock()

def CommonMethods.rmLock ( )

Definition at line 86 of file CommonMethods.py.

References checkLock().

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

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

◆ sendEmail()

def CommonMethods.sendEmail (   mailList,
  error 
)

General utilities.

Definition at line 150 of file CommonMethods.py.

References print().

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

150 def sendEmail(mailList,error):
151  print("Sending email to " + mailList + " with body: " + error)
152  list = mailList.split(',')
153  for email in list:
154  p = os.popen("mail -s \"Automatic workflow error\" " + email ,"w")
155  p.write(error)
156  status = p.close()
157 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def sendEmail(mailList, error)
General utilities.

◆ setLockName()

def CommonMethods.setLockName (   name)

Definition at line 68 of file CommonMethods.py.

Referenced by BeamSpotWorkflow.main().

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

◆ sortAndCleanBeamList()

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

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

Definition at line 592 of file CommonMethods.py.

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

Referenced by BeamSpotWorkflow.main().

592 def sortAndCleanBeamList(listbeam=[],IOVbase="lumibase"):
593  # sort the list
594  if IOVbase == "lumibase":
595  listbeam.sort( cmp = cmp_list_lumi )
596  else:
597  listbeam.sort( cmp = cmp_list_run )
598 
599  # first clean list of data for consecutive duplicates and bad fits
600  tmpremovelist = []
601  for ii in range(0,len(listbeam)):
602  ibeam = listbeam[ii]
603  datax = ibeam.IOVfirst
604  #print str(ii) + " " +datax
605  if datax == '0' and IOVbase =="runbase":
606  print(" iov = 0? skip this IOV = "+ str(ibeam.IOVfirst) + " to " + str(ibeam.IOVlast))
607  tmpremovelist.append(ibeam)
608 
609  if ii < len(listbeam) -1:
610  #print listbeam[ii+1].IOVfirst
611  if IOVbase =="lumibase":
612  if ibeam.Run == listbeam[ii+1].Run and ibeam.IOVfirst == listbeam[ii+1].IOVfirst:
613  print(" duplicate IOV = "+datax+", keep only last duplicate entry")
614  tmpremovelist.append(ibeam)
615  elif datax == listbeam[ii+1].IOVfirst:
616  print(" duplicate IOV = "+datax+", keep only last duplicate entry")
617  tmpremovelist.append(ibeam)
618 
619  for itmp in tmpremovelist:
620  listbeam.remove(itmp)
621 
def sortAndCleanBeamList(listbeam=[], IOVbase="lumibase")
Sort and clean list of data for consecutive duplicates and bad fits.
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)

◆ timeoutManager()

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

Definition at line 10 of file CommonMethods.py.

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

Referenced by BeamSpotWorkflow.selectFilesToProcess().

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

◆ unpack()

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

Definition at line 237 of file CommonMethods.py.

References mathSSE.return().

Referenced by unpackLumiid().

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

◆ unpackLumiid()

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

Definition at line 245 of file CommonMethods.py.

References unpack().

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

◆ uploadSqliteFile()

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

Definition at line 938 of file CommonMethods.py.

References print().

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

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

◆ weight()

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

Definition at line 270 of file CommonMethods.py.

References dqmMemoryStats.float, and str.

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

◆ writeSqliteFile()

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

Definition at line 883 of file CommonMethods.py.

References print().

Referenced by BeamSpotWorkflow.main().

883 def writeSqliteFile(sqliteFileName,tagName,timeType,beamSpotFile,sqliteTemplateFile,tmpDir="/tmp/"):
884  writeDBOut = tmpDir + "write2DB_" + tagName + ".py"
885  wFile = open(sqliteTemplateFile)
886  wNewFile = open(writeDBOut,'w')
887 
888  writeDBTags = [('SQLITEFILE','sqlite_file:' + sqliteFileName),
889  ('TAGNAME',tagName),
890  ('TIMETYPE',timeType),
891  ('BEAMSPOTFILE',beamSpotFile)]
892 
893  for line in wFile:
894  for itag in writeDBTags:
895  line = line.replace(itag[0],itag[1])
896  wNewFile.write(line)
897 
898  wNewFile.close()
899  print("writing sqlite file ...")
900  status_wDB = subprocess.getstatusoutput('cmsRun '+ writeDBOut)
901  print(status_wDB[1])
902 
903  os.system("rm -f " + writeDBOut)
904  return not status_wDB[0]
905 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def writeSqliteFile(sqliteFileName, tagName, timeType, beamSpotFile, sqliteTemplateFile, tmpDir="/tmp/")

Variable Documentation

◆ __nonzero__

CommonMethods.__nonzero__
private

Definition at line 138 of file CommonMethods.py.

◆ lockFile

CommonMethods.lockFile

Definition at line 7 of file CommonMethods.py.

◆ USAGE

CommonMethods.USAGE

OPTIONS.

Definition at line 104 of file CommonMethods.py.