CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions | Variables
CommonMethods Namespace Reference

Classes

class  ParsingError
 

Functions

def appendSqliteFile
 
def checkLock
 
def cmp_list_lumi
 
def cmp_list_run
 end lumi tools More...
 
def cp
 
def createWeightedPayloads
 CREATE FILE FOR PAYLOADS. More...
 
def createWeightedPayloadsNew
 
def delta
 
def deltaSig
 
def dirExists
 
def dump
 
def dumpValues
 
def exit
 
def isnan
 
def lock
 
def ls
 
def nonzero
 
def pack
 lumi tools CondCore/Utilities/python/timeUnitHelper.py More...
 
def parse
 
def readBeamSpotFile
 
def readSqliteFile
 
def rmLock
 
def sendEmail
 General utilities. More...
 
def setLockName
 
def sortAndCleanBeamList
 Sort and clean list of data for consecutive duplicates and bad fits. More...
 
def timeoutManager
 
def unpack
 
def unpackLumiid
 
def uploadSqliteFile
 
def weight
 
def writeSqliteFile
 

Variables

string lockFile = ".lock"
 
tuple USAGE = re.compile(r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
 OPTIONS. More...
 

Function Documentation

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

Definition at line 929 of file CommonMethods.py.

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

930 def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill ,tmpDir="/tmp/"):
931  aCommand = "cmscond_export_iov -d sqlite_file:" + tmpDir + combinedSqliteFileName + " -s sqlite_file:" + sqliteFileName + " -i " + tagName + " -t " + tagName + " -l sqlite_file:" + tmpDir + "log.db" + " -b " + IOVSince + " -e " + IOVTill
932  print aCommand
933  std = commands.getstatusoutput(aCommand)
934  print std[1]
935  return not std[0]
def CommonMethods.checkLock ( )

Definition at line 71 of file CommonMethods.py.

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

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

Definition at line 259 of file CommonMethods.py.

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

end lumi tools

Definition at line 253 of file CommonMethods.py.

254 def cmp_list_run(a,b):
255  if int(a.IOVfirst) < int(b.IOVfirst): return -1
256  if int(a.IOVfirst) == int(b.IOVfirst): return 0
257  if int(a.IOVfirst) > int(b.IOVfirst): return 1
def cmp_list_run
end lumi tools
def CommonMethods.cp (   fromDir,
  toDir,
  listOfFiles,
  overwrite = False,
  smallList = False 
)

Definition at line 189 of file CommonMethods.py.

Referenced by CustomPhysicsList.addCustomPhysics(), PixelTrackBuilder.build(), HtrXmlPattern.do_hand_fill(), edm::RootFile.dropOnInput(), DTUserKeyedConfigHandler.DTUserKeyedConfigHandler(), pftools::Exercises3.evaluateCalibrator(), HtrXmlPatternTool.Fill(), edm::RootOutputFile.fillBranches(), L1GtVhdlWriterCore.getCaloSetupContentFromTriggerMenu(), L1GtVhdlWriterCore.getMuonSetupContentFromTriggerMenu(), edm::RootDelayedReader.getProduct_(), copyAndRename.main(), copyFromCastor.main(), rename.main(), copyFiles.main(), splitter.main(), BeamSpotWorkflow.main(), PreshowerClusterAlgo.makeOneCluster(), InclusiveVertexFinder.nearTracks(), DDStreamer.pos_read(), Strip1DMeasurementTransformator.projectionMatrix(), ForwardDetLayer.setSurface(), BarrelDetLayer.setSurface(), CustomPhysicsList.setupRHadronPhycis(), and L1GtVmeWriterCore.writeVME().

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

CREATE FILE FOR PAYLOADS.

Definition at line 622 of file CommonMethods.py.

References delta(), deltaSig(), dump(), and weight().

Referenced by BeamSpotWorkflow.main().

623 def createWeightedPayloads(fileName,listbeam=[],weighted=True):
624  newlistbeam = []
625  tmpbeam = BeamSpot()
626  docreate = True
627  countlumi = 0
628  tmprun = ""
629  maxNlumis = 60
630  if weighted:
631  maxNlumis = 999999999
632  for ii in range(0,len(listbeam)):
633 
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 
645  # check last iov
646  if ii < len(listbeam) - 1:
647  inextbeam = listbeam[ii+1]
648  docheck = True
649  if ii < len(listbeam) -2:
650  iNNbeam = listbeam[ii+2]
651  else:
652  print "close payload because end of data has been reached. Run "+ibeam.Run
653  docreate = True
654  # check we run over the same run
655  if ibeam.Run != inextbeam.Run:
656  print "close payload because end of run "+ibeam.Run
657  docreate = True
658  # check maximum lumi counts
659  if countlumi == maxNlumis -1:
660  print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
661  docreate = True
662  countlumi = 0
663  # weighted average position
664  (tmpbeam.X, tmpbeam.Xerr) = weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
665  (tmpbeam.Y, tmpbeam.Yerr) = weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
666  (tmpbeam.Z, tmpbeam.Zerr) = weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
667  (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) = weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
668  (tmpbeam.dxdz, tmpbeam.dxdzerr) = weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
669  (tmpbeam.dydz, tmpbeam.dydzerr) = weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
670  #print "wx = " + ibeam.beamWidthX + " err= "+ ibeam.beamWidthXerr
671  (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) = weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
672  (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) = weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
673 
674  if weighted:
675  docheck = False
676  # check offsets
677  #if False:
678  if docheck:
679 
680  # define minimum limit
681  min_limit = 0.0025
682 
683  # limit for x and y
684  limit = float(ibeam.beamWidthX)/2.
685  if limit < min_limit: limit = min_limit
686 
687  # check movements in X
688  adelta1 = delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr)
689  adelta2 = (0.,1.e9)
690  adelta1dxdz = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
691  adelta2dxdz = (0.,1.e9)
692  adelta1dydz = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
693  adelta2dydz = (0.,1.e9)
694  adelta1widthx = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
695  adelta2widthx = (0.,1.e9)
696  adelta1widthy = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
697  adelta2widthy = (0.,1.e9)
698 
699  if iNNbeam.Type != -1:
700  adelta2 = delta(inextbeam.X, inextbeam.Xerr, iNNbeam.X, iNNbeam.Xerr)
701  adelta2dxdz = delta(inextbeam.dxdz, inextbeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr)
702  adelta2dydz = delta(inextbeam.dydz, inextbeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr)
703  adelta2widthx = delta(inextbeam.beamWidthX, inextbeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr)
704  adelta2widthy = delta(inextbeam.beamWidthY, inextbeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr)
705 
706  deltaX = deltaSig(adelta1) > 3.5 and adelta1[0] >= limit
707  if ii < len(listbeam) -2:
708  if deltaX==False and adelta1[0]*adelta2[0] > 0. and math.fabs(adelta1[0]+adelta2[0]) >= limit:
709  #print " positive, "+str(adelta1[0]+adelta2[0])+ " limit="+str(limit)
710  deltaX = True
711  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:
712  deltaX = False
713  #print " negative, "+str(adelta1[0]/adelta2[0])
714  #else:
715  # print str(adelta1[0]/adelta2[0])
716 
717  # check movemnts in Y
718  adelta1 = delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr)
719  adelta2 = (0.,1.e9)
720  if iNNbeam.Type != -1:
721  adelta2 = delta(inextbeam.Y, inextbeam.Yerr, iNNbeam.Y, iNNbeam.Yerr)
722 
723  deltaY = deltaSig(adelta1) > 3.5 and adelta1[0] >= limit
724  if ii < len(listbeam) -2:
725  if deltaY==False and adelta1[0]*adelta2[0] > 0. and math.fabs(adelta1[0]+adelta2[0]) >= limit:
726  deltaY = True
727  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:
728  deltaY = False
729  # check movements in Z
730  adelta = delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr)
731 
732 
733  limit = float(ibeam.sigmaZ)/2.
734  deltaZ = deltaSig(adelta) > 3.5 and adelta[0] >= limit
735 
736  adelta = delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr)
737  deltasigmaZ = deltaSig(adelta) > 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()
return newlistbeam
def createWeightedPayloads
CREATE FILE FOR PAYLOADS.
def CommonMethods.createWeightedPayloadsNew (   fileName,
  listbeam = [],
  weighted = True 
)

Definition at line 796 of file CommonMethods.py.

References delta(), dump(), and weight().

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()
def createWeightedPayloadsNew
def CommonMethods.delta (   x,
  xerr,
  nextx,
  nextxerr 
)

Definition at line 321 of file CommonMethods.py.

Referenced by createWeightedPayloads(), and createWeightedPayloadsNew().

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

Definition at line 325 of file CommonMethods.py.

Referenced by createWeightedPayloads().

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

Definition at line 157 of file CommonMethods.py.

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

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

Definition at line 289 of file CommonMethods.py.

References dumpValues().

Referenced by createWeightedPayloads(), and createWeightedPayloadsNew().

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

Definition at line 298 of file CommonMethods.py.

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

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

Definition at line 90 of file CommonMethods.py.

References rmLock().

Referenced by ls().

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

Definition at line 95 of file CommonMethods.py.

Referenced by readBeamSpotFile().

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

Definition at line 79 of file CommonMethods.py.

Referenced by stor::ConcurrentQueue< T, EnqPolicy >.addExternallyDroppedEvents(), evf::FUResourceTable.allocateResource(), stor::QueueCollection< T >.allQueuesStale(), cscdqm::Collection.book(), evf::FUResourceTable.buildResource(), cscdqm::EventProcessor.calcEMUFractionHisto(), stor::ConcurrentQueue< T, EnqPolicy >.clear(), stor::QueueCollection< T >.clearQueue(), stor::QueueCollection< T >.clearQueues(), stor::QueueCollection< T >.clearStaleQueues(), StorageAccount.counter(), cond::XMLAuthenticationService::XMLAuthenticationService.credentials(), evf::FUResourceBroker.customWebPage(), stor::ConcurrentQueue< T, EnqPolicy >.deqNowait(), stor::ConcurrentQueue< T, EnqPolicy >.deqTimedWait(), stor::ConcurrentQueue< T, EnqPolicy >.deqWait(), evf::FUResourceTable.discard(), evf::FUResourceTable.discardDataEvent(), stor::QueueCollection< T >.empty(), stor::ConcurrentQueue< T, EnqPolicy >.enqNowait(), stor::ConcurrentQueue< T, EnqPolicy >.enqTimedWait(), stor::ConcurrentQueue< T, EnqPolicy >.enqWait(), CSCMonitorObject.Fill(), stor::QueueCollection< T >.full(), stor::ConcurrentQueue< T, EnqPolicy >.full(), CSCMonitorObject.GetBinContent(), CSCMonitorObject.GetBinError(), CSCMonitorObject.GetEntries(), stor::QueueCollection< T >.getExpirationInterval(), edm::detail::ThreadSafeIndexedRegistry< T, E >.getMapped(), edm::detail::ThreadSafeRegistry< KEY, T, E >.getMapped(), CSCMonitorObject.GetMaximumBin(), stor::QueueCollection< T >.getQueue(), edm::detail::ThreadSafeIndexedRegistry< T, E >.insertMapped(), edm::detail::ThreadSafeRegistry< KEY, T, E >.insertMapped(), edm::detail::ThreadSafeIndexedRegistry< T, E >.instance(), edm::detail::ThreadSafeRegistry< KEY, T, E >.instance(), BeamSpotWorkflow.main(), DQMNet.onPeerConnect(), DQMNet.onPeerData(), stor::QueueCollection< T >.popEvent(), cscdqm::Dispatcher.processStandby(), evf::FUResourceTable.sendData(), CSCMonitorObject.SetAxisRange(), CSCMonitorObject.setAxisTitle(), CSCMonitorObject.SetBinContent(), CSCMonitorObject.SetBinError(), stor::ConcurrentQueue< T, EnqPolicy >.setCapacity(), CSCMonitorObject.SetEntries(), stor::QueueCollection< T >.setExpirationInterval(), CSCMonitorObject.SetMaximum(), stor::ConcurrentQueue< T, EnqPolicy >.setMemory(), CSCMonitorObject.SetNormFactor(), stor::QueueCollection< T >.size(), stor::QueueCollection< T >.stale(), StorageAccount::Stamp.Stamp(), cscdqm::EventProcessor.standbyEfficiencyHistos(), StorageAccount::Stamp.tick(), cscdqm::EventProcessor.updateEfficiencyHistos(), cscdqm::EventProcessorMutex.updateFractionAndEfficiencyHistos(), cscdqm::Dispatcher.updateFractionAndEfficiencyHistos(), cscdqm::EventProcessor.updateFractionHistos(), cscdqm::EventProcessor.writeShifterHistograms(), and stor::ConcurrentQueue< T, EnqPolicy >.~ConcurrentQueue().

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

Definition at line 166 of file CommonMethods.py.

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

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

Definition at line 129 of file CommonMethods.py.

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

lumi tools CondCore/Utilities/python/timeUnitHelper.py

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

Definition at line 227 of file CommonMethods.py.

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

Definition at line 105 of file CommonMethods.py.

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

Definition at line 329 of file CommonMethods.py.

References python.multivaluedict.append(), and isnan().

Referenced by BeamSpotWorkflow.main().

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

Definition at line 906 of file CommonMethods.py.

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 = commands.getstatusoutput('cmsRun '+ readDBOut)
923 
924  outtext = status_rDB[1]
925  print outtext
926  os.system("rm -f " + readDBOut)
927  return not status_rDB[0]
def CommonMethods.rmLock ( )

Definition at line 84 of file CommonMethods.py.

References checkLock().

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

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

General utilities.

Definition at line 148 of file CommonMethods.py.

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

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

Definition at line 66 of file CommonMethods.py.

Referenced by BeamSpotWorkflow.main().

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

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

Definition at line 590 of file CommonMethods.py.

Referenced by BeamSpotWorkflow.main().

591 def sortAndCleanBeamList(listbeam=[],IOVbase="lumibase"):
592  # sort the list
593  if IOVbase == "lumibase":
594  listbeam.sort( cmp = cmp_list_lumi )
595  else:
596  listbeam.sort( cmp = cmp_list_run )
597 
598  # first clean list of data for consecutive duplicates and bad fits
599  tmpremovelist = []
600  for ii in range(0,len(listbeam)):
601  ibeam = listbeam[ii]
602  datax = ibeam.IOVfirst
603  #print str(ii) + " " +datax
604  if datax == '0' and IOVbase =="runbase":
605  print " iov = 0? skip this IOV = "+ str(ibeam.IOVfirst) + " to " + str(ibeam.IOVlast)
606  tmpremovelist.append(ibeam)
607 
608  if ii < len(listbeam) -1:
609  #print listbeam[ii+1].IOVfirst
610  if IOVbase =="lumibase":
611  if ibeam.Run == listbeam[ii+1].Run and ibeam.IOVfirst == listbeam[ii+1].IOVfirst:
612  print " duplicate IOV = "+datax+", keep only last duplicate entry"
613  tmpremovelist.append(ibeam)
614  elif datax == listbeam[ii+1].IOVfirst:
615  print " duplicate IOV = "+datax+", keep only last duplicate entry"
616  tmpremovelist.append(ibeam)
617 
618  for itmp in tmpremovelist:
619  listbeam.remove(itmp)
def sortAndCleanBeamList
Sort and clean list of data for consecutive duplicates and bad fits.
def CommonMethods.timeoutManager (   type,
  timeout = -1,
  fileName = ".timeout" 
)

Definition at line 8 of file CommonMethods.py.

References split.

Referenced by BeamSpotWorkflow.selectFilesToProcess().

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

Definition at line 235 of file CommonMethods.py.

References mathSSE.return().

Referenced by unpackLumiid().

236 def unpack(i):
237  """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
238  """
239  high=i>>32
240  low=i&0xFFFFFFFF
241  return(high,low)
return((rh^lh)&mask)
def CommonMethods.unpackLumiid (   i)
unpack 64bit lumiid to dictionary {'run','lumisection'}

Definition at line 243 of file CommonMethods.py.

References unpack().

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

Definition at line 937 of file CommonMethods.py.

Referenced by BeamSpotWorkflow.main().

938 def uploadSqliteFile(sqliteFileDirName, sqliteFileName, dropbox="/DropBox"):
939  # Changing permissions to metadata
940  acmd = "chmod a+w " + sqliteFileDirName + sqliteFileName + ".txt"
941  outcmd = commands.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 = commands.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 = commands.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 = commands.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 = commands.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 = commands.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 = commands.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 = commands.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 = commands.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 = commands.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 
def CommonMethods.weight (   x1,
  x1err,
  x2,
  x2err 
)

Definition at line 268 of file CommonMethods.py.

Referenced by PhysicsTools::LeastSquares.add(), reco::TrackKinematics.add(), KalmanVertexUpdator< N >.add(), lhef::LHERunInfo::Counter.add(), MuonTruth.addChannel(), RPCRawDataCounts.addDccRecord(), Accumulator.addEntry(), CaloValidationStatistics.addEntry(), MultiTrajectoryStateAssembler.addInvalidState(), TtFullLepKinSolver.addKinSolInfo(), addMeas(), MuonCSCChamberResidual.addResidual(), MuonDT13ChamberResidual.addResidual(), MuonDT2ChamberResidual.addResidual(), CSCPairResidualsConstraint.addTrack(), FedCablingAlgorithm.analyse(), EWKSystUnc.analyze(), ZLONLOHistogrammer.analyze(), ZMCHistogrammer.analyze(), zPdfUnc.analyze(), JetAnaPythia< Jet >.analyze(), Rivet::CMS_2011_S8968497.analyze(), HistoAnalyzer< C >.analyze(), TtSemiLepSignalSelMVATrainer.analyze(), EBBeamHodoTask.analyze(), EEBeamHodoTask.analyze(), MuonTruth.analyze(), VVVValidation.analyze(), BasicHepMCHeavyIonValidation.analyze(), BasicHepMCValidation.analyze(), DrellYanValidation.analyze(), WValidation.analyze(), HiggsValidation.analyze(), BasicGenParticleValidation.analyze(), MBUEandQCDValidation.analyze(), Rivet::CMS_2010_S8656010.analyze(), DuplicationChecker.analyze(), Rivet::CMS_2011_S8978280.analyze(), Rivet::CMS_FWD_10_006.analyze(), Rivet::CMS_2011_S8884919.analyze(), Rivet::CMS_2010_S8547297.analyze(), TauValidation.analyze(), Rivet::CMS_QCD_10_010.analyze(), EgHLTOfflineSource.analyze(), Rivet::CMS_FWD_10_011.analyze(), IsolatedTracksNxN.analyze(), Rivet::MC_LES_HOUCHES_SYSTEMATICS_CMS.analyze(), JetTagMVATreeTrainer.analyze(), Rivet::CMS_EWK_10_012.analyze(), GsfVertexUpdator.assembleVertexComponents(), CaloTowersCreationAlgo.assignHit(), JetAnaPythia< Jet >.beginJob(), BremsstrahlungSimulator.brem(), GsfVertexWeightCalculator.calculate(), ClusterShapeAlgo.Calculate_EnergyDepTopology(), PositionCalc.Calculate_Location(), TBPositionCalc.CalculateCMSPos(), XHistogram.check_weight(), MultiGaussianStateCombiner1D.combine(), MultiTrajectoryStateCombiner.combine(), CandIsolatorFromDeposits::SingleDeposit.compute(), PairProductionSimulator.compute(), MuScleFitUtils.computeWeight(), EcalTPGParamBuilder.computeWeights(), MassWindow.count(), BackgroundHandler.countEventsInAllWindows(), MultiVertexFitter.createSeed(), createWeightedPayloads(), createWeightedPayloadsNew(), DreamSD.curve_LY(), ECalSD.curve_LY(), HcalTB02SD.curve_LY(), SignedImpactParameter3D.distanceWithJetAxis(), CSCOfflineMonitor.doEfficiencies(), CSCValidation.doEfficiencies(), PhysicsTools::TrainProcessor.doTrainData(), MuScleFit.duringFastLoop(), CalorimetryManager.EMShowerSimulation(), CaloTowersCreationAlgo.emShwrLogWeightPos(), DTCertificationSummary.endRun(), DTResolutionAnalysisTest.endRun(), AdaptiveVertexReconstructor.erase(), reco::Jet.etaetaMoment(), reco::Jet.etaphiMoment(), reco::Jet.etaPhiStatistics(), evaluateTtFullHadSignalSel(), evaluateTtSemiLepSignalSel(), ConfigurableHisto.fill(), HParticle.Fill(), HPartVSEta.Fill(), HPartVSPhi.Fill(), HPartVSPt.Fill(), HMassVSPart.Fill(), HMassVSPartProfile.Fill(), MuonSystemMapPlot1D.fill_dxdz(), MuonSystemMapPlot1D.fill_dydz(), MuonSystemMapPlot1D.fill_x(), MuonSystemMapPlot1D.fill_y(), SiPixelDataQuality.fillGlobalQualityPlot(), HLXMonitor.FillHistograms(), SVTagInfoValidationAnalyzer.fillRecoToSim(), recoBSVTagInfoValidationAnalyzer.fillRecoToSim(), SVTagInfoValidationAnalyzer.fillSimToReco(), recoBSVTagInfoValidationAnalyzer.fillSimToReco(), reco::PositiveSideGhostTrackFitter.fit(), MuonResiduals1DOFFitter.fit(), PFDisplacedVertexFinder.fitVertexFromSeed(), SherpaHadronizer.generatePartonsAndHadronize(), CaloSD.getAttenuation(), ECalSD.getBirkL3(), HcalTB06BeamSD.getEnergyDeposit(), EcalTBH4BeamSD.getEnergyDeposit(), ECalSD.getEnergyDeposit(), HcalTB02SD.getEnergyDeposit(), HCalSD.getEnergyDeposit(), EcalClusterTools.getEnergyDepTopology(), GsfBetheHeitlerUpdator.getMixtureParameters(), TtFullLepKinSolver.getNuSolution(), DreamSD.getStepInfo(), CaloMeanResponse.getWeight(), AdaptiveVertexFitter.getWeight(), tnp::BaseTreeFiller.init(), reco::GhostTrack.initStates(), CSCPairResidualsConstraint.isFiducial(), IPTools.jetTrackDistance(), likelihood(), EnergyLossPlain.logTruncate(), reco::PFDisplacedVertexSeed.mergeWith(), MuonResiduals1DOFFitter_FCN(), MuonResiduals5DOFFitter_FCN(), MuonResiduals6DOFFitter_FCN(), MuonResiduals6DOFrphiFitter_FCN(), SmsModeFinder3d.operator()(), MtvClusterizer1D< T >.operator()(), FsmwClusterizer1D< T >.operator()(), FsmwModeFinder3d.operator()(), EnergyLossPlain.optimal(), DTSegmentAnalysisTest.performClientDiagnostic(), reco::Jet.phiphiMoment(), TauValidation.photons(), MuonResiduals1DOFFitter.plot(), MuonResiduals5DOFFitter.plot(), MuonResiduals6DOFrphiFitter.plot(), MuonResiduals6DOFFitter.plot(), MuonResidualsFitter.plotweighted(), PrescaleWeightProvider.prescaleWeight(), PrintMaterialBudgetInfo.printInfo(), WeakEffectsWeightProducer.produce(), ISRGammaWeightProducer.produce(), ISRWeightProducer.produce(), FSRWeightProducer.produce(), edm::BeamHaloProducer.produce(), edm::BeamHaloSource.produce(), AlCaElectronsProducer.produce(), EcalTBWeightsXMLTranslator.readWeightSet(), EcalWeightSetXMLTranslator.readXML(), KalmanVertexUpdator< N >.remove(), CaloTowersCreationAlgo.rescale(), CaloTowersCreationAlgo.rescaleTowers(), AdaptiveVertexFitter.reWeightTracks(), EcalClusterTools.roundnessSelectedBarrelRecHits(), PhysicsTools::MLP.set(), UpdateTProfile.setBinContent(), FWGUIManager.setFrom(), Histograms.SetWeight(), CandIsolatorFromDeposits::SingleDeposit.SingleDeposit(), TauValidation.spinEffects(), TauValidation.spinEffectsZ(), sistrip::MeasureLA.summarize_module_muH_byLayer(), TBposition(), hcalCalib.Terminate(), EnergyLossPlain.truncate(), EcalTPGParamBuilder.uncodeWeight(), KalmanVertexUpdator< N >.update(), CommissioningTask.updateHistoSet(), reco::PFDisplacedVertexSeed.updateSeedPoint(), GsfMaterialEffectsUpdator.updateState(), MultiVertexFitter.updateWeights(), PrimaryVertexMonitor.vertexPlots(), VertexTrackFactory< 6 >.vertexTrack(), vtxMean(), TtFullLepKinSolver.WeightSolfromMC(), AdaptiveVertexFitter.weightTracks(), and MuonResidualsTwoBin.wmean().

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

Definition at line 882 of file CommonMethods.py.

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 = commands.getstatusoutput('cmsRun '+ writeDBOut)
901  print status_wDB[1]
902 
903  os.system("rm -f " + writeDBOut)
904  return not status_wDB[0]

Variable Documentation

string CommonMethods.lockFile = ".lock"

Definition at line 5 of file CommonMethods.py.

tuple CommonMethods.USAGE = re.compile(r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')

OPTIONS.

Definition at line 102 of file CommonMethods.py.