CMS 3D CMS Logo

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

TAKEN FROM http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/ElectroWeakAnalysis/Utilities/src/PdfWeightProducer.cc?&view=markup. More...

Namespaces

 mt2w_bisect
 

Classes

struct  AlphaT
 
struct  Apc
 
class  BTagSF
 
class  CMGMuonCleanerBySegmentsAlgo
 
class  Davismt2
 
class  EGammaMvaEleEstimatorFWLite
 
class  FSRWeightAlgo
 
class  Hemisphere
 
class  IsolationComputer
 
class  Megajet
 
class  MuScleFitCorrector
 
class  PdfWeightProducerTool
 
class  ReclusterJets
 
class  RochCor
 
class  RochCor2012
 
class  TriggerBitChecker
 

Functions

def callBack
 
def chunks
 
def createOutputDir
 
def getHeppyOption
 
def main
 
def runLoop
 
def runLoopAsync
 
def split
 

Variables

dictionary _heppyGlobalOptions = {}
 
string action = 'store_true'
 
 default = None)
 
string dest = "nevents"
 
string help = "number of events to process"
 
 loop = None
 
list oldv = sys.argv[:]
 
tuple parser = OptionParser()
 
string type = "int"
 

Detailed Description

TAKEN FROM http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/ElectroWeakAnalysis/Utilities/src/PdfWeightProducer.cc?&view=markup.

The Megajet class implements the algorithm to combine jets in hemispheres as defined in CMS SUSY searches

MuScleFitCorrector class Author M. De Mattia - 18/11/2008 Author S. Casasso - 25/10/2012 Author E. Migliore - 25/10/2012 This is used to have a common set of functions for the specialized templates to use. The constructor receives the name identifying the parameters for the correction function. It reads the parameters from a txt file in data/.

Function Documentation

def heppy.callBack (   result)

Definition at line 28 of file heppy.py.

28 
29 def callBack( result ):
30  pass
31  print 'production done:', str(result)
def callBack
Definition: heppy.py:28
def heppy.chunks (   l,
  n 
)

Definition at line 93 of file heppy.py.

Referenced by split().

93 
94 def chunks(l, n):
95  return [l[i:i+n] for i in range(0, len(l), n)]
def chunks
Definition: heppy.py:93
def heppy.createOutputDir (   dir,
  components,
  force 
)
Creates the output dir, dealing with the case where dir exists.

Definition at line 66 of file heppy.py.

References join().

Referenced by main().

66 
67 def createOutputDir(dir, components, force):
68  '''Creates the output dir, dealing with the case where dir exists.'''
69  answer = None
70  try:
71  os.mkdir(dir)
72  return True
73  except OSError:
74  print 'directory %s already exists' % dir
75  print 'contents: '
76  dirlist = [path for path in os.listdir(dir) if os.path.isdir( '/'.join([dir, path]) )]
77  pprint( dirlist )
78  print 'component list: '
79  print [comp.name for comp in components]
80  if force is True:
81  print 'force mode, continue.'
82  return True
83  else:
84  while answer not in ['Y','y','yes','N','n','no']:
85  answer = raw_input('Continue? [y/n]')
86  if answer.lower().startswith('n'):
87  return False
88  elif answer.lower().startswith('y'):
89  return True
90  else:
91  raise ValueError( ' '.join(['answer can not have this value!',
92  answer]) )
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def createOutputDir
Definition: heppy.py:66
def heppy.getHeppyOption (   name,
  default = None 
)

Definition at line 127 of file heppy.py.

128 def getHeppyOption(name,default=None):
129  global _heppyGlobalOptions
130  return _heppyGlobalOptions[name] if name in _heppyGlobalOptions else default
def getHeppyOption
Definition: heppy.py:127
def heppy.main (   options,
  args 
)

Definition at line 131 of file heppy.py.

References createOutputDir(), min(), runLoop(), and split().

132 def main( options, args ):
133 
134  if len(args) != 2:
135  parser.print_help()
136  print 'ERROR: please provide the processing name and the component list'
137  sys.exit(1)
138 
139  outDir = args[0]
140  if os.path.exists(outDir) and not os.path.isdir( outDir ):
141  parser.print_help()
142  print 'ERROR: when it exists, first argument must be a directory.'
143  sys.exit(2)
144  cfgFileName = args[1]
145  if not os.path.isfile( cfgFileName ):
146  parser.print_help()
147  print 'ERROR: second argument must be an existing file (your input cfg).'
148  sys.exit(3)
149 
150  if options.verbose:
151  import logging
152  logging.basicConfig(level=logging.INFO)
153 
154  # Propagate global options to _heppyGlobalOptions within this module
155  # I have to import it explicitly, 'global' does not work since the
156  # module is not set when executing the main
157  from PhysicsTools.HeppyCore.framework.heppy import _heppyGlobalOptions
158  for opt in options.extraOptions:
159  if "=" in opt:
160  (key,val) = opt.split("=",1)
161  _heppyGlobalOptions[key] = val
162  else:
163  _heppyGlobalOptions[opt] = True
164 
165  file = open( cfgFileName, 'r' )
166  cfg = imp.load_source( 'PhysicsTools.HeppyCore.__cfg_to_run__', cfgFileName, file)
167 
168  selComps = [comp for comp in cfg.config.components if len(comp.files)>0]
169  selComps = split(selComps)
170  # for comp in selComps:
171  # print comp
172  if len(selComps)>10:
173  print "WARNING: too many threads {tnum}, will just use a maximum of 10.".format(tnum=len(selComps))
174  if not createOutputDir(outDir, selComps, options.force):
175  print 'exiting'
176  sys.exit(0)
177  if len(selComps)>1:
178  shutil.copy( cfgFileName, outDir )
179  pool = Pool(processes=min(len(selComps),10))
180  ## workaround for a scoping problem in ipython+multiprocessing
181  import PhysicsTools.HeppyCore.framework.heppy as ML
182  for comp in selComps:
183  print 'submitting', comp.name
184  pool.apply_async( ML.runLoopAsync, [comp, outDir, 'PhysicsTools.HeppyCore.__cfg_to_run__', options],
185  callback=ML.callBack)
186  pool.close()
187  pool.join()
188  else:
189  # when running only one loop, do not use multiprocessor module.
190  # then, the exceptions are visible -> use only one sample for testing
191  global loop
192  loop = runLoop( comp, outDir, cfg.config, options )
193 
194 
def main
Definition: heppy.py:131
def runLoop
Definition: heppy.py:44
def split
Definition: heppy.py:96
T min(T a, T b)
Definition: MathUtil.h:58
def createOutputDir
Definition: heppy.py:66
def heppy.runLoop (   comp,
  outDir,
  config,
  options 
)

Definition at line 44 of file heppy.py.

References join().

Referenced by main(), and runLoopAsync().

44 
45 def runLoop( comp, outDir, config, options):
46  fullName = '/'.join( [outDir, comp.name ] )
47  # import pdb; pdb.set_trace()
48  config.components = [comp]
49  loop = Looper( fullName,
50  config,
51  options.nevents, 0,
52  nPrint = options.nprint,
53  timeReport = options.timeReport,
54  quiet = options.quiet)
55  # print loop
56  if options.iEvent is None:
57  loop.loop()
58  loop.write()
59  # print loop
60  else:
61  # loop.InitOutput()
62  iEvent = int(options.iEvent)
63  loop.process( iEvent )
64  return loop
65 
def runLoop
Definition: heppy.py:44
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def heppy.runLoopAsync (   comp,
  outDir,
  configName,
  options 
)

Definition at line 32 of file heppy.py.

References runLoop().

32 
33 def runLoopAsync(comp, outDir, configName, options):
34  try:
35  loop = runLoop( comp, outDir, copy.copy(sys.modules[configName].config), options)
36  return loop.name
37  except Exception:
38  import traceback
39  print "ERROR processing component %s" % comp.name
40  print comp
41  print "STACK TRACE: "
42  print traceback.format_exc()
43  raise
def runLoop
Definition: heppy.py:44
def runLoopAsync
Definition: heppy.py:32
def heppy.split (   comps)

Definition at line 96 of file heppy.py.

References chunks().

Referenced by main().

96 
97 def split(comps):
98  # import pdb; pdb.set_trace()
99  splitComps = []
100  for comp in comps:
101  if hasattr( comp, 'fineSplitFactor') and comp.fineSplitFactor>1:
102  subchunks = range(comp.fineSplitFactor)
103  for ichunk, chunk in enumerate([(f,i) for f in comp.files for i in subchunks]):
104  newComp = copy.deepcopy(comp)
105  newComp.files = [chunk[0]]
106  newComp.fineSplit = ( chunk[1], comp.fineSplitFactor )
107  newComp.name = '{name}_Chunk{index}'.format(name=newComp.name,
108  index=ichunk)
109  splitComps.append( newComp )
110  elif hasattr( comp, 'splitFactor') and comp.splitFactor>1:
111  chunkSize = len(comp.files) / comp.splitFactor
112  if len(comp.files) % comp.splitFactor:
113  chunkSize += 1
114  # print 'chunk size',chunkSize, len(comp.files), comp.splitFactor
115  for ichunk, chunk in enumerate( chunks( comp.files, chunkSize)):
116  newComp = copy.deepcopy(comp)
117  newComp.files = chunk
118  newComp.name = '{name}_Chunk{index}'.format(name=newComp.name,
119  index=ichunk)
120  splitComps.append( newComp )
121  else:
122  splitComps.append( comp )
123  return splitComps
124 
def chunks
Definition: heppy.py:93
def split
Definition: heppy.py:96

Variable Documentation

dictionary heppy._heppyGlobalOptions = {}

Definition at line 125 of file heppy.py.

string heppy.action = 'store_true'

Definition at line 220 of file heppy.py.

list heppy.default = None)

Definition at line 209 of file heppy.py.

string heppy.dest = "nevents"

Definition at line 206 of file heppy.py.

string heppy.help = "number of events to process"

Definition at line 208 of file heppy.py.

heppy.loop = None

Definition at line 26 of file heppy.py.

list heppy.oldv = sys.argv[:]

Definition at line 16 of file heppy.py.

tuple heppy.parser = OptionParser()

Definition at line 198 of file heppy.py.

string heppy.type = "int"

Definition at line 207 of file heppy.py.