Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:11

0001 #!/usr/bin/env python3
0002 import os, time,sys
0003 
0004 class configuration:
0005    datasetPat  = '/StreamExpress/Run2018*-SiStripCalMinBias__AAG__-Express-v*/ALCARECO'
0006    CMSSWDIR    = 'TO_FILL_IN'
0007    RUNDIR      = CMSSWDIR+'CalibTracker/SiStripCommon/test/MakeCalibrationTrees/'
0008    CASTORDIR   = '/store/group/dpg_tracker_strip/comm_tracker/Strip/Calibration/calibrationtree/GR18__AAG__'
0009    nFilesPerJob= 25
0010    collection  = "ALCARECOSiStripCalMinBias__AAG__"
0011    globalTag   = "TO_UPDATE"
0012    initEnv     = ""
0013    dasClient   = "dasgoclient"
0014    eosLs       = "eos ls "
0015    def  __init__(self,AAG=False,debug=False):
0016       self.relaunchList= []
0017       self.firstRun    = -1
0018       self.lastRun     = 999999
0019       self.launchedRuns = []
0020       self.AAG          = AAG
0021       self.datasetPat   = self.datasetPat.replace("__AAG__","AAG" if self.AAG else "")
0022       self.CASTORDIR    = self.CASTORDIR.replace ("__AAG__","_Aag" if self.AAG else "")
0023       self.collection   = self.collection.replace("__AAG__","AAG" if self.AAG else "")
0024       self.initEnv+='cd ' + self.CMSSWDIR + '; '
0025       self.initEnv+='export CMS_PATH=/cvmfs/cms.cern.ch; '
0026       self.initEnv+='source /afs/cern.ch/cms/cmsset_default.sh' + ';'
0027       self.initEnv+='eval `scramv1 runtime -sh`' + ';'
0028 
0029       proxyFile = "/afs/cern.ch/user/%s/%s/private/x509up_u%s"%(os.environ["USER"][0],os.environ["USER"],os.geteuid())
0030       if not os.path.isfile(proxyFile):
0031         print("WARNING : No private proxy file to use. Can't run on data outside of CERN")
0032       else:
0033         T = (time.time()-os.stat(proxyFile).st_mtime)
0034         print("proxy file created %sh and %s min ago"%(int(T)/3600, int(T)/60- 60*(int(T)/3600)))
0035         if T < 36000:
0036           # Proxy valid for 12hours --> Ignore files created more than 10h ago"
0037           self.initEnv+='export X509_USER_PROXY=%s ;'%proxyFile
0038         else:
0039           print("WARNING : proxy file expired. Can't run on data outside of CERN")
0040 
0041       self.initEnv+='cd -;'
0042       self.submit = not debug
0043       self.integrity = False
0044       self.setupEnviron()
0045       print("Integrity = %s"%self.checkIntegrity())
0046 
0047    def checkIntegrity(self):
0048       goodConfig=True
0049 
0050       #Check dataset :
0051       d = self.datasetPat.split("/")
0052       if not len(d) == 4:
0053          print("Bad dataset. Expecting 4 '/'")
0054          goodConfig=False
0055       if not d[0]=='':
0056          print("Bad dataset. Expecting nothing before first '/'")
0057          goodConfig=False
0058       if not len(d[1])>0 or not len(d[2]) > 0 or not len(d[3]) > 0:
0059          print("Bad dataset. Expecting text between '/'")
0060          goodConfig=False
0061       if os.path.isdir(self.datasetPat):
0062          print("Bad dataset. Can't be an existing directory")
0063          goodConfig=False
0064       #Check all paths exist
0065       if not os.path.isdir(self.CMSSWDIR):
0066          print("CMSSW dir does not exist.")
0067          goodConfig = False
0068       if not os.path.isdir(self.RUNDIR):
0069          print("RUN dir does not exist.")
0070          goodConfig = False
0071 
0072       #Check castor path exists FIXME
0073       cmd = self.eosLs.replace("-lrth","")+self.CASTORDIR
0074       cmd = cmd[:-2]+"*"
0075       (status,output) = subprocess.getstatusoutput(cmd)
0076       if status or not self.CASTORDIR.split("/")[-1] in output:
0077          print(cmd)
0078          print(output)
0079          print("CASTOR dir does not exist.")
0080          goodConfig = False
0081       self.integrity = goodConfig
0082       return goodConfig
0083 
0084    def setupEnviron(self):
0085       os.environ['PATH'] = os.getenv('PATH')+':/afs/cern.ch/cms/sw/common/'
0086       os.environ['CMS_PATH']='/afs/cern.ch/cms'
0087       os.environ['FRONTIER_PROXY'] = 'http://cmst0frontier.cern.ch:3128'
0088       os.environ['SCRAM_ARCH']='slc6_amd64_gcc530'
0089    def __str__(self):
0090       description = "Configuration :\n"
0091       description+= "First run  = %s\n"   %self.firstRun
0092       description+= "After Abort= %s\n"   %self.AAG
0093       description+= "dataset    = %s\n"   %self.datasetPat
0094       description+= "CMSSW      = %s\n"   %self.CMSSWDIR
0095       description+= "RUNDIR     = %s\n"   %self.RUNDIR
0096       description+= "CASTOR     = %s\n"   %self.CASTORDIR
0097       description+= "nFiles     = %s\n"   %self.nFilesPerJob
0098       description+= "collection = %s\n"   %self.collection
0099       description+= "initEnv    = %s\n"   %self.initEnv
0100       description+= "submit     = %s\n"   %self.submit
0101       return description
0102 
0103 if __name__ == "__main__":
0104    c = configuration(True)
0105    print(c)
0106 
0107