| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Public Attributes | Static 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__
def | setupParallelLogging
def | generatePyOutput
def | generateOptsOutput
def | printconfig
def | writeconfig
def | run
| Instantiate and run the application.
def | runSerial
def | runParallel

## Public Attributes
| log
| printsequence
| g

## Static Public Attributes
| mainLoop None

## Private Member Functions
def | _writepickle
def | _printsequence

## Detailed Description

Definition at line 8 of file Main.py.

## Constructor & Destructor Documentation

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

Definition at line 12 of file Main.py.

12
13 def __init__(self) :
14 from Configurables import ApplicationMgr
15 appMgr = ApplicationMgr()
16 if "GAUDIAPPNAME" in os.environ:
17 appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
18 if "GAUDIAPPVERSION" in os.environ:
19 appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
20 self.log = logging.getLogger(__name__)
21 self.printsequence = False

## Member Function Documentation

def Gaudi.Main.gaudimain._printsequence | ( |  | self | ) |
| private

Definition at line 110 of file Main.py.

110
111 def _printsequence(self):
112 if not self.printsequence:
113 # No printing requested
114 return
115
116 def printAlgo( algName, appMgr, prefix = ' ') :
117 print prefix + algName
118 alg = appMgr.algorithm( algName.split( "/" )[ -1 ] )
119 prop = alg.properties()
120 if prop.has_key( "Members" ) :
121 subs = prop[ "Members" ].value()
122 for i in subs : printAlgo( i.strip( '"' ), appMgr, prefix + " " )
123 elif prop.has_key( "DetectorList" ) :
124 subs = prop[ "DetectorList" ].value()
125 for i in subs : printAlgo( algName.split( "/" )[ -1 ] + i.strip( '"' ) + "Seq", appMgr, prefix + " ")
126
127 mp = self.g.properties()
128 print "\n ****************************** Algorithm Sequence **************************** \n"
129 for i in mp["TopAlg"].value(): printAlgo( i, self.g )
130 print "\n ****************************************************************************** \n"

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

Definition at line 74 of file Main.py.

74
75 def _writepickle(self, filename) :
76 #--- Lets take the first file input file as the name of the pickle file
77 import pickle
78 output = open(filename, 'wb')
79 # Dump only the the configurables that make sense to dump (not User ones)
80 from GaudiKernel.Proxy.Configurable import getNeededConfigurables
81 to_dump = {}
82 for n in getNeededConfigurables():
83 to_dump[n] = Configuration.allConfigurables[n]
84 pickle.dump(to_dump, output, -1)
85 output.close()

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

Definition at line 61 of file Main.py.

61
62 def generateOptsOutput(self, all = False):
63 from pprint import pformat
64 conf_dict = Configuration.configurationDict(all)
65 out = []
66 names = conf_dict.keys()
67 names.sort()
68 for n in names:
69 props = conf_dict[n].keys()
70 props.sort()
71 for p in props:
72 out.append('%s.%s = %s;' % (n,p, repr(conf_dict[n][p])))
73 return "\n".join(out)

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

Definition at line 56 of file Main.py.

56
57 def generatePyOutput(self, all = False):
58 from pprint import pformat
59 conf_dict = Configuration.configurationDict(all)
60 return pformat(conf_dict)

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

Definition at line 86 of file Main.py.

86
87 def printconfig(self, old_format = False, all = False) :
88 msg = 'Dumping all configurables and properties'
89 if not all:
90 msg += ' (different from default)'
91 log.info(msg)
92 conf_dict = Configuration.configurationDict(all)
93 if old_format:
94 print self.generateOptsOutput(all)
95 else:
96 print self.generatePyOutput(all)

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

Instantiate and run the application.

Depending on the number of CPUs (ncpus) specified, it start

Definition at line 133 of file Main.py.

133
134 def run(self, ncpus = None):
135 if not ncpus:
136 # Standard sequential mode
137 result = self.runSerial()
138 else:
139 # Otherwise, run with the specified number of cpus
140 result = self.runParallel(ncpus)
141 return result
142

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

Definition at line 177 of file Main.py.

177
178 def runParallel(self, ncpus) :
179 if self.mainLoop:
180 self.log.fatal("Cannot use custom main loop in multi-process mode, check your options")
181 return 1
182 self.setupParallelLogging( )
183 from Gaudi.Configuration import Configurable
184 import GaudiMP.GMPBase as gpp
185 c = Configurable.allConfigurables
186 self.log.info('-'*80)
187 self.log.info('%s: Parallel Mode : %i '%(__name__, ncpus))
188 from commands import getstatusoutput as gso
189 metadataCommands = [ 'uname -a',
190 'echo $CMTCONFIG',
191 'echo $GAUDIAPPNAME',
192 'echo $GAUDIAPPVERSION']
193 for comm in metadataCommands :
194 s, o = gso( comm )
195 if s :
196 o = "Undetermined"
197 string = '%s: %30s : %s '%(__name__, comm, o)
198 self.log.info( string )
199 try :
200 events = str(c['ApplicationMgr'].EvtMax)
201 except :
202 events = "Undetermined"
203 self.log.info('%s: Events Specified : %s '%(__name__,events))
204 self.log.info('-'*80)
205 # Parall = gpp.Coordinator(ncpus, shared, c, self.log)
206 Parall = gpp.Coord( ncpus, c, self.log )
207 sysStart = time()
208 sc = Parall.Go()
209 self.log.info('MAIN.PY : received %s from Coordinator'%(sc))
210 if sc.isFailure() :
211 return 1
212 sysTime = time()-sysStart
213 self.log.name = 'Gaudi/Main.py Logger'
214 self.log.info('-'*80)
215 self.log.info('%s: parallel system finished, time taken: %5.4fs', __name__, sysTime)
216 self.log.info('-'*80)
217 return 0

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

Definition at line 143 of file Main.py.

143
144 def runSerial(self) :
145 #--- Instantiate the ApplicationMgr------------------------------
146 import GaudiPython
147 self.log.debug('-'*80)
148 self.log.debug('%s: running in serial mode', __name__)
149 self.log.debug('-'*80)
150 sysStart = time()
151 self.g = GaudiPython.AppMgr()
152 self._printsequence()
153 runner = self.mainLoop or (lambda app, nevt: app.run(nevt))
154 try:
155 statuscode = runner(self.g, self.g.EvtMax)
156 except SystemError:
157 # It may not be 100% correct, but usually it means a segfault in C++
158 self.g.ReturnCode = 128 + 11
159 statuscode = False
160 except:
161 # for other exceptions, just set a generic error code
162 self.g.ReturnCode = 1
163 statuscode = False
164 if hasattr(statuscode, "isSuccess"):
165 success = statuscode.isSuccess()
166 else:
167 success = statuscode
168 success = self.g.exit().isSuccess() and success
169 if not success and self.g.ReturnCode == 0:
170 # ensure that the return code is correctly set
171 self.g.ReturnCode = 1
172 sysTime = time()-sysStart
173 self.log.debug('-'*80)
174 self.log.debug('%s: serial system finished, time taken: %5.4fs', __name__, sysTime)
175 self.log.debug('-'*80)
176 return self.g.ReturnCode

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

Definition at line 22 of file Main.py.

22
23 def setupParallelLogging( self ) :
24 # ---------------------------------------------------
25 # set up Logging
26 # ----------------
27 # from multiprocessing import enableLogging, getLogger
28 import multiprocessing
29 # preliminaries for handlers/output files, etc.
30 from time import ctime
31 datetime = ctime()
32 datetime = datetime.replace(' ', '_')
33 outfile = open( 'gaudirun-%s.log'%(datetime), 'w' )
34 # two handlers, one for a log file, one for terminal
35 streamhandler = logging.StreamHandler(strm=outfile)
36 console = logging.StreamHandler()
37 # create formatter : the params in parentheses are variable names available via logging
38 formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s" )
39 # add formatter to Handler
40 streamhandler.setFormatter(formatter)
41 console.setFormatter(formatter)
42 # now, configure the logger
43 # enableLogging( level=0 )
44 # self.log = getLogger()
45 self.log = multiprocessing.log_to_stderr()
46 self.log.setLevel( logging.INFO )
47 self.log.name = 'Gaudi/Main.py Logger'
48 self.log.handlers = []
49 # add handlers to logger : one for output to a file, one for console output
50 self.log.addHandler(streamhandler)
51 self.log.addHandler(console)
52 self.log.removeHandler(console)
53 # set level!!
54 self.log.setLevel = logging.INFO
55 # ---------------------------------------------------

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

Definition at line 97 of file Main.py.

97
98 def writeconfig(self, filename, all = False):
99 write = { ".pkl" : lambda filename, all: self._writepickle(filename),
100 ".py" : lambda filename, all: open(filename,"w").write(self.generatePyOutput(all) + "\n"),
101 ".opts": lambda filename, all: open(filename,"w").write(self.generateOptsOutput(all) + "\n"),
102 }
103 from os.path import splitext
104 ext = splitext(filename)[1]
105 if ext in write:
106 write[ext](filename, all)
107 else:
108 log.error("Unknown file type '%s'. Must be any of %r.", ext, write.keys())
109 sys.exit(1)

## Member Data Documentation

Gaudi.Main.gaudimain.g

Definition at line 150 of file Main.py.

Gaudi.Main.gaudimain.log

Definition at line 19 of file Main.py.

Gaudi.Main.gaudimain.mainLoop None
| static

Definition at line 10 of file Main.py.

Gaudi.Main.gaudimain.printsequence

Definition at line 20 of file Main.py.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/Gaudi/python/Gaudi/Main.py