All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Gaudi.Main.gaudimain Class Reference
Inheritance diagram for Gaudi.Main.gaudimain:
Collaboration diagram for Gaudi.Main.gaudimain:

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
 
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
 
def _writepickle
 
def _printsequence
 

Detailed Description

Definition at line 30 of file Main.py.

Constructor & Destructor Documentation

def Gaudi.Main.gaudimain.__init__ (   self)

Definition at line 34 of file Main.py.

34 
35  def __init__(self) :
36  from Configurables import ApplicationMgr
37  appMgr = ApplicationMgr()
38  if "GAUDIAPPNAME" in os.environ:
39  appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
40  if "GAUDIAPPVERSION" in os.environ:
41  appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
42  self.log = logging.getLogger(__name__)
43  self.printsequence = False
def Gaudi.Main.gaudimain.__init__ (   self)

Definition at line 34 of file Main.py.

34 
35  def __init__(self) :
36  from Configurables import ApplicationMgr
37  appMgr = ApplicationMgr()
38  if "GAUDIAPPNAME" in os.environ:
39  appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
40  if "GAUDIAPPVERSION" in os.environ:
41  appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
42  self.log = logging.getLogger(__name__)
43  self.printsequence = False

Member Function Documentation

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

Definition at line 132 of file Main.py.

133  def _printsequence(self):
134  if not self.printsequence:
135  # No printing requested
136  return
137 
138  def printAlgo( algName, appMgr, prefix = ' ') :
139  print prefix + algName
140  alg = appMgr.algorithm( algName.split( "/" )[ -1 ] )
141  prop = alg.properties()
142  if prop.has_key( "Members" ) :
143  subs = prop[ "Members" ].value()
144  for i in subs : printAlgo( i.strip( '"' ), appMgr, prefix + " " )
145  elif prop.has_key( "DetectorList" ) :
146  subs = prop[ "DetectorList" ].value()
147  for i in subs : printAlgo( algName.split( "/" )[ -1 ] + i.strip( '"' ) + "Seq", appMgr, prefix + " ")
148 
149  mp = self.g.properties()
150  print "\n ****************************** Algorithm Sequence **************************** \n"
151  for i in mp["TopAlg"].value(): printAlgo( i, self.g )
152  print "\n ****************************************************************************** \n"
def Gaudi.Main.gaudimain._printsequence (   self)
private

Definition at line 132 of file Main.py.

133  def _printsequence(self):
134  if not self.printsequence:
135  # No printing requested
136  return
137 
138  def printAlgo( algName, appMgr, prefix = ' ') :
139  print prefix + algName
140  alg = appMgr.algorithm( algName.split( "/" )[ -1 ] )
141  prop = alg.properties()
142  if prop.has_key( "Members" ) :
143  subs = prop[ "Members" ].value()
144  for i in subs : printAlgo( i.strip( '"' ), appMgr, prefix + " " )
145  elif prop.has_key( "DetectorList" ) :
146  subs = prop[ "DetectorList" ].value()
147  for i in subs : printAlgo( algName.split( "/" )[ -1 ] + i.strip( '"' ) + "Seq", appMgr, prefix + " ")
148 
149  mp = self.g.properties()
150  print "\n ****************************** Algorithm Sequence **************************** \n"
151  for i in mp["TopAlg"].value(): printAlgo( i, self.g )
152  print "\n ****************************************************************************** \n"
def Gaudi.Main.gaudimain._writepickle (   self,
  filename 
)
private

Definition at line 96 of file Main.py.

96 
97  def _writepickle(self, filename) :
98  #--- Lets take the first file input file as the name of the pickle file
99  import pickle
100  output = open(filename, 'wb')
101  # Dump only the the configurables that make sense to dump (not User ones)
102  from GaudiKernel.Proxy.Configurable import getNeededConfigurables
103  to_dump = {}
104  for n in getNeededConfigurables():
105  to_dump[n] = Configuration.allConfigurables[n]
106  pickle.dump(to_dump, output, -1)
107  output.close()
def Gaudi.Main.gaudimain._writepickle (   self,
  filename 
)
private

Definition at line 96 of file Main.py.

96 
97  def _writepickle(self, filename) :
98  #--- Lets take the first file input file as the name of the pickle file
99  import pickle
100  output = open(filename, 'wb')
101  # Dump only the the configurables that make sense to dump (not User ones)
102  from GaudiKernel.Proxy.Configurable import getNeededConfigurables
103  to_dump = {}
104  for n in getNeededConfigurables():
105  to_dump[n] = Configuration.allConfigurables[n]
106  pickle.dump(to_dump, output, -1)
107  output.close()
def Gaudi.Main.gaudimain.generateOptsOutput (   self,
  all = False 
)

Definition at line 83 of file Main.py.

83 
84  def generateOptsOutput(self, all = False):
85  from pprint import pformat
86  conf_dict = Configuration.configurationDict(all)
87  out = []
88  names = conf_dict.keys()
89  names.sort()
90  for n in names:
91  props = conf_dict[n].keys()
92  props.sort()
93  for p in props:
94  out.append('%s.%s = %s;' % (n,p, toOpt(conf_dict[n][p])))
95  return "\n".join(out)
def Gaudi.Main.gaudimain.generateOptsOutput (   self,
  all = False 
)

Definition at line 83 of file Main.py.

83 
84  def generateOptsOutput(self, all = False):
85  from pprint import pformat
86  conf_dict = Configuration.configurationDict(all)
87  out = []
88  names = conf_dict.keys()
89  names.sort()
90  for n in names:
91  props = conf_dict[n].keys()
92  props.sort()
93  for p in props:
94  out.append('%s.%s = %s;' % (n,p, toOpt(conf_dict[n][p])))
95  return "\n".join(out)
def Gaudi.Main.gaudimain.generatePyOutput (   self,
  all = False 
)

Definition at line 78 of file Main.py.

78 
79  def generatePyOutput(self, all = False):
80  from pprint import pformat
81  conf_dict = Configuration.configurationDict(all)
82  return pformat(conf_dict)
def Gaudi.Main.gaudimain.generatePyOutput (   self,
  all = False 
)

Definition at line 78 of file Main.py.

78 
79  def generatePyOutput(self, all = False):
80  from pprint import pformat
81  conf_dict = Configuration.configurationDict(all)
82  return pformat(conf_dict)
def Gaudi.Main.gaudimain.printconfig (   self,
  old_format = False,
  all = False 
)

Definition at line 108 of file Main.py.

109  def printconfig(self, old_format = False, all = False) :
110  msg = 'Dumping all configurables and properties'
111  if not all:
112  msg += ' (different from default)'
113  log.info(msg)
114  conf_dict = Configuration.configurationDict(all)
115  if old_format:
116  print self.generateOptsOutput(all)
117  else:
118  print self.generatePyOutput(all)
def Gaudi.Main.gaudimain.printconfig (   self,
  old_format = False,
  all = False 
)

Definition at line 108 of file Main.py.

109  def printconfig(self, old_format = False, all = False) :
110  msg = 'Dumping all configurables and properties'
111  if not all:
112  msg += ' (different from default)'
113  log.info(msg)
114  conf_dict = Configuration.configurationDict(all)
115  if old_format:
116  print self.generateOptsOutput(all)
117  else:
118  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 155 of file Main.py.

156  def run(self, ncpus = None):
157  if not ncpus:
158  # Standard sequential mode
159  result = self.runSerial()
160  else:
161  # Otherwise, run with the specified number of cpus
162  result = self.runParallel(ncpus)
163  return result
164 
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 155 of file Main.py.

156  def run(self, ncpus = None):
157  if not ncpus:
158  # Standard sequential mode
159  result = self.runSerial()
160  else:
161  # Otherwise, run with the specified number of cpus
162  result = self.runParallel(ncpus)
163  return result
164 
def Gaudi.Main.gaudimain.runParallel (   self,
  ncpus 
)

Definition at line 199 of file Main.py.

200  def runParallel(self, ncpus) :
201  if self.mainLoop:
202  self.log.fatal("Cannot use custom main loop in multi-process mode, check your options")
203  return 1
204  self.setupParallelLogging( )
205  from Gaudi.Configuration import Configurable
206  import GaudiMP.GMPBase as gpp
207  c = Configurable.allConfigurables
208  self.log.info('-'*80)
209  self.log.info('%s: Parallel Mode : %i '%(__name__, ncpus))
210  from commands import getstatusoutput as gso
211  metadataCommands = [ 'uname -a',
212  'echo $CMTCONFIG',
213  'echo $GAUDIAPPNAME',
214  'echo $GAUDIAPPVERSION']
215  for comm in metadataCommands :
216  s, o = gso( comm )
217  if s :
218  o = "Undetermined"
219  string = '%s: %30s : %s '%(__name__, comm, o)
220  self.log.info( string )
221  try :
222  events = str(c['ApplicationMgr'].EvtMax)
223  except :
224  events = "Undetermined"
225  self.log.info('%s: Events Specified : %s '%(__name__,events))
226  self.log.info('-'*80)
227  # Parall = gpp.Coordinator(ncpus, shared, c, self.log)
228  Parall = gpp.Coord( ncpus, c, self.log )
229  sysStart = time()
230  sc = Parall.Go()
231  self.log.info('MAIN.PY : received %s from Coordinator'%(sc))
232  if sc.isFailure() :
233  return 1
234  sysTime = time()-sysStart
235  self.log.name = 'Gaudi/Main.py Logger'
236  self.log.info('-'*80)
237  self.log.info('%s: parallel system finished, time taken: %5.4fs', __name__, sysTime)
238  self.log.info('-'*80)
239  return 0
def Gaudi.Main.gaudimain.runParallel (   self,
  ncpus 
)

Definition at line 199 of file Main.py.

200  def runParallel(self, ncpus) :
201  if self.mainLoop:
202  self.log.fatal("Cannot use custom main loop in multi-process mode, check your options")
203  return 1
204  self.setupParallelLogging( )
205  from Gaudi.Configuration import Configurable
206  import GaudiMP.GMPBase as gpp
207  c = Configurable.allConfigurables
208  self.log.info('-'*80)
209  self.log.info('%s: Parallel Mode : %i '%(__name__, ncpus))
210  from commands import getstatusoutput as gso
211  metadataCommands = [ 'uname -a',
212  'echo $CMTCONFIG',
213  'echo $GAUDIAPPNAME',
214  'echo $GAUDIAPPVERSION']
215  for comm in metadataCommands :
216  s, o = gso( comm )
217  if s :
218  o = "Undetermined"
219  string = '%s: %30s : %s '%(__name__, comm, o)
220  self.log.info( string )
221  try :
222  events = str(c['ApplicationMgr'].EvtMax)
223  except :
224  events = "Undetermined"
225  self.log.info('%s: Events Specified : %s '%(__name__,events))
226  self.log.info('-'*80)
227  # Parall = gpp.Coordinator(ncpus, shared, c, self.log)
228  Parall = gpp.Coord( ncpus, c, self.log )
229  sysStart = time()
230  sc = Parall.Go()
231  self.log.info('MAIN.PY : received %s from Coordinator'%(sc))
232  if sc.isFailure() :
233  return 1
234  sysTime = time()-sysStart
235  self.log.name = 'Gaudi/Main.py Logger'
236  self.log.info('-'*80)
237  self.log.info('%s: parallel system finished, time taken: %5.4fs', __name__, sysTime)
238  self.log.info('-'*80)
239  return 0
def Gaudi.Main.gaudimain.runSerial (   self)

Definition at line 165 of file Main.py.

166  def runSerial(self) :
167  #--- Instantiate the ApplicationMgr------------------------------
168  import GaudiPython
169  self.log.debug('-'*80)
170  self.log.debug('%s: running in serial mode', __name__)
171  self.log.debug('-'*80)
172  sysStart = time()
173  self.g = GaudiPython.AppMgr()
174  self._printsequence()
175  runner = self.mainLoop or (lambda app, nevt: app.run(nevt))
176  try:
177  statuscode = runner(self.g, self.g.EvtMax)
178  except SystemError:
179  # It may not be 100% correct, but usually it means a segfault in C++
180  self.g.ReturnCode = 128 + 11
181  statuscode = False
182  except:
183  # for other exceptions, just set a generic error code
184  self.g.ReturnCode = 1
185  statuscode = False
186  if hasattr(statuscode, "isSuccess"):
187  success = statuscode.isSuccess()
188  else:
189  success = statuscode
190  success = self.g.exit().isSuccess() and success
191  if not success and self.g.ReturnCode == 0:
192  # ensure that the return code is correctly set
193  self.g.ReturnCode = 1
194  sysTime = time()-sysStart
195  self.log.debug('-'*80)
196  self.log.debug('%s: serial system finished, time taken: %5.4fs', __name__, sysTime)
197  self.log.debug('-'*80)
198  return self.g.ReturnCode
def Gaudi.Main.gaudimain.runSerial (   self)

Definition at line 165 of file Main.py.

166  def runSerial(self) :
167  #--- Instantiate the ApplicationMgr------------------------------
168  import GaudiPython
169  self.log.debug('-'*80)
170  self.log.debug('%s: running in serial mode', __name__)
171  self.log.debug('-'*80)
172  sysStart = time()
173  self.g = GaudiPython.AppMgr()
174  self._printsequence()
175  runner = self.mainLoop or (lambda app, nevt: app.run(nevt))
176  try:
177  statuscode = runner(self.g, self.g.EvtMax)
178  except SystemError:
179  # It may not be 100% correct, but usually it means a segfault in C++
180  self.g.ReturnCode = 128 + 11
181  statuscode = False
182  except:
183  # for other exceptions, just set a generic error code
184  self.g.ReturnCode = 1
185  statuscode = False
186  if hasattr(statuscode, "isSuccess"):
187  success = statuscode.isSuccess()
188  else:
189  success = statuscode
190  success = self.g.exit().isSuccess() and success
191  if not success and self.g.ReturnCode == 0:
192  # ensure that the return code is correctly set
193  self.g.ReturnCode = 1
194  sysTime = time()-sysStart
195  self.log.debug('-'*80)
196  self.log.debug('%s: serial system finished, time taken: %5.4fs', __name__, sysTime)
197  self.log.debug('-'*80)
198  return self.g.ReturnCode
def Gaudi.Main.gaudimain.setupParallelLogging (   self)

Definition at line 44 of file Main.py.

44 
45  def setupParallelLogging( self ) :
46  # ---------------------------------------------------
47  # set up Logging
48  # ----------------
49  # from multiprocessing import enableLogging, getLogger
50  import multiprocessing
51  # preliminaries for handlers/output files, etc.
52  from time import ctime
53  datetime = ctime()
54  datetime = datetime.replace(' ', '_')
55  outfile = open( 'gaudirun-%s.log'%(datetime), 'w' )
56  # two handlers, one for a log file, one for terminal
57  streamhandler = logging.StreamHandler(strm=outfile)
58  console = logging.StreamHandler()
59  # create formatter : the params in parentheses are variable names available via logging
60  formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s" )
61  # add formatter to Handler
62  streamhandler.setFormatter(formatter)
63  console.setFormatter(formatter)
64  # now, configure the logger
65  # enableLogging( level=0 )
66  # self.log = getLogger()
67  self.log = multiprocessing.log_to_stderr()
68  self.log.setLevel( logging.INFO )
69  self.log.name = 'Gaudi/Main.py Logger'
70  self.log.handlers = []
71  # add handlers to logger : one for output to a file, one for console output
72  self.log.addHandler(streamhandler)
73  self.log.addHandler(console)
74  self.log.removeHandler(console)
75  # set level!!
76  self.log.setLevel = logging.INFO
77  # ---------------------------------------------------
def Gaudi.Main.gaudimain.setupParallelLogging (   self)

Definition at line 44 of file Main.py.

44 
45  def setupParallelLogging( self ) :
46  # ---------------------------------------------------
47  # set up Logging
48  # ----------------
49  # from multiprocessing import enableLogging, getLogger
50  import multiprocessing
51  # preliminaries for handlers/output files, etc.
52  from time import ctime
53  datetime = ctime()
54  datetime = datetime.replace(' ', '_')
55  outfile = open( 'gaudirun-%s.log'%(datetime), 'w' )
56  # two handlers, one for a log file, one for terminal
57  streamhandler = logging.StreamHandler(strm=outfile)
58  console = logging.StreamHandler()
59  # create formatter : the params in parentheses are variable names available via logging
60  formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s" )
61  # add formatter to Handler
62  streamhandler.setFormatter(formatter)
63  console.setFormatter(formatter)
64  # now, configure the logger
65  # enableLogging( level=0 )
66  # self.log = getLogger()
67  self.log = multiprocessing.log_to_stderr()
68  self.log.setLevel( logging.INFO )
69  self.log.name = 'Gaudi/Main.py Logger'
70  self.log.handlers = []
71  # add handlers to logger : one for output to a file, one for console output
72  self.log.addHandler(streamhandler)
73  self.log.addHandler(console)
74  self.log.removeHandler(console)
75  # set level!!
76  self.log.setLevel = logging.INFO
77  # ---------------------------------------------------
def Gaudi.Main.gaudimain.writeconfig (   self,
  filename,
  all = False 
)

Definition at line 119 of file Main.py.

120  def writeconfig(self, filename, all = False):
121  write = { ".pkl" : lambda filename, all: self._writepickle(filename),
122  ".py" : lambda filename, all: open(filename,"w").write(self.generatePyOutput(all) + "\n"),
123  ".opts": lambda filename, all: open(filename,"w").write(self.generateOptsOutput(all) + "\n"),
124  }
125  from os.path import splitext
126  ext = splitext(filename)[1]
127  if ext in write:
128  write[ext](filename, all)
129  else:
130  log.error("Unknown file type '%s'. Must be any of %r.", ext, write.keys())
131  sys.exit(1)
def Gaudi.Main.gaudimain.writeconfig (   self,
  filename,
  all = False 
)

Definition at line 119 of file Main.py.

120  def writeconfig(self, filename, all = False):
121  write = { ".pkl" : lambda filename, all: self._writepickle(filename),
122  ".py" : lambda filename, all: open(filename,"w").write(self.generatePyOutput(all) + "\n"),
123  ".opts": lambda filename, all: open(filename,"w").write(self.generateOptsOutput(all) + "\n"),
124  }
125  from os.path import splitext
126  ext = splitext(filename)[1]
127  if ext in write:
128  write[ext](filename, all)
129  else:
130  log.error("Unknown file type '%s'. Must be any of %r.", ext, write.keys())
131  sys.exit(1)

Member Data Documentation

Gaudi.Main.gaudimain.g

Definition at line 172 of file Main.py.

Gaudi.Main.gaudimain.log

Definition at line 41 of file Main.py.

Gaudi.Main.gaudimain.mainLoop None
static

Definition at line 32 of file Main.py.

Gaudi.Main.gaudimain.printsequence

Definition at line 42 of file Main.py.


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