CMS 3D CMS Logo

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

Functions

def haddInCastor
 
def haddLocal
 
def listFilesInCastor
 
def listFilesLocal
 
def loadCmsProcess
 
def loadCrabCfg
 
def loadCrabDefault
 
def parseInput
 
def prependPaths
 
def replaceTemplate
 
def setGridEnv
 
def writeCfg
 

Function Documentation

def tools.haddInCastor (   castor_dir,
  result_file,
  type = 'root',
  prefix = 'rfio:',
  suffix = None 
)

Definition at line 34 of file tools.py.

References listFilesInCastor().

34 
35 def haddInCastor(castor_dir,result_file,type = 'root',prefix = 'rfio:',suffix = None):
36  if not castor_dir: raise ValueError,'Please specify valid castor dir'
37  if not result_file: raise ValueError,'Please specify valid output file name'
38 
39  #cmd = 'hadd %s `./listfilesCastor %s | grep %s`'%(result_file,castor_dir,type)
40  #print "Running",cmd
41  #os.system(cmd)
42  from subprocess import call
43  files = listFilesInCastor(castor_dir,type,prefix)
44  if suffix: files = [item + suffix for item in files]
45 
46  cmd = ['hadd',result_file]
47  cmd.extend(files)
48  #print cmd
49  retcode = call(cmd)
50  return retcode
def listFilesInCastor
Definition: tools.py:14
def haddInCastor
Definition: tools.py:34
def tools.haddLocal (   dir,
  result_file,
  type = 'root' 
)

Definition at line 51 of file tools.py.

References listFilesLocal().

51 
52 def haddLocal(dir,result_file,type = 'root'):
53  if not dir: raise ValueError,'Please specify valid dir'
54  if not result_file: raise ValueError,'Please specify valid output file name'
55 
56  from subprocess import call
57  files = listFilesLocal(dir,type)
58  cmd = ['hadd',result_file]
59  cmd.extend(files)
60  #print cmd
61  retcode = call(cmd)
62  return retcode
def listFilesLocal
Definition: tools.py:24
def haddLocal
Definition: tools.py:51
def tools.listFilesInCastor (   castor_dir,
  type = 'root',
  prefix = 'rfio:' 
)

Definition at line 14 of file tools.py.

Referenced by haddInCastor(), and DTDqm.runDQM().

14 
15 def listFilesInCastor(castor_dir,type = 'root',prefix = 'rfio:'):
16  if not castor_dir: raise ValueError,'Please specify valid castor dir'
17 
18  from subprocess import Popen,PIPE
19  p1 = Popen(['nsls',castor_dir],stdout=PIPE)
20  p2 = Popen(['grep',type],stdin=p1.stdout,stdout=PIPE)
21  files = [prefix + castor_dir + "/" + item[:-1] for item in p2.stdout]
22  p2.stdout.close()
23  return files
def listFilesInCastor
Definition: tools.py:14
def tools.listFilesLocal (   dir,
  type = 'root' 
)

Definition at line 24 of file tools.py.

Referenced by haddLocal().

24 
25 def listFilesLocal(dir,type = 'root'):
26  if not dir: raise ValueError,'Please specify valid dir'
27 
28  from subprocess import Popen,PIPE
29  p1 = Popen(['ls',dir],stdout=PIPE)
30  p2 = Popen(['grep',type],stdin=p1.stdout,stdout=PIPE)
31  files = [dir + "/" + item[:-1] for item in p2.stdout]
32  p2.stdout.close()
33  return files
def listFilesLocal
Definition: tools.py:24
def tools.loadCmsProcess (   pset_name)

Definition at line 93 of file tools.py.

93 
94 def loadCmsProcess(pset_name):
95  pset = imp.load_source("psetmodule",pset_name)
96  return pset.process
def loadCmsProcess
Definition: tools.py:93
def tools.loadCrabCfg (   cfg_name)

Definition at line 105 of file tools.py.

Referenced by DTTTrigProd.DTTTrigProd.initCrab(), and DTTTrigValid.DTTTrigValid.initCrab().

106 def loadCrabCfg(cfg_name):
107  config = ConfigParser.ConfigParser()
108  config.read(cfg_name)
109  return config
def loadCrabCfg
Definition: tools.py:105
def tools.loadCrabDefault (   crab_cfg,
  config 
)

Definition at line 110 of file tools.py.

Referenced by DTTTrigProd.DTTTrigProd.initCrab(), and DTTTrigValid.DTTTrigValid.initCrab().

111 def loadCrabDefault(crab_cfg,config):
112  # CRAB section
113  if not crab_cfg.has_section('CRAB'): crab_cfg.add_section('CRAB')
114  crab_cfg.set('CRAB','jobtype','cmssw')
115  crab_cfg.set('CRAB','scheduler',config.scheduler)
116  if config.useserver: crab_cfg.set('CRAB','use_server',1)
117 
118  # CMSSW section
119  if not crab_cfg.has_section('CMSSW'): crab_cfg.add_section('CMSSW')
120  crab_cfg.set('CMSSW','datasetpath',config.datasetpath)
121  crab_cfg.set('CMSSW','pset','pset.py')
122 
123  # Splitting config
124  crab_cfg.remove_option('CMSSW','total_number_of_events')
125  crab_cfg.remove_option('CMSSW','events_per_job')
126  crab_cfg.remove_option('CMSSW','number_of_jobs')
127  crab_cfg.remove_option('CMSSW','total_number_of_lumis')
128  crab_cfg.remove_option('CMSSW','lumis_per_job')
129  crab_cfg.remove_option('CMSSW','lumi_mask')
130  crab_cfg.remove_option('CMSSW','split_by_run')
131 
132  crab_cfg.set('CMSSW','runselection',config.runselection)
133  #if hasattr(config,'totalnumberevents'): crab_cfg.set('CMSSW','total_number_of_events',config.totalnumberevents)
134  #if hasattr(config,'eventsperjob'): crab_cfg.set('CMSSW','events_per_job',config.eventsperjob)
135  if hasattr(config,'splitByLumi') and config.splitByLumi:
136  crab_cfg.set('CMSSW','total_number_of_lumis',config.totalnumberlumis)
137  crab_cfg.set('CMSSW','lumis_per_job',config.lumisperjob)
138  if hasattr(config,'lumimask') and config.lumimask: crab_cfg.set('CMSSW','lumi_mask',config.lumimask)
139  else:
140  crab_cfg.set('CMSSW','split_by_run',1)
141 
142  # USER section
143  if not crab_cfg.has_section('USER'): crab_cfg.add_section('USER')
144 
145  # Stageout config
146  if hasattr(config,'stageOutCAF') and config.stageOutCAF:
147  crab_cfg.set('USER','return_data',0)
148  crab_cfg.set('USER','copy_data',1)
149  crab_cfg.set('USER','storage_element','T2_CH_CAF')
150  crab_cfg.set('USER','user_remote_dir',config.userdircaf)
151  crab_cfg.set('USER','check_user_remote_dir',0)
152  elif hasattr(config,'stageOutLocal') and config.stageOutLocal:
153  crab_cfg.set('USER','return_data',1)
154  crab_cfg.set('USER','copy_data',0)
155  crab_cfg.remove_option('USER','storage_element')
156  crab_cfg.remove_option('USER','user_remote_dir')
157  crab_cfg.remove_option('USER','check_user_remote_dir')
158 
159  if hasattr(config,'email') and config.email: crab_cfg.set('USER','eMail',config.email)
160  crab_cfg.set('USER','xml_report','crabReport.xml')
161 
162  if hasattr(config,'runOnGrid') and config.runOnGrid:
163  crab_cfg.remove_section('CAF')
def loadCrabDefault
Definition: tools.py:110
def tools.parseInput (   inputFields,
  requiredFields = () 
)

Definition at line 75 of file tools.py.

75 
76 def parseInput(inputFields,requiredFields = ()):
77 
78  class options: pass
79  for item in sys.argv:
80  option = item.split('=')[0]
81  if option in inputFields:
82  value = item.split('=')[1]
83  if value in ('true','True','yes','Yes'): value = True
84  elif value in ('false','False','no','No'): value = False
85 
86  setattr(options,option,value)
87 
88  for item in requiredFields:
89  if not hasattr(options,item):
90  raise RuntimeError,'Need to set "%s"' % item
91 
92  return options
def parseInput
Definition: tools.py:75
def tools.prependPaths (   process,
  seqname 
)

Definition at line 97 of file tools.py.

97 
98 def prependPaths(process,seqname):
99  for path in process.paths:
100  getattr(process,path)._seq = getattr(process,seqname)*getattr(process,path)._seq
def prependPaths
Definition: tools.py:97
def tools.replaceTemplate (   template,
  opts 
)

Definition at line 4 of file tools.py.

References SiPixelLorentzAngle_cfi.read.

4 
5 def replaceTemplate(template,**opts):
6  result = open(template).read()
7  for item in opts:
8  old = '@@%s@@'%item
9  new = str(opts[item])
10  print "Replacing",old,"to",new
11  result = result.replace(old,new)
12 
13  return result
def replaceTemplate
Definition: tools.py:4
def tools.setGridEnv (   cmssw_dir)

Definition at line 63 of file tools.py.

63 
64 def setGridEnv(cmssw_dir):
65  cwd = os.getcwd()
66  os.chdir(cmssw_dir)
67 
68  os.system('source /afs/cern.ch/cms/LCG/LCG-2/UI/cms_ui_env.sh')
69  os.system('cmsenv')
70  os.system('source /afs/cern.ch/cms/ccs/wm/scripts/Crab/crab.sh')
71 
72  os.chdir(cwd)
73 
74  return
def setGridEnv
Definition: tools.py:63
def tools.writeCfg (   process,
  dir,
  pset_name 
)

Definition at line 101 of file tools.py.

102 def writeCfg(process,dir,pset_name):
103  if not os.path.exists(dir): os.makedirs(dir)
104  open(dir + '/' + pset_name,'w').write(process.dumpPython())
def writeCfg
Definition: tools.py:101