| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Public Attributes | Private Member Functions | List of all members
Gaudi.Main.gaudimain Class Reference
Inheritance diagram for Gaudi.Main.gaudimain:
[legend]
Collaboration diagram for Gaudi.Main.gaudimain:
[legend]

## Public Member Functions
def | __init__ (self)
def | setupParallelLogging (self)
def | generatePyOutput (self, all=False)
def | generateOptsOutput (self, all=False)
def | printconfig (self, old_format=False, all=False)
def | writeconfig (self, filename, all=False)
def | run (self, attach_debugger, ncpus=None)
def | hookDebugger (self, debugger='gdb')
def | runSerial (self, attach_debugger)
def | runParallel (self, ncpus)

## Public Attributes
| log
| printsequence
| application

## Private Member Functions
def | _writepickle (self, filename)

## Detailed Description

Definition at line 178 of file Main.py.

## Constructor & Destructor Documentation

## ◆ __init__()

def Gaudi.Main.gaudimain.__init__ | ( |  | self | ) |

Definition at line 179 of file Main.py.

179 def __init__(self):
180 from Configurables import ApplicationMgr
181 appMgr = ApplicationMgr()
182 if "GAUDIAPPNAME" in os.environ:
183 appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
184 if "GAUDIAPPVERSION" in os.environ:
185 appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
186 self.log = logging.getLogger(__name__)
187 self.printsequence = False
188 self.application = 'Gaudi::Application'
189
ApplicationMgr
The Application Manager class.
Definition: ApplicationMgr.h:45

## Member Function Documentation

## ◆ _writepickle()

def Gaudi.Main.gaudimain._writepickle | ( |  | self,
|  |  | filename
| ) |  |
| private

Definition at line 243 of file Main.py.

243 def _writepickle(self, filename):
244 # --- Lets take the first file input file as the name of the pickle file
245 import pickle
246 output = open(filename, 'wb')
247 # Dump only the the configurables that make sense to dump (not User ones)
248 from GaudiKernel.Proxy.Configurable import getNeededConfigurables
249 to_dump = {}
250 for n in getNeededConfigurables():
251 to_dump[n] = Configuration.allConfigurables[n]
252 pickle.dump(to_dump, output, -1)
253 output.close()
254
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:21

## ◆ generateOptsOutput()

def Gaudi.Main.gaudimain.generateOptsOutput | ( |  | self,
|  |  | all = `False`
| ) |  |

Definition at line 230 of file Main.py.

230 def generateOptsOutput(self, all=False):
231 from pprint import pformat
232 conf_dict = Configuration.configurationDict(all)
233 out = []
234 names = conf_dict.keys()
235 names.sort()
236 for n in names:
237 props = conf_dict[n].keys()
238 props.sort()
239 for p in props:
240 out.append('%s.%s = %s;' % (n, p, toOpt(conf_dict[n][p])))
241 return "\n".join(out)
242
Gaudi.Main.toOpt
def toOpt(value)
Definition: Main.py:154

## ◆ generatePyOutput()

def Gaudi.Main.gaudimain.generatePyOutput | ( |  | self,
|  |  | all = `False`
| ) |  |

Definition at line 225 of file Main.py.

225 def generatePyOutput(self, all=False):
226 from pprint import pformat
227 conf_dict = Configuration.configurationDict(all)
228 return pformat(conf_dict)
229

## ◆ hookDebugger()

def Gaudi.Main.gaudimain.hookDebugger | ( |  | self,
|  |  | debugger = `'gdb'`
| ) |  |

Definition at line 291 of file Main.py.

291 def hookDebugger(self, debugger='gdb'):
292 import os
293 self.log.info('attaching debugger to PID ' + str(os.getpid()))
294 pid = os.spawnvp(os.P_NOWAIT, debugger,
295 [debugger, '-q', 'python',
296 str(os.getpid())])
297
298 # give debugger some time to attach to the python process
299 import time
300 time.sleep(5)
301
302 # verify the process' existence (will raise OSError if failed)
303 os.waitpid(pid, os.WNOHANG)
304 os.kill(pid, 0)
305 return
306

## ◆ printconfig()

def Gaudi.Main.gaudimain.printconfig | ( |  | self,
|  |  | old_format = `False`,
|  |  | all = `False`
| ) |  |

Definition at line 255 of file Main.py.

255 def printconfig(self, old_format=False, all=False):
256 msg = 'Dumping all configurables and properties'
257 if not all:
258 msg += ' (different from default)'
259 log.info(msg)
260 conf_dict = Configuration.configurationDict(all)
261 if old_format:
262 print self.generateOptsOutput(all)
263 else:
264 print self.generatePyOutput(all)
265

## ◆ run()

def Gaudi.Main.gaudimain.run | ( |  | self,
|  |  | attach_debugger,
|  |  | ncpus = `None`
| ) |  |

Definition at line 282 of file Main.py.

282 def run(self, attach_debugger, ncpus=None):
283 if not ncpus:
284 # Standard sequential mode
285 result = self.runSerial(attach_debugger)
286 else:
287 # Otherwise, run with the specified number of cpus
288 result = self.runParallel(ncpus)
289 return result
290

## ◆ runParallel()

def Gaudi.Main.gaudimain.runParallel | ( |  | self,
|  |  | ncpus
| ) |  |

Definition at line 369 of file Main.py.

369 def runParallel(self, ncpus):
370 self.setupParallelLogging()
371 from Gaudi.Configuration import Configurable
372 import GaudiMP.GMPBase as gpp
373 c = Configurable.allConfigurables
374 self.log.info('-' * 80)
375 self.log.info('%s: Parallel Mode : %i ', __name__, ncpus)
376 for name, value in [
377 ('platrofm', ' '.join(os.uname())),
378 ('config', os.environ.get('BINARY_TAG')
379 or os.environ.get('CMTCONFIG')),
380 ('app. name', os.environ.get('GAUDIAPPNAME')),
381 ('app. version', os.environ.get('GAUDIAPPVERSION')),
382 ]:
383 self.log.info('%s: %30s : %s ', __name__, name, value
384 or 'Undefined')
385 try:
386 events = str(c['ApplicationMgr'].EvtMax)
387 except:
388 events = "Undetermined"
389 self.log.info('%s: Events Specified : %s ', __name__, events)
390 self.log.info('-' * 80)
391 # Parall = gpp.Coordinator(ncpus, shared, c, self.log)
392 Parall = gpp.Coord(ncpus, c, self.log)
393 sysStart = time()
394 sc = Parall.Go()
395 self.log.info('MAIN.PY : received %s from Coordinator' % (sc))
396 if sc.isFailure():
397 return 1
398 sysTime = time() - sysStart
399 self.log.name = 'Gaudi/Main.py Logger'
400 self.log.info('-' * 80)
401 self.log.info('%s: parallel system finished, time taken: %5.4fs',
402 __name__, sysTime)
403 self.log.info('-' * 80)
404 return 0
plotSpeedupsPyRoot.time
def time
Definition: plotSpeedupsPyRoot.py:152
Gaudi.Configuration
Definition: Configuration.py:1
GaudiMP.GMPBase
Definition: GMPBase.py:1

## ◆ runSerial()

def Gaudi.Main.gaudimain.runSerial | ( |  | self,
|  |  | attach_debugger
| ) |  |

Definition at line 307 of file Main.py.

307 def runSerial(self, attach_debugger):
308 try:
309 from GaudiKernel.Proxy.Configurable import expandvars
310 except ImportError:
311 # pass-through implementation if expandvars is not defined (AthenaCommon)
312 def expandvars(data):
313 return data
314
315 from GaudiKernel.Proxy.Configurable import Configurable, getNeededConfigurables
316
317 self.log.debug('runSerial: apply options')
318 conf_dict = {'ApplicationMgr.JobOptionsType': '"NONE"'}
319
320 # FIXME: this is to make sure special properties are correctly
321 # expanded before we fill conf_dict
322 for c in Configurable.allConfigurables.values():
323 if hasattr(c, 'getValuedProperties'):
324 c.getValuedProperties()
325
326 for n in getNeededConfigurables():
327 c = Configurable.allConfigurables[n]
328 for p, v in c.getValuedProperties().items():
329 v = expandvars(v)
330 # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference
331 if hasattr(Configurable, "PropertyReference") and type(
332 v) == Configurable.PropertyReference:
333 # this is done in "getFullName", but the exception is ignored,
334 # so we do it again to get it
335 v = v.__resolve__()
336 if type(v) == str:
337 # properly escape quotes in the string
338 v = '"%s"' % v.replace('"', '\\"')
339 elif type(v) == long:
340 v = '%d' % v # prevent pending 'L'
341 conf_dict['{}.{}'.format(n, p)] = str(v)
342
343 if self.printsequence:
344 conf_dict['ApplicationMgr.PrintAlgsSequence'] = 'true'
345
346 if hasattr(Configurable, "_configurationLocked"):
347 Configurable._configurationLocked = True
348
349 if attach_debugger:
350 self.hookDebugger()
351
352 self.log.debug('-' * 80)
353 self.log.debug('%s: running in serial mode', __name__)
354 self.log.debug('-' * 80)
355 sysStart = time()
356
357 import Gaudi
358 app = Gaudi.Application.create(self.application, conf_dict)
359 retcode = app.run()
360
361 sysTime = time() - sysStart
362 self.log.debug('-' * 80)
363 self.log.debug('%s: serial system finished, time taken: %5.4fs',
364 __name__, sysTime)
365 self.log.debug('-' * 80)
366
367 return retcode
368
plotSpeedupsPyRoot.time
def time
Definition: plotSpeedupsPyRoot.py:152
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:21
gaudirun.type
type
Definition: gaudirun.py:142
Gaudi.Application.create
def create(cls, appType, opts)
Definition: __init__.py:83
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:35

## ◆ setupParallelLogging()

def Gaudi.Main.gaudimain.setupParallelLogging | ( |  | self | ) |

Definition at line 190 of file Main.py.

190 def setupParallelLogging(self):
191 # ---------------------------------------------------
192 # set up Logging
193 # ----------------
194 # from multiprocessing import enableLogging, getLogger
195 import multiprocessing
196 # preliminaries for handlers/output files, etc.
197 from time import ctime
198 datetime = ctime()
199 datetime = datetime.replace(' ', '_')
200 outfile = open('gaudirun-%s.log' % (datetime), 'w')
201 # two handlers, one for a log file, one for terminal
202 streamhandler = logging.StreamHandler(stream=outfile)
203 console = logging.StreamHandler()
204 # create formatter : the params in parentheses are variable names available via logging
205 formatter = logging.Formatter(
206 "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
207 # add formatter to Handler
208 streamhandler.setFormatter(formatter)
209 console.setFormatter(formatter)
210 # now, configure the logger
211 # enableLogging( level=0 )
212 # self.log = getLogger()
213 self.log = multiprocessing.log_to_stderr()
214 self.log.setLevel(logging.INFO)
215 self.log.name = 'Gaudi/Main.py Logger'
216 self.log.handlers = []
217 # add handlers to logger : one for output to a file, one for console output
218 self.log.addHandler(streamhandler)
219 self.log.addHandler(console)
220 self.log.removeHandler(console)
221 # set level!!
222 self.log.setLevel = logging.INFO
223 # ---------------------------------------------------
224

## ◆ writeconfig()

def Gaudi.Main.gaudimain.writeconfig | ( |  | self,
|  |  | filename,
|  |  | all = `False`
| ) |  |

Definition at line 266 of file Main.py.

266 def writeconfig(self, filename, all=False):
267 write = {".pkl": lambda filename, all: self._writepickle(filename),
268 ".py": lambda filename, all: open(filename, "w").write(self.generatePyOutput(all) + "\n"),
269 ".opts": lambda filename, all: open(filename, "w").write(self.generateOptsOutput(all) + "\n"),
270 }
271 from os.path import splitext
272 ext = splitext(filename)[1]
273 if ext in write:
274 write[ext](filename, all)
275 else:
276 log.error("Unknown file type '%s'. Must be any of %r.", ext,
277 write.keys())
278 sys.exit(1)
279

## Member Data Documentation

## ◆ application

Gaudi.Main.gaudimain.application

Definition at line 188 of file Main.py.

## ◆ log

Gaudi.Main.gaudimain.log

Definition at line 186 of file Main.py.

## ◆ printsequence

Gaudi.Main.gaudimain.printsequence

Definition at line 187 of file Main.py.

The documentation for this class was generated from the following file:

- Gaudi/python/Gaudi/Main.py