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

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

929 def appendSqliteFile(combinedSqliteFileName, sqliteFileName, tagName, IOVSince, IOVTill ,tmpDir="/tmp/"):
930  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
931  print aCommand
932  std = commands.getstatusoutput(aCommand)
933  print std[1]
934  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(), CustomPhysicsListSS.addCustomPhysics(), heppy::IsolationComputer.addVetos(), cmsutils::bqueue< TrajectoryMeasurement >.bqueue(), PixelTrackBuilder.build(), HtrXmlPatternTool.createHists(), HtrXmlPattern.do_hand_fill(), edm::RootFile.dropOnInput(), DTUserKeyedConfigHandler.DTUserKeyedConfigHandler(), pftools::Exercises3.evaluateCalibrator(), HtrXmlPatternTool.Fill(), edm::RootOutputFile.fillBranches(), L1GtVhdlWriterCore.getCaloSetupContentFromTriggerMenu(), L1GtVhdlWriterCore.getMuonSetupContentFromTriggerMenu(), edm::RootDelayedReader.getProduct_(), heppy::IsolationComputer.isoSumNeutralsWeighted(), heppy::IsolationComputer.isoSumRaw(), rename.main(), copyAndRename.main(), copyFromCastor.main(), copyFiles.main(), splitter.main(), BeamSpotWorkflow.main(), PreshowerClusterAlgo.makeOneCluster(), TracksClusteringFromDisplacedSeed.nearTracks(), cmsutils::bqueue< TrajectoryMeasurement >.operator=(), DDStreamer.pos_read(), DuplicateTrackMerger.produce(), Strip1DMeasurementTransformator.projectionMatrix(), BarrelDetLayer.setSurface(), ForwardDetLayer.setSurface(), CustomPhysicsListSS.setupRHadronPhycis(), 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(), and dump().

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  ibeam = listbeam[ii]
634  inextbeam = BeamSpot()
635  iNNbeam = BeamSpot()
636  if docreate:
637  tmpbeam.IOVfirst = ibeam.IOVfirst
638  tmpbeam.IOVBeginTime = ibeam.IOVBeginTime
639  tmpbeam.Run = ibeam.Run
640  tmpbeam.Type = 2
641  docheck = False
642  docreate = False
643  #print "Currently testing ii="+str(ii)+" Lumi1: "+str(ibeam.IOVfirst)
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  adelta1z0 = delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr)
699  adelta1sigmaZ = delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr)
700 
701  if iNNbeam.Type != -1:
702  adelta2 = delta(inextbeam.X, inextbeam.Xerr, iNNbeam.X, iNNbeam.Xerr)
703  adelta2dxdz = delta(inextbeam.dxdz, inextbeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr)
704  adelta2dydz = delta(inextbeam.dydz, inextbeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr)
705  adelta2widthx = delta(inextbeam.beamWidthX, inextbeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr)
706  adelta2widthy = delta(inextbeam.beamWidthY, inextbeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr)
707 
708  deltaX = deltaSig(adelta1) > 3.5 and adelta1[0] >= limit
709  if ii < len(listbeam) -2:
710  if deltaX==False and adelta1[0]*adelta2[0] > 0. and math.fabs(adelta1[0]+adelta2[0]) >= limit:
711  #print " positive, "+str(adelta1[0]+adelta2[0])+ " limit="+str(limit)
712  deltaX = True
713  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:
714  deltaX = False
715  #print " negative, "+str(adelta1[0]/adelta2[0])
716  #else:
717  # print str(adelta1[0]/adelta2[0])
718 
719  # check movemnts in Y
720  adelta1 = delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr)
721  adelta2 = (0.,1.e9)
722  if iNNbeam.Type != -1:
723  adelta2 = delta(inextbeam.Y, inextbeam.Yerr, iNNbeam.Y, iNNbeam.Yerr)
724 
725  deltaY = deltaSig(adelta1) > 3.5 and adelta1[0] >= limit
726  if ii < len(listbeam) -2:
727  if deltaY==False and adelta1[0]*adelta2[0] > 0. and math.fabs(adelta1[0]+adelta2[0]) >= limit:
728  deltaY = True
729  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:
730  deltaY = False
731  # check movements in Z
732 
733  limit = float(ibeam.sigmaZ)/2.
734  deltaZ = deltaSig(adelta1z0) > 3.5 and math.fabs(adelta1z0[0]) >= limit
735 
736  deltasigmaZ = deltaSig(adelta1sigmaZ) > 5.0
737 
738  # check dxdz
739  adelta = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
740  deltadxdz = deltaSig(adelta) > 5.0
741  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:
742  deltadxdz = False
743  # check dydz
744  adelta = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
745  deltadydz = deltaSig(adelta) > 5.0
746  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:
747  deltadydz = False
748 
749  adelta = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
750  deltawidthX = deltaSig(adelta) > 5
751  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:
752  deltawidthX = False
753 
754  adelta = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
755  deltawidthY = deltaSig(adelta) > 5
756  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:
757  deltawidthY = False
758  #if iNNbeam.Type != -1:
759  # deltaX = deltaX and delta(ibeam.X, ibeam.Xerr, iNNbeam.X, iNNbeam.Xerr) > 1.5
760  # deltaY = deltaY and delta(ibeam.Y, ibeam.Yerr, iNNbeam.Y, iNNbeam.Yerr) > 1.5
761  # deltaZ = deltaZ and delta(ibeam.Z, ibeam.Zerr, iNNbeam.Z, iNNbeam.Zerr) > 1.5
762  #
763  # deltasigmaZ = deltasigmaZ and delta(ibeam.sigmaZ, ibeam.sigmaZerr, iNNbeam.sigmaZ, iNNbeam.sigmaZerr) > 2.5
764  # deltadxdz = deltadxdz and delta(ibeam.dxdz, ibeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr) > 2.5
765  # deltadydz = deltadydz and delta(ibeam.dydz, ibeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr) > 2.5
766  #
767  # deltawidthX = deltawidthX and delta(ibeam.beamWidthX, ibeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr) > 3
768  # deltawidthY = deltawidthY and delta(ibeam.beamWidthY, ibeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr) > 3
769 
770  if deltaX or deltaY or deltaZ or deltasigmaZ or deltadxdz or deltadydz or deltawidthX or deltawidthY:
771  docreate = True
772  #print "shift here: x="+str(deltaX)+" y="+str(deltaY)
773  #print "x1 = "+ibeam.X + " x1err = "+ibeam.Xerr
774  #print "x2 = "+inextbeam.X + " x2err = "+inextbeam.Xerr
775  #print "Lumi1: "+str(ibeam.IOVfirst) + " Lumi2: "+str(inextbeam.IOVfirst)
776  #print " x= "+ibeam.X+" +/- "+ibeam.Xerr
777  #print "weighted average x = "+tmpbeam.X +" +//- "+tmpbeam.Xerr
778  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)
779  if docreate:
780  #if ii == len(listbeam)-1:
781  tmpbeam.IOVlast = ibeam.IOVlast
782  tmpbeam.IOVEndTime = ibeam.IOVEndTime
783  print " Run: "+tmpbeam.Run +" Lumi1: "+str(tmpbeam.IOVfirst) + " Lumi2: "+str(tmpbeam.IOVlast)
784  newlistbeam.append(tmpbeam)
785  tmpbeam = BeamSpot()
786  countlumi = 0
787  tmprun = ibeam.Run
788  countlumi += 1
789 
790  payloadfile = open(fileName,"w")
791  for iload in newlistbeam:
792  dump( iload, payloadfile )
793  payloadfile.close()
return newlistbeam
def createWeightedPayloads
CREATE FILE FOR PAYLOADS.
Definition: weight.py:1
def CommonMethods.createWeightedPayloadsNew (   fileName,
  listbeam = [],
  weighted = True 
)

Definition at line 795 of file CommonMethods.py.

References delta(), and dump().

796 def createWeightedPayloadsNew(fileName,listbeam=[],weighted=True):
797  newlistbeam = []
798  docreate = False
799  docheck = False
800  lastPayload = listbeam[0]
801 
802  firstToUse = 0
803  lastToUse = 0
804  for ii in range(0,len(listbeam)):
805  docreate = False
806  if docheck:
807  deltaX = delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr) > 1.5
808  deltaY = delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr) > 1.5
809  deltaZ = delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr) > 2.5
810 
811  deltasigmaZ = delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr) > 2.5
812  deltadxdz = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr) > 2.5
813  deltadydz = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr) > 2.5
814 
815  deltawidthX = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr) > 3
816  deltawidthY = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr) > 3
817 
818  #if iNNbeam.Type != -1:
819  # deltaX = deltaX and delta(ibeam.X, ibeam.Xerr, iNNbeam.X, iNNbeam.Xerr) > 1.5
820  # deltaY = deltaY and delta(ibeam.Y, ibeam.Yerr, iNNbeam.Y, iNNbeam.Yerr) > 1.5
821  # deltaZ = deltaZ and delta(ibeam.Z, ibeam.Zerr, iNNbeam.Z, iNNbeam.Zerr) > 1.5
822  #
823  # deltasigmaZ = deltasigmaZ and delta(ibeam.sigmaZ, ibeam.sigmaZerr, iNNbeam.sigmaZ, iNNbeam.sigmaZerr) > 2.5
824  # deltadxdz = deltadxdz and delta(ibeam.dxdz, ibeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr) > 2.5
825  # deltadydz = deltadydz and delta(ibeam.dydz, ibeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr) > 2.5
826  #
827  # deltawidthX = deltawidthX and delta(ibeam.beamWidthX, ibeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr) > 3
828  # deltawidthY = deltawidthY and delta(ibeam.beamWidthY, ibeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr) > 3
829 
830  if deltaX or deltaY or deltaZ or deltasigmaZ or deltadxdz or deltadydz or deltawidthX or deltawidthY:
831  if ii != 0:
832  docreate = True
833  lastToUse = ii-1
834  #print "shift here: x="+str(deltaX)+" y="+str(deltaY)
835  #print "x1 = "+ibeam.X + " x1err = "+ibeam.Xerr
836  #print "x2 = "+inextbeam.X + " x2err = "+inextbeam.Xerr
837  #print "Lumi1: "+str(ibeam.IOVfirst) + " Lumi2: "+str(inextbeam.IOVfirst)
838  #print " x= "+ibeam.X+" +/- "+ibeam.Xerr
839  #print "weighted average x = "+tmpbeam.X +" +//- "+tmpbeam.Xerr
840  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)
841 
842  #WARNING this will only be fine for Run based IOVs
843  if ii >= len(listbeam) - 1 or listbeam[ii].Run != listbeam[ii+1].Run :
844  print "close payload because end of run has been reached. Run " + listbeam[ii].Run
845  docreate = True
846  lastToUse = ii
847 
848 
849  # check maximum lumi counts
850 #? if countlumi == maxNlumis:
851 #? print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
852 #? docreate = True
853 #? countlumi = 0
854  if docreate:
855  tmpbeam = BeamSpot()
856  for ibeam in listbeam[firstToUse:lastToUse]:
857  (tmpbeam.X, tmpbeam.Xerr) = weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
858  (tmpbeam.Y, tmpbeam.Yerr) = weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
859  (tmpbeam.Z, tmpbeam.Zerr) = weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
860  (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) = weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
861  (tmpbeam.dxdz, tmpbeam.dxdzerr) = weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
862  (tmpbeam.dydz, tmpbeam.dydzerr) = weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
863  #print "wx = " + ibeam.beamWidthX + " err= "+ ibeam.beamWidthXerr
864  (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) = weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
865  (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) = weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
866  tmpbeam.IOVfirst = listbeam[firstToUse].IOVfirst
867  tmpbeam.IOVBeginTime = listbeam[firstToUse].IOVBeginTime
868  tmpbeam.Run = listbeam[firstToUse].Run
869  tmpbeam.Type = 2
870  tmpbeam.IOVlast = listbeam[lastToUse].IOVlast
871  tmpbeam.IOVEndTime = listbeam[lastToUse].IOVEndTime
872  newlistbeam.append(tmpbeam)
873  firstToUse = lastToUse+1
874  print "Run: " + tmpbeam.Run + " Lumi1: " + str(tmpbeam.IOVfirst) + " Lumi2: " + str(tmpbeam.IOVlast)
875 
876  payloadfile = open(fileName,"w")
877  for iload in newlistbeam:
878  dump( iload, payloadfile )
879  payloadfile.close()
Definition: weight.py:1
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 evf::FastMonitoringService.accumulateFileSize(), cond::service::PoolDBOutputService.appendSinceTime(), dqm::DQMFileSaverOnline.appendSnapshot(), cscdqm::Collection.book(), cscdqm::EventProcessor.calcEMUFractionHisto(), ecaldqm.checkElectronicsMap(), ecaldqm.checkGeometry(), ecaldqm.checkTopology(), ecaldqm.checkTrigTowerMap(), cond::service::PoolDBOutputService.closeIOV(), StorageAccount.counter(), cond::service::PoolDBOutputService.createNewIOV(), cond::XMLAuthenticationService::XMLAuthenticationService.credentials(), CandidateBoostedDoubleSecondaryVertexComputer.discriminator(), evf::FastMonitoringService.dowork(), TMVAEvaluator.evaluateTMVA(), CSCMonitorObject.Fill(), evf::FastMonitoringService.getAbortFlagForLumi(), CSCMonitorObject.GetBinContent(), CSCMonitorObject.GetBinError(), CSCMonitorObject.GetEntries(), evf::FastMonitoringService.getEventsProcessedForLumi(), CSCMonitorObject.GetMaximumBin(), XrdAdaptor::XrdSiteStatisticsInformation.getStatisticsForSite(), cond::service::PoolDBOutputService.initDB(), edm::JobReport.inputFileClosed(), cond::service::PoolDBOutputService.lookUpRecord(), BeamSpotWorkflow.main(), DQMNet.onPeerConnect(), DQMNet.onPeerData(), evf::FastMonitoringService.postBeginJob(), evf::FastMonitoringService.preGlobalBeginLumi(), evf::FastMonitoringService.preGlobalEarlyTermination(), evf::FastMonitoringService.preGlobalEndLumi(), evf::FastMonitoringService.preModuleBeginJob(), evf::FastMonitoringService.prePathEvent(), evf::FastMonitoringService.preSourceEarlyTermination(), evf::FastMonitoringService.preStreamBeginLumi(), FastTimerService.preStreamBeginRun(), evf::FastMonitoringService.preStreamEarlyTermination(), evf::FastMonitoringService.preStreamEndLumi(), cscdqm::Dispatcher.processStandby(), cms::CkfTrackCandidateMakerBase.produceBase(), edm::JobReport.reportAnalysisFile(), edm::JobReport.reportError(), evf::FastMonitoringService.reportEventsThisLumiInSource(), edm::JobReport.reportFallbackAttempt(), evf::FastMonitoringService.reportLockWait(), edm::JobReport.reportRandomStateFile(), edm::JobReport.reportSkippedEvent(), edm::JobReport.reportSkippedFile(), CSCMonitorObject.SetAxisRange(), CSCMonitorObject.setAxisTitle(), CSCMonitorObject.SetBinContent(), CSCMonitorObject.SetBinError(), ecaldqm.setElectronicsMap(), CSCMonitorObject.SetEntries(), ecaldqm.setGeometry(), CSCMonitorObject.SetMaximum(), CSCMonitorObject.SetNormFactor(), ecaldqm.setTopology(), ecaldqm.setTrigTowerMap(), StorageAccount::Stamp.Stamp(), cscdqm::EventProcessor.standbyEfficiencyHistos(), edm::ZombieKillerService.startThread(), evf::FastMonitoringService.stoppedLookingForFile(), cond::service::PoolDBOutputService.tagInfo(), StorageAccount::Stamp.tick(), cscdqm::EventProcessor.updateEfficiencyHistos(), cscdqm::EventProcessorMutex.updateFractionAndEfficiencyHistos(), cscdqm::Dispatcher.updateFractionAndEfficiencyHistos(), cscdqm::EventProcessor.updateFractionHistos(), cond::service::PoolDBOutputService.writeOne(), and cscdqm::EventProcessor.writeShifterHistograms().

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

Referenced by BeamSpotWorkflow.main().

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

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

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

Definition at line 268 of file CommonMethods.py.

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

Referenced by BeamSpotWorkflow.main().

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