CMS 3D CMS Logo

Namespaces | Functions | Variables

tools Namespace Reference

Namespaces

namespace  embedder
namespace  matcher
namespace  prototypes
namespace  validator

Functions

def addCrabInputFile
def copyFilesFromCastor
def copyFilesLocal
def dqmWorkflowName
def haddInCastor
def haddLocal
def listFilesInCastor
def listFilesLocal
def loadCmsProcess
def loadCmsProcessFile
def loadCrabCfg
def loadCrabDefault
def parseInput
def prependPaths
def replaceTemplate
def setGridEnv
def writeCfg
def writeCfgPkl

Variables

tuple arch = os.getenv('SCRAM_ARCH', None)
tuple localrt = os.getenv('LOCALRT', None)

Function Documentation

def tools::addCrabInputFile (   crabCfg,
  inputFile 
)

Definition at line 173 of file tools.py.

00174                                        :
00175     additionalInputFiles = ''
00176     if crabCfg.has_option('USER','additional_input_files'):
00177         additionalInputFiles = crab_cfg_parser.get('USER','additional_input_files')
00178 
00179     if additionalInputFiles: additionalInputFiles += ',%s' % inputFile
00180     else: additionalInputFiles = inputFile
00181 
00182     crabCfg.set('USER','additional_input_files',additionalInputFiles)
00183 
00184     return crabCfg

def tools::copyFilesFromCastor (   castor_dir,
  output_dir,
  type = 'root' 
)

Definition at line 47 of file tools.py.

00048                                                           :
00049     from subprocess import call
00050     files = listFilesInCastor(castor_dir,type,'')
00051 
00052     print "Copying files from %s to %s" % (castor_dir,output_dir) 
00053     for item in files:
00054         cmd = ['rfcp',item,output_dir] 
00055         print "..." + item
00056         retcode = call(cmd)
00057         if retcode != 0: raise RuntimeError,'Error in copying file %s to directory %s' % (item,output_dir)
00058 
00059     return 0

def tools::copyFilesLocal (   dir,
  output_dir,
  type = 'root' 
)

Definition at line 60 of file tools.py.

00061                                               :
00062     if not dir: raise ValueError,'Please specify valid dir'
00063     if not output_dir: raise ValueError,'Please specify valid output dir'
00064   
00065     from subprocess import call
00066     files = listFilesLocal(dir,type)
00067     cmd = ['cp']
00068     cmd.extend(files)
00069     cmd.append(output_dir)
00070     print cmd 
00071     retcode = call(cmd)
00072     return retcode

def tools::dqmWorkflowName (   datasetpath,
  type,
  rev = 1 
)

Definition at line 15 of file tools.py.

00016                                            :
00017     workflowName = datasetpath
00018     sections = workflowName.split('/')[1:]
00019     workflowName = '/%s/%s-%s-rev%d/%s' % (sections[0],sections[1],type,rev,sections[2])
00020     
00021     return workflowName 
   
def tools::haddInCastor (   castor_dir,
  result_file,
  type = 'root',
  prefix = 'rfio:',
  suffix = None 
)

Definition at line 73 of file tools.py.

00073                                                                     :',suffix = None):
00074     if not castor_dir: raise ValueError,'Please specify valid castor dir'
00075     if not result_file: raise ValueError,'Please specify valid output file name'
00076 
00077     #cmd = 'hadd %s `./listfilesCastor %s | grep %s`'%(result_file,castor_dir,type)
00078     #print "Running",cmd
00079     #os.system(cmd)
00080     from subprocess import call
00081     files = listFilesInCastor(castor_dir,type,prefix)
00082     if suffix: files = [item + suffix for item in files]
00083  
00084     cmd = ['hadd',result_file]
00085     cmd.extend(files)
00086     #print cmd
00087     retcode = call(cmd)
00088     return retcode
00089 
def tools::haddLocal (   dir,
  result_file,
  type = 'root' 
)

Definition at line 90 of file tools.py.

00091                                             :
00092     if not dir: raise ValueError,'Please specify valid dir'
00093     if not result_file: raise ValueError,'Please specify valid output file name'
00094 
00095     from subprocess import call
00096     files = listFilesLocal(dir,type)
00097     cmd = ['hadd',result_file]
00098     cmd.extend(files)
00099     #print cmd
00100     retcode = call(cmd)
00101     return retcode

def tools::listFilesInCastor (   castor_dir,
  type = 'root',
  prefix = 'rfio:' 
)

Definition at line 22 of file tools.py.

00022                                                              :'):
00023     if not castor_dir: raise ValueError,'Please specify valid castor dir'
00024 
00025     from subprocess import Popen,PIPE
00026     p1 = Popen(['nsls',castor_dir],stdout=PIPE)
00027     #p2 = Popen(['grep',type],stdin=p1.stdout,stdout=PIPE)
00028     #files = [prefix + castor_dir + "/" + item[:-1] for item in p2.stdout]
00029     #p2.stdout.close()
00030     files = [ "%s%s/%s" % (prefix,castor_dir,item.rstrip()) for item in p1.stdout if item.find(type) != -1 ] 
00031     p1.stdout.close()
00032     return files
00033 
def tools::listFilesLocal (   dir,
  type = 'root' 
)

Definition at line 34 of file tools.py.

00035                                      :
00036     if not dir: raise ValueError,'Please specify valid dir'
00037 
00038     #from subprocess import Popen,PIPE
00039     #p1 = Popen(['ls',dir],stdout=PIPE)
00040     #p2 = Popen(['grep',type],stdin=p1.stdout,stdout=PIPE)
00041     #files = [dir + "/" + item[:-1] for item in p2.stdout]
00042     #p2.stdout.close()
00043     files = os.listdir(dir)
00044     files = [ "%s/%s" % (dir,item) for item in files if item.find(type) != -1 ]
00045 
00046     return files

def tools::loadCmsProcess (   psetPath)

Definition at line 136 of file tools.py.

00137                             :
00138     module = __import__(psetPath)
00139     process = sys.modules[psetPath].process
00140 
00141     import copy 
00142     processNew = copy.copy(process)
00143     return processNew

def tools::loadCmsProcessFile (   psetName)

Definition at line 132 of file tools.py.

00133                                 :
00134     pset = imp.load_source("psetmodule",psetName)
00135     return pset.process

def tools::loadCrabCfg (   cfgName = None)

Definition at line 168 of file tools.py.

00169                              :
00170     config = ConfigParser.ConfigParser()
00171     if cfgName: config.read(cfgName)
00172     return config

def tools::loadCrabDefault (   crabCfg,
  config 
)

Definition at line 185 of file tools.py.

00186                                    :
00187     # CRAB section
00188     if not crabCfg.has_section('CRAB'): crabCfg.add_section('CRAB')
00189     crabCfg.set('CRAB','jobtype','cmssw')
00190 
00191     if hasattr(config,'scheduler') and config.scheduler: crabCfg.set('CRAB','scheduler',config.scheduler) 
00192     else: crabCfg.set('CRAB','scheduler','CAF')
00193 
00194     if hasattr(config,'useserver') and config.useserver: crabCfg.set('CRAB','use_server',1)
00195 
00196     # CMSSW section
00197     if not crabCfg.has_section('CMSSW'): crabCfg.add_section('CMSSW')
00198     if hasattr(config,'datasetpath') and config.datasetpath: crabCfg.set('CMSSW','datasetpath',config.datasetpath)
00199     else: crabCfg.set('CMSSW','datasetpath','/XXX/YYY/ZZZ') 
00200     crabCfg.set('CMSSW','pset','pset.py')
00201 
00202     # Splitting config
00203     crabCfg.remove_option('CMSSW','total_number_of_events')
00204     crabCfg.remove_option('CMSSW','events_per_job')
00205     crabCfg.remove_option('CMSSW','number_of_jobs')
00206     crabCfg.remove_option('CMSSW','total_number_of_lumis')
00207     crabCfg.remove_option('CMSSW','lumis_per_job')
00208     crabCfg.remove_option('CMSSW','lumi_mask')
00209     crabCfg.remove_option('CMSSW','split_by_run')
00210  
00211     if hasattr(config,'runselection') and config.runselection: crabCfg.set('CMSSW','runselection',config.runselection)
00212     """
00213     if hasattr(config,'totalnumberevents'): crabCfg.set('CMSSW','total_number_of_events',config.totalnumberevents)
00214     if hasattr(config,'eventsperjob'): crabCfg.set('CMSSW','events_per_job',config.eventsperjob) 
00215     """
00216     if hasattr(config,'splitByLumi') and config.splitByLumi:
00217         crabCfg.set('CMSSW','total_number_of_lumis',config.totalnumberlumis)
00218         crabCfg.set('CMSSW','lumis_per_job',config.lumisperjob)
00219         if hasattr(config,'lumimask') and config.lumimask: crabCfg.set('CMSSW','lumi_mask',config.lumimask)
00220     else:
00221         crabCfg.set('CMSSW','split_by_run',1)
00222  
00223     # USER section
00224     if not crabCfg.has_section('USER'): crabCfg.add_section('USER')  
00225 
00226     # Stageout config
00227     if hasattr(config,'stageOutCAF') and config.stageOutCAF:
00228         crabCfg.set('USER','return_data',0)                
00229         crabCfg.set('USER','copy_data',1)  
00230         crabCfg.set('USER','storage_element','T2_CH_CAF')
00231         crabCfg.set('USER','user_remote_dir',config.userdircaf)
00232         crabCfg.set('USER','check_user_remote_dir',0)
00233     elif hasattr(config,'stageOutLocal') and config.stageOutLocal:
00234         crabCfg.set('USER','return_data',1)                
00235         crabCfg.set('USER','copy_data',0)
00236         crabCfg.remove_option('USER','storage_element')
00237         crabCfg.remove_option('USER','user_remote_dir')
00238         crabCfg.remove_option('USER','check_user_remote_dir')
00239 
00240     if hasattr(config,'email') and config.email: crabCfg.set('USER','eMail',config.email)
00241     crabCfg.set('USER','xml_report','crabReport.xml')
00242 
00243     if hasattr(config,'runOnGrid') and config.runOnGrid:
00244         crabCfg.remove_section('CAF')
00245     else:
00246         if not crabCfg.has_section('CAF'): crabCfg.add_section('CAF')
00247         crabCfg.set('CAF','queue',config.queueAtCAF) 
00248     
00249     return crabCfg
def tools::parseInput (   inputFields,
  requiredFields = () 
)

Definition at line 114 of file tools.py.

00115                                                :
00116 
00117     class options: pass
00118     for item in sys.argv:
00119         option = item.split('=')[0]
00120         if option in inputFields:
00121             value = item.split('=')[1]
00122             if value in ('true','True','yes','Yes'): value = True
00123             elif value in ('false','False','no','No'): value = False
00124 
00125             setattr(options,option,value)
00126 
00127     for item in requiredFields:
00128         if not hasattr(options,item):
00129             raise RuntimeError,'Need to set "%s"' % item
00130 
00131     return options

def tools::prependPaths (   process,
  seqname 
)

Definition at line 144 of file tools.py.

00145                                  :
00146     for path in process.paths: 
00147         getattr(process,path)._seq = getattr(process,seqname)*getattr(process,path)._seq

def tools::replaceTemplate (   template,
  opts 
)

Definition at line 5 of file tools.py.

00006                                     :
00007     result = open(template).read()
00008     for item in opts:
00009          old = '@@%s@@'%item
00010          new = str(opts[item])
00011          print "Replacing",old,"to",new
00012          result = result.replace(old,new)
00013 
00014     return result
 
def tools::setGridEnv (   cmssw_dir)

Definition at line 102 of file tools.py.

00103                          :
00104     cwd = os.getcwd()
00105     os.chdir(cmssw_dir)
00106 
00107     os.system('source /afs/cern.ch/cms/LCG/LCG-2/UI/cms_ui_env.sh')
00108     os.system('cmsenv')
00109     os.system('source /afs/cern.ch/cms/ccs/wm/scripts/Crab/crab.sh')
00110  
00111     os.chdir(cwd)
00112  
00113     return

def tools::writeCfg (   process,
  dir,
  psetName 
)

Definition at line 148 of file tools.py.

00149                                   :
00150     if not os.path.exists(dir): os.makedirs(dir)
00151     open(dir + '/' + psetName,'w').write(process.dumpPython())

def tools::writeCfgPkl (   process,
  dir,
  psetName 
)

Definition at line 152 of file tools.py.

00153                                      :
00154     if not os.path.exists(dir): os.makedirs(dir)
00155 
00156     pklFileName = psetName.split('.')[0] + '.pkl'
00157     pklFile = open(dir + '/' + pklFileName,"wb")
00158     myPickle = pickle.Pickler(pklFile)
00159     myPickle.dump(process)
00160     pklFile.close()
00161  
00162     outFile = open(dir + '/' + psetName,"w")
00163     outFile.write("import FWCore.ParameterSet.Config as cms\n")
00164     outFile.write("import pickle\n")
00165     outFile.write("process = pickle.load(open('%s', 'rb'))\n" % pklFileName)
00166     outFile.close()
00167 


Variable Documentation

tuple tools::arch = os.getenv('SCRAM_ARCH', None)

Definition at line 4 of file __init__.py.

tuple tools::localrt = os.getenv('LOCALRT', None)

Definition at line 3 of file __init__.py.