CMS 3D CMS Logo

Classes | Functions | Variables

CommonMethods Namespace Reference

Classes

class  ParsingError

Functions

def appendSqliteFile
def checkLock
def cmp_list_lumi
def cmp_list_run
def cp
def createWeightedPayloads
 CREATE FILE FOR PAYLOADS.
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
def parse
def readBeamSpotFile
def readSqliteFile
def rmLock
def sendEmail
 General utilities.
def setLockName
def sortAndCleanBeamList
 Sort and clean list of data for consecutive duplicates and bad fits.
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.

Function Documentation

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

Definition at line 929 of file CommonMethods.py.

00930                                                                                                         :
00931     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
00932     print aCommand
00933     std = commands.getstatusoutput(aCommand)
00934     print std[1]
00935     return not std[0]

def CommonMethods::checkLock ( )

Definition at line 71 of file CommonMethods.py.

00072                :
00073     global lockFile
00074     if os.path.isfile(lockFile):
00075         return True
00076     else:
00077         return False
    
def CommonMethods::cmp_list_lumi (   a,
  b 
)

Definition at line 259 of file CommonMethods.py.

00260                       :
00261     if int(a.Run) < int(b.Run): return -1
00262     if int(a.Run) == int(b.Run):
00263         if int(a.IOVfirst) < int(b.IOVfirst): return -1
00264         if int(a.IOVfirst) == int(b.IOVfirst): return 0
00265         if int(a.IOVfirst) > int(b.IOVfirst): return 1
00266     if int(a.Run) > int(b.Run) : return 1

def CommonMethods::cmp_list_run (   a,
  b 
)

Definition at line 253 of file CommonMethods.py.

00254                      :
00255     if int(a.IOVfirst) < int(b.IOVfirst): return -1
00256     if int(a.IOVfirst) == int(b.IOVfirst): return 0
00257     if int(a.IOVfirst) > int(b.IOVfirst): return 1

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(), DTUserKeyedConfigHandler::DTUserKeyedConfigHandler(), pftools::Exercises3::evaluateCalibrator(), HtrXmlPatternTool::Fill(), edm::RootOutputFile::fillBranches(), L1GtVhdlWriterCore::getCaloSetupContentFromTriggerMenu(), L1GtVhdlWriterCore::getMuonSetupContentFromTriggerMenu(), PreshowerClusterAlgo::makeOneCluster(), InclusiveVertexFinder::nearTracks(), DDStreamer::pos_read(), Strip1DMeasurementTransformator::projectionMatrix(), BarrelDetLayer::setSurface(), ForwardDetLayer::setSurface(), CustomPhysicsList::setupRHadronPhycis(), and L1GtVmeWriterCore::writeVME().

00190                                                                  :
00191     cpCommand   = ''
00192     copiedFiles = []
00193     if fromDir.find('castor') != -1 or toDir.find('castor') != -1 :
00194         cpCommand = 'rf'
00195     elif fromDir.find('resilient') != -1:
00196         cpCommand = 'dc'
00197     if fromDir[len(fromDir)-1] != '/':
00198         fromDir += '/'
00199 
00200     if toDir[len(toDir)-1] != '/':
00201         toDir += '/'
00202         
00203     for file in listOfFiles:
00204         if os.path.isfile(toDir+file):
00205             if overwrite:
00206                 print "File " + file + " already exists in destination directory. We will overwrite it."
00207             else:
00208                 print "File " + file + " already exists in destination directory. We will Keep original file."
00209                 if not smallList:
00210                     copiedFiles.append(file)
00211                 continue
00212         # copy to local disk
00213         aCommand = cpCommand + 'cp '+ fromDir + file + " " + toDir
00214         print " >> " + aCommand
00215         tmpStatus = commands.getstatusoutput( aCommand )
00216         if tmpStatus[0] == 0:
00217             copiedFiles.append(file)
00218         else:
00219             print "[cp()]\tERROR: Can't copy file " + file
00220     return copiedFiles

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

CREATE FILE FOR PAYLOADS.

Definition at line 622 of file CommonMethods.py.

00623                                                               :
00624     newlistbeam = []
00625     tmpbeam = BeamSpot()
00626     docreate = True
00627     countlumi = 0
00628     tmprun = ""
00629     maxNlumis = 60
00630     if weighted:
00631         maxNlumis = 999999999
00632     for ii in range(0,len(listbeam)):
00633         
00634         ibeam = listbeam[ii]
00635         inextbeam = BeamSpot()
00636         iNNbeam = BeamSpot()
00637         if docreate:
00638             tmpbeam.IOVfirst = ibeam.IOVfirst
00639             tmpbeam.IOVBeginTime = ibeam.IOVBeginTime
00640             tmpbeam.Run = ibeam.Run
00641             tmpbeam.Type = 2
00642         docheck = False
00643         docreate = False
00644             
00645         # check last iov
00646         if ii < len(listbeam) - 1: 
00647             inextbeam = listbeam[ii+1]
00648             docheck = True
00649             if ii < len(listbeam) -2:
00650                 iNNbeam = listbeam[ii+2]
00651         else:
00652             print "close payload because end of data has been reached. Run "+ibeam.Run
00653             docreate = True
00654         # check we run over the same run
00655         if ibeam.Run != inextbeam.Run:
00656             print "close payload because end of run "+ibeam.Run
00657             docreate = True
00658         # check maximum lumi counts
00659         if countlumi == maxNlumis -1:
00660             print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
00661             docreate = True
00662             countlumi = 0
00663         # weighted average position
00664         (tmpbeam.X, tmpbeam.Xerr) = weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
00665         (tmpbeam.Y, tmpbeam.Yerr) = weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
00666         (tmpbeam.Z, tmpbeam.Zerr) = weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
00667         (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) = weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
00668         (tmpbeam.dxdz, tmpbeam.dxdzerr) = weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
00669         (tmpbeam.dydz, tmpbeam.dydzerr) = weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
00670         #print "wx = " + ibeam.beamWidthX + " err= "+ ibeam.beamWidthXerr
00671         (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) = weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
00672         (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) = weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
00673         
00674         if weighted:
00675             docheck = False
00676         # check offsets
00677         #if False:
00678         if docheck:
00679 
00680             # define minimum limit
00681             min_limit = 0.0025
00682             
00683             # limit for x and y
00684             limit = float(ibeam.beamWidthX)/2.
00685             if limit < min_limit: limit = min_limit
00686             
00687             # check movements in X
00688             adelta1 = delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr)
00689             adelta2 = (0.,1.e9)
00690             adelta1dxdz = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
00691             adelta2dxdz = (0.,1.e9)
00692             adelta1dydz = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
00693             adelta2dydz = (0.,1.e9)
00694             adelta1widthx = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
00695             adelta2widthx = (0.,1.e9)
00696             adelta1widthy = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr)
00697             adelta2widthy = (0.,1.e9)
00698             
00699             if iNNbeam.Type != -1:
00700                 adelta2 = delta(inextbeam.X, inextbeam.Xerr, iNNbeam.X, iNNbeam.Xerr)
00701                 adelta2dxdz = delta(inextbeam.dxdz, inextbeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr)
00702                 adelta2dydz = delta(inextbeam.dydz, inextbeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr)
00703                 adelta2widthx = delta(inextbeam.beamWidthX, inextbeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr)
00704                 adelta2widthy = delta(inextbeam.beamWidthY, inextbeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr)
00705                 
00706             deltaX = deltaSig(adelta1) > 3.5 and adelta1[0] >= limit
00707             if ii < len(listbeam) -2:
00708                 if deltaX==False and adelta1[0]*adelta2[0] > 0. and  math.fabs(adelta1[0]+adelta2[0]) >= limit:
00709                     #print " positive, "+str(adelta1[0]+adelta2[0])+ " limit="+str(limit)
00710                     deltaX = True
00711                 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:
00712                     deltaX = False
00713                     #print " negative, "+str(adelta1[0]/adelta2[0])
00714                 #else:
00715                 #    print str(adelta1[0]/adelta2[0])
00716 
00717             # check movemnts in Y
00718             adelta1 = delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr)
00719             adelta2 = (0.,1.e9)
00720             if iNNbeam.Type != -1:
00721                 adelta2 = delta(inextbeam.Y, inextbeam.Yerr, iNNbeam.Y, iNNbeam.Yerr)
00722                 
00723             deltaY = deltaSig(adelta1) > 3.5 and adelta1[0] >= limit
00724             if ii < len(listbeam) -2:
00725                 if deltaY==False and adelta1[0]*adelta2[0] > 0. and  math.fabs(adelta1[0]+adelta2[0]) >= limit:
00726                     deltaY = True
00727                 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:
00728                     deltaY = False
00729             # check movements in Z                                                    
00730             adelta = delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr)
00731 
00732             
00733             limit = float(ibeam.sigmaZ)/2.
00734             deltaZ = deltaSig(adelta) > 3.5 and adelta[0] >= limit
00735  
00736             adelta = delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr)
00737             deltasigmaZ = deltaSig(adelta) > 5.0
00738 
00739             # check dxdz
00740             adelta = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr)
00741             deltadxdz   = deltaSig(adelta) > 5.0
00742             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:
00743                 deltadxdz = False
00744             # check dydz
00745             adelta = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr)
00746             deltadydz   = deltaSig(adelta) > 5.0
00747             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:
00748                 deltadydz = False
00749             
00750             adelta = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr)
00751             deltawidthX = deltaSig(adelta) > 5
00752             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:
00753                 deltawidthX = False
00754                 
00755             adelta = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr) 
00756             deltawidthY = deltaSig(adelta) > 5
00757             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:
00758                 deltawidthY = False
00759             #if iNNbeam.Type != -1:
00760             #    deltaX = deltaX and delta(ibeam.X, ibeam.Xerr, iNNbeam.X, iNNbeam.Xerr) > 1.5
00761             #    deltaY = deltaY and delta(ibeam.Y, ibeam.Yerr, iNNbeam.Y, iNNbeam.Yerr) > 1.5
00762             #    deltaZ = deltaZ and delta(ibeam.Z, ibeam.Zerr, iNNbeam.Z, iNNbeam.Zerr) > 1.5
00763             #           
00764             #    deltasigmaZ = deltasigmaZ and delta(ibeam.sigmaZ, ibeam.sigmaZerr, iNNbeam.sigmaZ, iNNbeam.sigmaZerr) > 2.5
00765             #    deltadxdz   = deltadxdz and delta(ibeam.dxdz, ibeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr) > 2.5
00766             #    deltadydz   = deltadydz and delta(ibeam.dydz, ibeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr) > 2.5
00767             #
00768             #    deltawidthX = deltawidthX and delta(ibeam.beamWidthX, ibeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr) > 3
00769             #    deltawidthY = deltawidthY and delta(ibeam.beamWidthY, ibeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr) > 3
00770 
00771             if deltaX or deltaY or deltaZ or deltasigmaZ or deltadxdz or deltadydz or deltawidthX or deltawidthY:
00772                 docreate = True
00773                 #print "shift here: x="+str(deltaX)+" y="+str(deltaY)
00774                 #print "x1 = "+ibeam.X + " x1err = "+ibeam.Xerr
00775                 #print "x2 = "+inextbeam.X + " x2err = "+inextbeam.Xerr
00776                 #print "Lumi1: "+str(ibeam.IOVfirst) + " Lumi2: "+str(inextbeam.IOVfirst)
00777                 #print " x= "+ibeam.X+" +/- "+ibeam.Xerr
00778                 #print "weighted average x = "+tmpbeam.X +" +//- "+tmpbeam.Xerr
00779                 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)
00780         if docreate:
00781             #if ii == len(listbeam)-1:
00782             tmpbeam.IOVlast = ibeam.IOVlast
00783             tmpbeam.IOVEndTime = ibeam.IOVEndTime
00784             print "  Run: "+tmpbeam.Run +" Lumi1: "+str(tmpbeam.IOVfirst) + " Lumi2: "+str(tmpbeam.IOVlast)
00785             newlistbeam.append(tmpbeam)
00786             tmpbeam = BeamSpot()
00787             countlumi = 0
00788         tmprun = ibeam.Run
00789         countlumi += 1
00790 
00791     payloadfile = open(fileName,"w")
00792     for iload in newlistbeam:
00793         dump( iload, payloadfile )
00794     payloadfile.close()
    return newlistbeam
def CommonMethods::createWeightedPayloadsNew (   fileName,
  listbeam = [],
  weighted = True 
)

Definition at line 796 of file CommonMethods.py.

00797                                                                  :
00798     newlistbeam = []
00799     docreate = False
00800     docheck = False
00801     lastPayload = listbeam[0]
00802 
00803     firstToUse = 0
00804     lastToUse = 0
00805     for ii in range(0,len(listbeam)):
00806         docreate = False
00807         if docheck:
00808             deltaX = delta(ibeam.X, ibeam.Xerr, inextbeam.X, inextbeam.Xerr) > 1.5
00809             deltaY = delta(ibeam.Y, ibeam.Yerr, inextbeam.Y, inextbeam.Yerr) > 1.5
00810             deltaZ = delta(ibeam.Z, ibeam.Zerr, inextbeam.Z, inextbeam.Zerr) > 2.5
00811 
00812             deltasigmaZ = delta(ibeam.sigmaZ, ibeam.sigmaZerr, inextbeam.sigmaZ, inextbeam.sigmaZerr) > 2.5
00813             deltadxdz   = delta(ibeam.dxdz, ibeam.dxdzerr, inextbeam.dxdz, inextbeam.dxdzerr) > 2.5
00814             deltadydz   = delta(ibeam.dydz, ibeam.dydzerr, inextbeam.dydz, inextbeam.dydzerr) > 2.5
00815 
00816             deltawidthX = delta(ibeam.beamWidthX, ibeam.beamWidthXerr, inextbeam.beamWidthX, inextbeam.beamWidthXerr) > 3
00817             deltawidthY = delta(ibeam.beamWidthY, ibeam.beamWidthYerr, inextbeam.beamWidthY, inextbeam.beamWidthYerr) > 3
00818 
00819             #if iNNbeam.Type != -1:
00820             #    deltaX = deltaX and delta(ibeam.X, ibeam.Xerr, iNNbeam.X, iNNbeam.Xerr) > 1.5
00821             #    deltaY = deltaY and delta(ibeam.Y, ibeam.Yerr, iNNbeam.Y, iNNbeam.Yerr) > 1.5
00822             #    deltaZ = deltaZ and delta(ibeam.Z, ibeam.Zerr, iNNbeam.Z, iNNbeam.Zerr) > 1.5
00823             #           
00824             #    deltasigmaZ = deltasigmaZ and delta(ibeam.sigmaZ, ibeam.sigmaZerr, iNNbeam.sigmaZ, iNNbeam.sigmaZerr) > 2.5
00825             #    deltadxdz   = deltadxdz and delta(ibeam.dxdz, ibeam.dxdzerr, iNNbeam.dxdz, iNNbeam.dxdzerr) > 2.5
00826             #    deltadydz   = deltadydz and delta(ibeam.dydz, ibeam.dydzerr, iNNbeam.dydz, iNNbeam.dydzerr) > 2.5
00827             #
00828             #    deltawidthX = deltawidthX and delta(ibeam.beamWidthX, ibeam.beamWidthXerr, iNNbeam.beamWidthX, iNNbeam.beamWidthXerr) > 3
00829             #    deltawidthY = deltawidthY and delta(ibeam.beamWidthY, ibeam.beamWidthYerr, iNNbeam.beamWidthY, iNNbeam.beamWidthYerr) > 3
00830 
00831             if deltaX or deltaY or deltaZ or deltasigmaZ or deltadxdz or deltadydz or deltawidthX or deltawidthY:
00832                 if ii != 0:
00833                     docreate = True
00834                     lastToUse = ii-1
00835                 #print "shift here: x="+str(deltaX)+" y="+str(deltaY)
00836                 #print "x1 = "+ibeam.X + " x1err = "+ibeam.Xerr
00837                 #print "x2 = "+inextbeam.X + " x2err = "+inextbeam.Xerr
00838                 #print "Lumi1: "+str(ibeam.IOVfirst) + " Lumi2: "+str(inextbeam.IOVfirst)
00839                 #print " x= "+ibeam.X+" +/- "+ibeam.Xerr
00840                 #print "weighted average x = "+tmpbeam.X +" +//- "+tmpbeam.Xerr
00841                 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)
00842         
00843         #WARNING this will only be fine for Run based IOVs
00844         if ii >= len(listbeam) - 1 or listbeam[ii].Run != listbeam[ii+1].Run :
00845             print "close payload because end of run has been reached. Run " + listbeam[ii].Run
00846             docreate = True
00847             lastToUse = ii
00848         
00849 
00850          # check maximum lumi counts
00851 #?        if countlumi == maxNlumis:
00852 #?            print "close payload because maximum lumi sections accumulated within run "+ibeam.Run
00853 #?            docreate = True
00854 #?            countlumi = 0
00855         if docreate:
00856             tmpbeam = BeamSpot()
00857             for ibeam in listbeam[firstToUse:lastToUse]:
00858                 (tmpbeam.X, tmpbeam.Xerr) = weight(tmpbeam.X, tmpbeam.Xerr, ibeam.X, ibeam.Xerr)
00859                 (tmpbeam.Y, tmpbeam.Yerr) = weight(tmpbeam.Y, tmpbeam.Yerr, ibeam.Y, ibeam.Yerr)
00860                 (tmpbeam.Z, tmpbeam.Zerr) = weight(tmpbeam.Z, tmpbeam.Zerr, ibeam.Z, ibeam.Zerr)
00861                 (tmpbeam.sigmaZ, tmpbeam.sigmaZerr) = weight(tmpbeam.sigmaZ, tmpbeam.sigmaZerr, ibeam.sigmaZ, ibeam.sigmaZerr)
00862                 (tmpbeam.dxdz, tmpbeam.dxdzerr) = weight(tmpbeam.dxdz, tmpbeam.dxdzerr, ibeam.dxdz, ibeam.dxdzerr)
00863                 (tmpbeam.dydz, tmpbeam.dydzerr) = weight(tmpbeam.dydz, tmpbeam.dydzerr, ibeam.dydz, ibeam.dydzerr)
00864                 #print "wx = " + ibeam.beamWidthX + " err= "+ ibeam.beamWidthXerr
00865                 (tmpbeam.beamWidthX, tmpbeam.beamWidthXerr) = weight(tmpbeam.beamWidthX, tmpbeam.beamWidthXerr, ibeam.beamWidthX, ibeam.beamWidthXerr)
00866                 (tmpbeam.beamWidthY, tmpbeam.beamWidthYerr) = weight(tmpbeam.beamWidthY, tmpbeam.beamWidthYerr, ibeam.beamWidthY, ibeam.beamWidthYerr)
00867             tmpbeam.IOVfirst     = listbeam[firstToUse].IOVfirst
00868             tmpbeam.IOVBeginTime = listbeam[firstToUse].IOVBeginTime
00869             tmpbeam.Run          = listbeam[firstToUse].Run
00870             tmpbeam.Type         = 2
00871             tmpbeam.IOVlast      = listbeam[lastToUse].IOVlast
00872             tmpbeam.IOVEndTime   = listbeam[lastToUse].IOVEndTime
00873             newlistbeam.append(tmpbeam)
00874             firstToUse = lastToUse+1
00875             print "Run: " + tmpbeam.Run + " Lumi1: " + str(tmpbeam.IOVfirst) + " Lumi2: " + str(tmpbeam.IOVlast)
00876             
00877     payloadfile = open(fileName,"w")
00878     for iload in newlistbeam:
00879         dump( iload, payloadfile )
00880     payloadfile.close()

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

Definition at line 321 of file CommonMethods.py.

00322                                 :
00323     #return math.fabs( float(x) - float(nextx) )/math.sqrt(math.pow(float(xerr),2) + math.pow(float(nextxerr),2))
00324     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.

00326                  :
00327     return math.fabs(x[0])/x[1]

def CommonMethods::dirExists (   dir)

Definition at line 157 of file CommonMethods.py.

Referenced by SiStripCommissioningSource::remove().

00158                   :
00159     if dir.find("castor") != -1:
00160         lsCommand = "nsls " + dir
00161         output = commands.getstatusoutput( lsCommand )
00162         return not output[0]
00163     else:
00164         return os.path.exists(dir)

def CommonMethods::dump (   beam,
  file 
)

Definition at line 289 of file CommonMethods.py.

00290                      :
00291     end = "\n"
00292     file.write("Runnumber "+beam.Run+end)
00293     file.write("BeginTimeOfFit "+str(beam.IOVBeginTime)+end)
00294     file.write("EndTimeOfFit "+str(beam.IOVEndTime)+end)
00295     file.write("LumiRange "+str(beam.IOVfirst)+" - "+str(beam.IOVlast)+end)
00296     dumpValues(beam, file)

def CommonMethods::dumpValues (   beam,
  file 
)

Definition at line 298 of file CommonMethods.py.

00299                            :
00300     end = "\n"
00301     file.write("Type "+str(beam.Type)+end)
00302     file.write("X0 "+str(beam.X)+end)
00303     file.write("Y0 "+str(beam.Y)+end)
00304     file.write("Z0 "+str(beam.Z)+end)
00305     file.write("sigmaZ0 "+str(beam.sigmaZ)+end)
00306     file.write("dxdz "+str(beam.dxdz)+end)
00307     file.write("dydz "+str(beam.dydz)+end)
00308     file.write("BeamWidthX "+beam.beamWidthX+end)
00309     file.write("BeamWidthY "+beam.beamWidthY+end)
00310     file.write("Cov(0,j) "+str(math.pow(float(beam.Xerr),2))+" 0 0 0 0 0 0"  +end)
00311     file.write("Cov(1,j) 0 "+str(math.pow(float(beam.Yerr),2))+" 0 0 0 0 0"  +end)
00312     file.write("Cov(2,j) 0 0 "+str(math.pow(float(beam.Zerr),2))+" 0 0 0 0"  +end)
00313     file.write("Cov(3,j) 0 0 0 "+str(math.pow(float(beam.sigmaZerr),2))+" 0 0 0"  +end)
00314     file.write("Cov(4,j) 0 0 0 0 "+str(math.pow(float(beam.dxdzerr),2))+" 0 0"  +end)
00315     file.write("Cov(5,j) 0 0 0 0 0 "+str(math.pow(float(beam.dydzerr),2))+" 0"  +end)
00316     file.write("Cov(6,j) 0 0 0 0 0 0 "+str(math.pow(float(beam.beamWidthXerr),2))  +end)
00317     file.write("EmittanceX 0"+end)
00318     file.write("EmittanceY 0"+end)
00319     file.write("BetaStar 0"+end)

def CommonMethods::exit (   msg = "")

Definition at line 90 of file CommonMethods.py.

00091                 :
00092     rmLock()
00093     raise SystemExit(msg or optionstring.replace("%prog",sys.argv[0]))

def CommonMethods::isnan (   num)

Definition at line 95 of file CommonMethods.py.

00096               :
00097     fnum = float(num)
00098     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(), 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().

00080           :
00081     global lockFile
00082     commands.getstatusoutput( "touch " + lockFile)

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

Definition at line 166 of file CommonMethods.py.

00167                      :
00168     lsCommand      = ''
00169     listOfFiles    = []
00170     if dir.find('castor') != -1:
00171         lsCommand = 'ns'
00172     elif not os.path.exists(dir):
00173         print "ERROR: File or directory " + dir + " doesn't exist"
00174         return listOfFiles
00175 
00176     aCommand  = lsCommand  + 'ls '+ dir
00177     #aCommand  = lsCommand  + 'ls '+ dir + " | grep .txt"
00178     if filter != "":
00179         aCommand  += " | grep " + filter 
00180 
00181     tmpStatus = commands.getstatusoutput( aCommand )
00182     listOfFiles = tmpStatus[1].split('\n')
00183     if len(listOfFiles) == 1:
00184         if listOfFiles[0].find('No such file or directory') != -1:
00185             exit("ERROR: File or directory " + dir + " doesn't exist") 
00186 
00187     return listOfFiles            

def CommonMethods::nonzero (   self)

Definition at line 129 of file CommonMethods.py.

00129                  : # will become the nonzero method of optparse.Values
00130     "True if options were given"
00131     for v in self.__dict__.itervalues():
00132         if v is not None: return True
00133     return False
00134 
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.

00228                   :
00229     """pack high,low 32bit unsigned int to one unsigned 64bit long long
00230        Note:the print value of result number may appear signed, if the sign bit is used.
00231     """
00232     h=high<<32
00233     return (h|low)

def CommonMethods::parse (   docstring,
  arglist = None 
)

Definition at line 105 of file CommonMethods.py.

00106                                   :
00107     global optionstring
00108     global tagType
00109     optionstring = docstring
00110     match = USAGE.search(optionstring)
00111     if not match: raise ParsingError("Cannot find the option string")
00112     optlines = match.group(1).splitlines()
00113     try:
00114         p = optparse.OptionParser(optlines[0])
00115         for line in optlines[1:]:
00116             opt, help=line.split(':')[:2]
00117             short,long=opt.split(',')[:2]
00118             if '=' in opt:
00119                 action='store'
00120                 long=long.split('=')[0]
00121             else:
00122                 action='store_true'
00123             p.add_option(short.strip(),long.strip(),
00124                          action = action, help = help.strip())
00125     except (IndexError,ValueError):
00126         raise ParsingError("Cannot parse the option string correctly")
00127     return p.parse_args(arglist)

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

Definition at line 329 of file CommonMethods.py.

00330                                                                                                :
00331     tmpbeam = BeamSpot()
00332     tmpbeamsize = 0
00333     
00334     #firstRun = "1"
00335     #lastRun  = "4999999999"
00336     if IOVbase == "lumibase" and firstRun=='1' and lastRun=='4999999999' :
00337         firstRun = "1:1"
00338         lastRun = "4999999999:4999999999"
00339 
00340     inputfiletype = 0
00341     #print "first = " +firstRun
00342     #print "last = " +lastRun
00343 
00344     # for bx
00345     maplist = {}
00346     hasBX = False
00347             
00348     tmpfile = open(fileName)
00349     atmpline = tmpfile.readline()
00350     if atmpline.find('Runnumber') != -1:
00351         inputfiletype = 1
00352         if len(atmpline.split()) > 2:
00353             hasBX = True
00354             print " Input data has been calculated as function of BUNCH CROSSINGS."
00355     tmpfile.seek(0)
00356 
00357         
00358     if inputfiletype ==1:
00359 
00360         tmpBX = 0
00361         for line in tmpfile:
00362             
00363             if line.find('Type') != -1:
00364                 tmpbeam.Type = int(line.split()[1])
00365                 tmpbeamsize += 1
00366             if line.find('X0') != -1:
00367                 tmpbeam.X = line.split()[1]
00368                 #tmpbeam.Xerr = line.split()[4]
00369                 tmpbeamsize += 1
00370             #print " x = " + str(tmpbeam.X)
00371             if line.find('Y0') != -1:
00372                 tmpbeam.Y = line.split()[1]
00373                 #tmpbeam.Yerr = line.split()[4]
00374                 tmpbeamsize += 1
00375             #print " y =" + str(tmpbeam.Y)
00376             if line.find('Z0') != -1 and line.find('sigmaZ0') == -1:
00377                 tmpbeam.Z = line.split()[1]
00378                 #tmpbeam.Zerr = line.split()[4]
00379                 tmpbeamsize += 1
00380             if line.find('sigmaZ0') !=-1:
00381                 tmpbeam.sigmaZ = line.split()[1]
00382                 #tmpbeam.sigmaZerr = line.split()[5]
00383                 tmpbeamsize += 1
00384             if line.find('dxdz') != -1:
00385                 tmpbeam.dxdz = line.split()[1]
00386                 #tmpbeam.dxdzerr = line.split()[4]
00387                 tmpbeamsize += 1
00388             if line.find('dydz') != -1:
00389                 tmpbeam.dydz = line.split()[1]
00390                 #tmpbeam.dydzerr = line.split()[4]
00391                 tmpbeamsize += 1
00392             if line.find('BeamWidthX') != -1:
00393                 tmpbeam.beamWidthX = line.split()[1]
00394                 #tmpbeam.beamWidthXerr = line.split()[6]
00395                 tmpbeamsize += 1
00396             if line.find('BeamWidthY') != -1:
00397                 tmpbeam.beamWidthY = line.split()[1]
00398                 #tmpbeam.beamWidthYerr = line.split()[6]
00399                 tmpbeamsize += 1
00400             if line.find('Cov(0,j)') != -1:
00401                 tmpbeam.Xerr = str(math.sqrt( float( line.split()[1] ) ) )
00402                 tmpbeamsize += 1
00403             if line.find('Cov(1,j)') != -1:
00404                 tmpbeam.Yerr = str(math.sqrt( float( line.split()[2] ) ) )
00405                 tmpbeamsize += 1
00406             if line.find('Cov(2,j)') != -1:
00407                 tmpbeam.Zerr = str(math.sqrt( float( line.split()[3] ) ) )
00408                 tmpbeamsize += 1
00409             if line.find('Cov(3,j)') != -1:
00410                 tmpbeam.sigmaZerr = str(math.sqrt( float( line.split()[4] ) ) )
00411                 tmpbeamsize += 1
00412             if line.find('Cov(4,j)') != -1:
00413                 tmpbeam.dxdzerr = str(math.sqrt( float( line.split()[5] ) ) )
00414                 tmpbeamsize += 1
00415             if line.find('Cov(5,j)') != -1:
00416                 tmpbeam.dydzerr = str(math.sqrt( float( line.split()[6] ) ) )
00417                 tmpbeamsize += 1
00418             if line.find('Cov(6,j)') != -1:
00419                 tmpbeam.beamWidthXerr = str(math.sqrt( float( line.split()[7] ) ) )
00420                 tmpbeam.beamWidthYerr = tmpbeam.beamWidthXerr
00421                 tmpbeamsize += 1
00422             if line.find('LumiRange')  != -1:
00423                 if IOVbase=="lumibase":
00424                     tmpbeam.IOVfirst = line.split()[1]
00425                     tmpbeam.IOVlast = line.split()[3]
00426                 tmpbeamsize += 1
00427             if line.find('Runnumber') != -1:
00428                 tmpbeam.Run = line.split()[1]
00429                 if IOVbase == "runbase":
00430                     tmpbeam.IOVfirst = line.split()[1]
00431                     tmpbeam.IOVlast = line.split()[1]
00432                 if hasBX:
00433                     tmpBX = line.split()[3]
00434                 tmpbeamsize += 1
00435             if line.find('BeginTimeOfFit') != -1:
00436                 tmpbeam.IOVBeginTime = line.split()[1] +" "+line.split()[2] +" "+line.split()[3]
00437                 if IOVbase =="timebase":
00438                     tmpbeam.IOVfirst =  time.mktime( time.strptime(line.split()[1] +  " " + line.split()[2] + " " + line.split()[3],"%Y.%m.%d %H:%M:%S %Z") )
00439                 tmpbeamsize += 1
00440             if line.find('EndTimeOfFit') != -1:
00441                 tmpbeam.IOVEndTime = line.split()[1] +" "+line.split()[2] +" "+line.split()[3]
00442                 if IOVbase =="timebase":
00443                     tmpbeam.IOVlast = time.mktime( time.strptime(line.split()[1] +  " " + line.split()[2] + " " + line.split()[3],"%Y.%m.%d %H:%M:%S %Z") )
00444                 tmpbeamsize += 1
00445             if tmpbeamsize == 20:
00446                 if IOVbase=="lumibase":
00447                     tmprunfirst = int(firstRun.split(":")[0])
00448                     tmprunlast  = int(lastRun.split(":")[0])
00449                     tmplumifirst = int(firstRun.split(":")[1])
00450                     tmplumilast  = int(lastRun.split(":")[1])
00451                     acceptiov1 = acceptiov2 = False
00452                     # check lumis in the same run
00453                     if tmprunfirst == tmprunlast and int(tmpbeam.Run)==tmprunfirst:
00454                         if int(tmpbeam.IOVfirst) >= tmplumifirst and int(tmpbeam.IOVlast)<=tmplumilast:
00455                             acceptiov1 = acceptiov2 = True
00456                     # if different runs make sure you select the correct range of lumis
00457                     elif int(tmpbeam.Run) == tmprunfirst:
00458                         if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 = True
00459                     elif int(tmpbeam.Run) == tmprunlast:
00460                         if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 = True
00461                     elif tmprunfirst <= int(tmpbeam.Run) and tmprunlast >= int(tmpbeam.Run): 
00462                         acceptiov1 = acceptiov2 = True
00463                         
00464                     if acceptiov1 and acceptiov2:
00465                         if tmpbeam.Type != 2:
00466                             print "invalid fit, skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)
00467                         elif isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
00468                             print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)                       
00469                         elif hasBX:
00470                             if maplist.has_key(tmpBX) == False:
00471                                 maplist[tmpBX] = [tmpbeam]
00472                             else:
00473                                 maplist[tmpBX].append(tmpbeam)
00474                         else:
00475                             listbeam.append(tmpbeam)
00476 
00477                 elif int(tmpbeam.IOVfirst) >= int(firstRun) and int(tmpbeam.IOVlast) <= int(lastRun):
00478                     if tmpbeam.Type != 2:
00479                         print "invalid fit, skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)
00480                     elif isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
00481                         print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)
00482                     else:
00483                         listbeam.append(tmpbeam)
00484                         
00485                 tmpbeamsize = 0
00486                 tmpbeam = BeamSpot()
00487                 tmpBX = 0
00488     else:
00489 
00490         for line in tmpfile:
00491         
00492             if line.find('X0') != -1:
00493                 tmpbeam.X = line.split()[2]
00494                 tmpbeam.Xerr = line.split()[4]
00495                 tmpbeamsize += 1
00496             #print " x = " + str(tmpbeam.X)
00497             if line.find('Y0') != -1:
00498                 tmpbeam.Y = line.split()[2]
00499                 tmpbeam.Yerr = line.split()[4]
00500                 tmpbeamsize += 1
00501             #print " y =" + str(tmpbeam.Y)
00502             if line.find('Z0') != -1 and line.find('Sigma Z0') == -1:
00503                 tmpbeam.Z = line.split()[2]
00504                 tmpbeam.Zerr = line.split()[4]
00505                 tmpbeamsize += 1
00506             #print " z =" + str(tmpbeam.Z)
00507             if line.find('Sigma Z0') !=-1:
00508                 tmpbeam.sigmaZ = line.split()[3]
00509                 tmpbeam.sigmaZerr = line.split()[5]
00510                 tmpbeamsize += 1
00511             if line.find('dxdz') != -1:
00512                 tmpbeam.dxdz = line.split()[2]
00513                 tmpbeam.dxdzerr = line.split()[4]
00514                 tmpbeamsize += 1
00515             if line.find('dydz') != -1:
00516                 tmpbeam.dydz = line.split()[2]
00517                 tmpbeam.dydzerr = line.split()[4]
00518                 tmpbeamsize += 1
00519             if line.find('Beam Width X') != -1:
00520                 tmpbeam.beamWidthX = line.split()[4]
00521                 tmpbeam.beamWidthXerr = line.split()[6]
00522                 tmpbeamsize += 1
00523             if line.find('Beam Width Y') != -1:
00524                 tmpbeam.beamWidthY = line.split()[4]
00525                 tmpbeam.beamWidthYerr = line.split()[6]
00526                 tmpbeamsize += 1
00527         #if line.find('Run ') != -1:
00528             if line.find('for runs')  != -1:
00529             #tmpbeam.IOVfirst = line.split()[6].strip(',')
00530                 tmpbeam.Run      = line.split()[2]
00531                 if IOVbase == "runbase":
00532                   tmpbeam.IOVfirst = line.split()[2]
00533                   tmpbeam.IOVlast = line.split()[4]
00534                 tmpbeamsize += 1
00535             if line.find('LumiSection')  != -1:
00536                 if IOVbase=="lumibase":
00537                     tmpbeam.IOVfirst = line.split()[10]
00538                     tmpbeam.IOVlast = line.split()[10]
00539                 tmpbeamsize += 1
00540             if tmpbeamsize == 10:
00541 
00542                 if IOVbase=="lumibase":
00543                     tmprunfirst = int(firstRun.split(":")[0])
00544                     tmprunlast  = int(lastRun.split(":")[0])
00545                     tmplumifirst = int(firstRun.split(":")[1])
00546                     tmplumilast  = int(lastRun.split(":")[1])
00547                     acceptiov1 = acceptiov2 = False
00548                     # check lumis in the same run
00549                     if tmprunfirst == tmprunlast and int(tmpbeam.Run)==tmprunfirst:
00550                         if int(tmpbeam.IOVfirst) >= tmplumifirst and int(tmpbeam.IOVlast)<=tmplumilast:
00551                             acceptiov1 = acceptiov2 = True
00552                     # if different runs make sure you select the correct range of lumis
00553                     elif int(tmpbeam.Run) == tmprunfirst:
00554                         if int(tmpbeam.IOVfirst) >= tmplumifirst: acceptiov1 = True
00555                     elif int(tmpbeam.Run) == tmprunlast:
00556                         if int(tmpbeam.IOVlast) <= tmplumilast: acceptiov2 = True
00557                     elif tmprunfirst <= int(tmpbeam.Run) and tmprunlast >= int(tmpbeam.Run): 
00558                         acceptiov1 = acceptiov2 = True
00559                         
00560                     if acceptiov1 and acceptiov2:
00561                         if isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
00562                             print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)                       
00563                         elif hasBX:
00564                             if maplist.has_key(tmpBX) == False:
00565                                 maplist[tmpBX] = [tmpbeam]
00566                             else:
00567                                 maplist[tmpBX].append(tmpbeam)
00568                         else:
00569                             listbeam.append(tmpbeam)
00570 
00571                 elif int(tmpbeam.IOVfirst) >= int(firstRun) and int(tmpbeam.IOVlast) <= int(lastRun):
00572                     if isnan(tmpbeam.Z) or isnan(tmpbeam.Zerr) or isnan(tmpbeam.sigmaZerr) or isnan(tmpbeam.beamWidthXerr) or isnan(tmpbeam.beamWidthYerr):
00573                         print "invalid fit, NaN values!! skip Run "+str(tmpbeam.Run)+" IOV: "+str(tmpbeam.IOVfirst) + " to "+ str(tmpbeam.IOVlast)
00574                     else:
00575                         listbeam.append(tmpbeam)
00576                         
00577                 tmpbeamsize = 0
00578                 tmpbeam = BeamSpot()
00579                 tmpBX = 0
00580 
00581     tmpfile.close()
00582     print " got total number of IOVs = " + str(len(listbeam)) + " from file " + fileName
00583     #print " run " + str(listbeam[3].IOVfirst ) + " " + str( listbeam[3].X )
00584     if hasBX:
00585         return maplist
00586     else:
00587         return listbeam

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

Definition at line 906 of file CommonMethods.py.

00907                                                                             :
00908     readDBOut = tmpDir + "readDB_" + tagName + ".py"
00909     
00910     rFile = open(sqliteTemplateFile)
00911     rNewFile = open(readDBOut,'w')
00912     
00913     readDBTags = [('SQLITEFILE','sqlite_file:' + sqliteFileName),
00914                   ('TAGNAME',tagName)]
00915 
00916     for line in rFile:
00917         for itag in readDBTags:
00918             line = line.replace(itag[0],itag[1])
00919         rNewFile.write(line)
00920 
00921     rNewFile.close()
00922     status_rDB = commands.getstatusoutput('cmsRun '+ readDBOut)
00923     
00924     outtext = status_rDB[1]
00925     print outtext
00926     os.system("rm -f " + readDBOut)
00927     return not status_rDB[0]

def CommonMethods::rmLock ( )

Definition at line 84 of file CommonMethods.py.

00085             :
00086     global lockFile
00087     if checkLock():
00088         commands.getstatusoutput( "rm " + lockFile)

def CommonMethods::sendEmail (   mailList,
  error 
)

General utilities.

Definition at line 148 of file CommonMethods.py.

00149                              :
00150     print "Sending email to " + mailList + " with body: " + error
00151     list = mailList.split(',')
00152     for email in list:
00153         p = os.popen("mail -s \"Automatic workflow error\" " + email ,"w")
00154         p.write(error)
00155         status = p.close() 

def CommonMethods::setLockName (   name)

Definition at line 66 of file CommonMethods.py.

00067                      :
00068     global lockFile
00069     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.

00591                                                         :
00592     # sort the list
00593     if IOVbase == "lumibase":
00594         listbeam.sort( cmp = cmp_list_lumi )
00595     else:
00596         listbeam.sort( cmp = cmp_list_run )
00597     
00598     # first clean list of data for consecutive duplicates and bad fits
00599     tmpremovelist = []
00600     for ii in range(0,len(listbeam)):
00601         ibeam = listbeam[ii]
00602         datax = ibeam.IOVfirst
00603         #print str(ii) + "  " +datax
00604         if datax == '0' and IOVbase =="runbase":
00605             print " iov = 0? skip this IOV = "+ str(ibeam.IOVfirst) + " to " + str(ibeam.IOVlast)
00606             tmpremovelist.append(ibeam)
00607         
00608         if ii < len(listbeam) -1:
00609             #print listbeam[ii+1].IOVfirst
00610             if IOVbase =="lumibase":
00611                 if ibeam.Run == listbeam[ii+1].Run and ibeam.IOVfirst == listbeam[ii+1].IOVfirst:
00612                     print " duplicate IOV = "+datax+", keep only last duplicate entry"
00613                     tmpremovelist.append(ibeam)
00614             elif datax == listbeam[ii+1].IOVfirst:
00615                 print " duplicate IOV = "+datax+", keep only last duplicate entry"
00616                 tmpremovelist.append(ibeam)
00617 
00618     for itmp in tmpremovelist:
00619         listbeam.remove(itmp)

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

Definition at line 8 of file CommonMethods.py.

00009                                                        :
00010     if timeout == 0:
00011         return 1
00012     timeFormat = "%a,%Y/%m/%d,%H:%M:%S"
00013     currentTime = time.gmtime()
00014     timeoutLine = type + ' ' + time.strftime(timeFormat, currentTime) + '\n'
00015     isTimeout = False
00016     alreadyThere = False
00017     timeoutType = -1;
00018     fileExist = os.path.isfile(fileName)
00019     text = ''
00020     fields = []
00021     reset = False
00022     if timeout == -1:
00023         reset = True
00024     if fileExist:
00025         file = open(fileName)
00026         for line in file:
00027             text += line
00028             fields = line.strip('\n').split(' ')
00029             if fields[0] == type:
00030                 alreadyThere = True
00031                 if reset:
00032                     text = text.replace(line,'')
00033                     continue
00034 
00035                 fileTime = time.strptime(fields[1],timeFormat)
00036                 myTime = time.mktime(fileTime)
00037                 referenceTime = time.mktime(time.gmtime())
00038                 daylight = 0
00039                 if currentTime.tm_isdst == 0:
00040                     daylight = 3600
00041                 elapsedTime = referenceTime-myTime-daylight
00042                 if elapsedTime > timeout:
00043                     isTimeout = True
00044                     timeoutType = 1
00045                     print "Timeout! " + str(elapsedTime) + " seconds passed since the " + type + " timeout was set and you can't tolerate more than " + str(timeout) + " seconds!"
00046                 else:
00047                     timeoutType = 0
00048                     print "Timeout of type " + type + " already exist and was generated " + str(elapsedTime) + " seconds ago at " + fields[1]
00049 
00050         file.close()
00051 
00052     if not fileExist or not alreadyThere and not reset:
00053         timeoutType = -1
00054         text += timeoutLine
00055 
00056     if not fileExist or not alreadyThere or isTimeout or (reset and alreadyThere):
00057         if fileExist:
00058             commands.getstatusoutput("rm -rf " + fileName)
00059         file = open(fileName,'w')
00060         file.write(text)
00061         file.close()
00062 
00063     return timeoutType
00064 

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.

00236              :
00237     """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
00238     """
00239     high=i>>32
00240     low=i&0xFFFFFFFF
00241     return(high,low)

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

Definition at line 243 of file CommonMethods.py.

00244                    :
00245     """unpack 64bit lumiid to dictionary {'run','lumisection'}
00246     """
00247     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.

00938                                                                            :
00939     # Changing permissions to metadata
00940     acmd = "chmod a+w " + sqliteFileDirName + sqliteFileName + ".txt"
00941     outcmd = commands.getstatusoutput(acmd)
00942     print acmd
00943 #    print outcmd[1]
00944     if outcmd[0]:
00945         print "Can't change permission to file: " + sqliteFileDirName + sqliteFileName + ".txt"
00946         return False
00947 
00948     acmd = "cp " + sqliteFileDirName + sqliteFileName + ".db " + sqliteFileDirName + sqliteFileName + ".txt ." 
00949     print acmd
00950     outcmd = commands.getstatusoutput(acmd)
00951     print outcmd[1]
00952     if outcmd[0]:
00953         print "Couldn't cd to " + sqliteFileDirName
00954         return False
00955 
00956     acmd = "tar -cvjf " + sqliteFileName + ".tar.bz2 " + sqliteFileName + ".db " + sqliteFileName + ".txt"
00957     print acmd
00958     outcmd = commands.getstatusoutput(acmd)
00959     print outcmd[1]
00960     if outcmd[0]:
00961         print "Couldn't zip the files!"
00962         return False
00963 
00964     acmd = "chmod a+w " + sqliteFileName + ".tar.bz2"
00965     outcmd = commands.getstatusoutput(acmd)
00966     print acmd
00967 #    print outcmd[1]
00968     if outcmd[0]:
00969         print "Can't change permission to file: " + sqliteFileDirName + sqliteFileName + ".tar.bz2"
00970         return False
00971 
00972     acmd = "scp -p " + sqliteFileName + ".tar.bz2" + " webcondvm.cern.ch:" + dropbox
00973     print acmd
00974     outcmd = commands.getstatusoutput(acmd)
00975     print outcmd[1]
00976     if outcmd[0]:
00977         print "Couldn't scp the files to DropBox!"
00978         return False
00979 
00980 
00981     acmd = "mv " + sqliteFileName + ".tar.bz2 " + sqliteFileDirName
00982     print acmd
00983     outcmd = commands.getstatusoutput(acmd)
00984     print outcmd[1]
00985     if outcmd[0]:
00986         print "Couldn't mv the file to " + sqliteFileDirName
00987         return False
00988 
00989     acmd = "rm " + sqliteFileName + ".db " + sqliteFileName + ".txt"
00990     print acmd
00991     outcmd = commands.getstatusoutput(acmd)
00992     print outcmd[1]
00993     if outcmd[0]:
00994         print "Couldn't rm the db and txt files"
00995         return False
00996 
00997 #    acmd = "scp -p " + sqliteFileDirName + sqliteFileName + ".txt webcondvm.cern.ch:/tmp"
00998 #    outcmd = commands.getstatusoutput(acmd)
00999 #    print acmd
01000 #    print outcmd[1]
01001 #    if outcmd[0]:
01002 #        print "Can't change permission to file: " + sqliteFileName + ".txt"
01003 #        return False
01004 
01005 #    acmd = "ssh webcondvm.cern.ch \"mv /tmp/" + sqliteFileName + ".db /tmp/" + sqliteFileName + ".txt " + dropbox +"\""
01006 #    print acmd
01007 #    outcmd = commands.getstatusoutput(acmd)
01008 #    print outcmd[1]
01009 #    if outcmd[0]:
01010 #        print "Can't move files from tmp to dropbox!"
01011         return False
01012 
01013 #    acmd = "ssh webcondvm.cern.ch \"mv /tmp/" + final_sqlite_file_name + ".txt "+dropbox +"\""
01014 #    outcmd = commands.getstatusoutput(acmd)
01015 #    print acmd
01016 #    print outcmd[1]
01017 #    if outcmd[0]:
01018 #        print "Can't change permission to file: " + sqliteFileName + ".txt"
01019 #        return False
01020 
01021     return True
01022 
def CommonMethods::weight (   x1,
  x1err,
  x2,
  x2err 
)

Definition at line 268 of file CommonMethods.py.

Referenced by lhef::LHERunInfo::Counter::add(), KalmanVertexUpdator< N >::add(), reco::TrackKinematics::add(), PhysicsTools::LeastSquares::add(), MuonTruth::addChannel(), RPCRawDataCounts::addDccRecord(), CaloValidationStatistics::addEntry(), Accumulator::addEntry(), MultiTrajectoryStateAssembler::addInvalidState(), TtFullLepKinSolver::addKinSolInfo(), addMeas(), MuonCSCChamberResidual::addResidual(), MuonDT13ChamberResidual::addResidual(), MuonDT2ChamberResidual::addResidual(), CSCPairResidualsConstraint::addTrack(), FedCablingAlgorithm::analyse(), TtSemiLepSignalSelMVATrainer::analyze(), Rivet::CMS_EWK_10_012::analyze(), HistoAnalyzer< C >::analyze(), MuonTruth::analyze(), Rivet::CMS_FWD_10_006::analyze(), JetAnaPythia< Jet >::analyze(), EBBeamHodoTask::analyze(), Rivet::CMS_2010_S8656010::analyze(), Rivet::CMS_2011_S8884919::analyze(), Rivet::CMS_2010_S8547297::analyze(), Rivet::MC_LES_HOUCHES_SYSTEMATICS_CMS::analyze(), EEBeamHodoTask::analyze(), zPdfUnc::analyze(), JetTagMVATreeTrainer::analyze(), EWKSystUnc::analyze(), ZLONLOHistogrammer::analyze(), Rivet::CMS_2011_S8968497::analyze(), Rivet::CMS_2011_S8978280::analyze(), IsolatedTracksNxN::analyze(), Rivet::CMS_FWD_10_011::analyze(), Rivet::CMS_QCD_10_010::analyze(), ZMCHistogrammer::analyze(), EgHLTOfflineSource::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(), PairProductionSimulator::compute(), CandIsolatorFromDeposits::SingleDeposit::compute(), MuScleFitUtils::computeWeight(), MassWindow::count(), BackgroundHandler::countEventsInAllWindows(), HcalTB02SD::curve_LY(), ECalSD::curve_LY(), DreamSD::curve_LY(), SignedImpactParameter3D::distanceWithJetAxis(), CSCOfflineMonitor::doEfficiencies(), CSCValidation::doEfficiencies(), PhysicsTools::TrainProcessor::doTrainData(), MuScleFit::duringFastLoop(), CalorimetryManager::EMShowerSimulation(), CaloTowersCreationAlgo::emShwrLogWeightPos(), DTResolutionAnalysisTest::endRun(), DTCertificationSummary::endRun(), edm::RefVector< TrackingRecHitCollection >::erase(), reco::Jet::etaetaMoment(), reco::Jet::etaphiMoment(), reco::Jet::etaPhiStatistics(), evaluateTtFullHadSignalSel(), evaluateTtSemiLepSignalSel(), HParticle::Fill(), HMassVSPart::Fill(), HMassVSPartProfile::Fill(), ConfigurableHisto::fill(), HPartVSEta::Fill(), HPartVSPt::Fill(), HPartVSPhi::Fill(), MuonSystemMapPlot1D::fill_dxdz(), MuonSystemMapPlot1D::fill_dydz(), MuonSystemMapPlot1D::fill_x(), MuonSystemMapPlot1D::fill_y(), SiPixelDataQuality::fillGlobalQualityPlot(), HLXMonitor::FillHistograms(), recoBSVTagInfoValidationAnalyzer::fillRecoToSim(), SVTagInfoValidationAnalyzer::fillRecoToSim(), SVTagInfoValidationAnalyzer::fillSimToReco(), recoBSVTagInfoValidationAnalyzer::fillSimToReco(), reco::PositiveSideGhostTrackFitter::fit(), MuonResiduals1DOFFitter::fit(), PFDisplacedVertexFinder::fitVertexFromSeed(), SherpaHadronizer::generatePartonsAndHadronize(), CaloSD::getAttenuation(), ECalSD::getBirkL3(), HCalSD::getEnergyDeposit(), ECalSD::getEnergyDeposit(), EcalTBH4BeamSD::getEnergyDeposit(), HcalTB02SD::getEnergyDeposit(), HcalTB06BeamSD::getEnergyDeposit(), EcalClusterTools::getEnergyDepTopology(), GsfBetheHeitlerUpdator::getMixtureParameters(), TtFullLepKinSolver::getNuSolution(), DreamSD::getStepInfo(), AdaptiveVertexFitter::getWeight(), CaloMeanResponse::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(), MtvClusterizer1D< T >::operator()(), SmsModeFinder3d::operator()(), FsmwModeFinder3d::operator()(), FsmwClusterizer1D< T >::operator()(), EnergyLossPlain::optimal(), DTSegmentAnalysisTest::performClientDiagnostic(), reco::Jet::phiphiMoment(), MuonResiduals6DOFrphiFitter::plot(), MuonResiduals6DOFFitter::plot(), MuonResiduals5DOFFitter::plot(), MuonResiduals1DOFFitter::plot(), MuonResidualsFitter::plotweighted(), PrescaleWeightProvider::prescaleWeight(), PrintMaterialBudgetInfo::printInfo(), WeakEffectsWeightProducer::produce(), edm::BeamHaloProducer::produce(), AlCaElectronsProducer::produce(), ISRWeightProducer::produce(), ISRGammaWeightProducer::produce(), FSRWeightProducer::produce(), edm::BeamHaloSource::produce(), EcalTBWeightsXMLTranslator::readWeightSet(), KalmanVertexUpdator< N >::remove(), CaloTowersCreationAlgo::rescale(), CaloTowersCreationAlgo::rescaleTowers(), EcalClusterTools::roundnessSelectedBarrelRecHits(), UpdateTProfile::setBinContent(), FWGUIManager::setFrom(), Histograms::SetWeight(), CandIsolatorFromDeposits::SingleDeposit::SingleDeposit(), sistrip::MeasureLA::summarize_module_muH_byLayer(), TBposition(), hcalCalib::Terminate(), SiTrivialDigitalConverter::truncate(), EcalTPGParamBuilder::uncodeWeight(), KalmanVertexUpdator< N >::update(), CommissioningTask::updateHistoSet(), reco::PFDisplacedVertexSeed::updateSeedPoint(), GsfMaterialEffectsUpdator::updateState(), MultiVertexFitter::updateWeights(), PrimaryVertexMonitor::vertexPlots(), VertexTrackFactory< 6 >::vertexTrack(), vtxMean(), TtFullLepKinSolver::WeightSolfromMC(), and MuonResidualsTwoBin::wmean().

00269                               :
00270     #print "x1 = "+str(x1)+" +/- "+str(x1err)+" x2 = "+str(x2)+" +/- "+str(x2err)
00271     x1     = float(x1)
00272     x1err  = float(x1err)
00273     x2     = float(x2)
00274     x2err  = float(x2err)
00275     tmperr = 0.
00276     if x2err < 1e-6 :
00277         x2err = 1e-6
00278     if x1err < 1e-6:
00279         x1 = x2/(x2err * x2err)
00280         tmperr = 1/(x2err*x2err)
00281     else:
00282         x1 = x1/(x1err*x1err) + x2/(x2err * x2err)
00283         tmperr = 1/(x1err*x1err) + 1/(x2err*x2err)
00284     x1 = x1/tmperr
00285     x1err = 1/tmperr
00286     x1err = math.sqrt(x1err)
00287     return (str(x1), str(x1err))

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

Definition at line 882 of file CommonMethods.py.

00883                                                                                                    :
00884     writeDBOut = tmpDir + "write2DB_" + tagName + ".py"
00885     wFile      = open(sqliteTemplateFile)
00886     wNewFile   = open(writeDBOut,'w')
00887     
00888     writeDBTags = [('SQLITEFILE','sqlite_file:' + sqliteFileName),
00889                    ('TAGNAME',tagName),
00890                    ('TIMETYPE',timeType),
00891                    ('BEAMSPOTFILE',beamSpotFile)]
00892     
00893     for line in wFile:
00894         for itag in writeDBTags:
00895             line = line.replace(itag[0],itag[1])
00896         wNewFile.write(line)
00897             
00898     wNewFile.close()
00899     print "writing sqlite file ..."
00900     status_wDB = commands.getstatusoutput('cmsRun '+ writeDBOut)
00901     print status_wDB[1]
00902         
00903     os.system("rm -f " + writeDBOut)
00904     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.