4 from Gaudi
import Configuration
7 log = logging.getLogger(__name__)
12 Helper to convert values to old .opts format. 14 >>> print toOpt('some "text"') 16 >>> print toOpt('first\\nsecond') 19 >>> print toOpt({'a': [1, 2, '3']}) 22 if isinstance(value, basestring):
23 return '"{0}"'.
format(value.replace(
'"',
'\\"'))
24 elif isinstance(value, dict):
25 return '{{{0}}}'.
format(
', '.join(
27 for k, v
in value.iteritems()))
28 elif hasattr(value,
'__iter__'):
29 return '[{0}]'.
format(
', '.join(
map(toOpt, value)))
36 from Configurables
import 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__)
51 import multiprocessing
53 from time
import ctime
55 datetime = datetime.replace(
' ',
'_')
56 outfile = open(
'gaudirun-%s.log' % (datetime),
'w')
58 streamhandler = logging.StreamHandler(stream=outfile)
59 console = logging.StreamHandler()
61 formatter = logging.Formatter(
62 "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
64 streamhandler.setFormatter(formatter)
65 console.setFormatter(formatter)
69 self.
log = multiprocessing.log_to_stderr()
70 self.log.setLevel(logging.INFO)
71 self.log.name =
'Gaudi/Main.py Logger' 72 self.log.handlers = []
74 self.log.addHandler(streamhandler)
75 self.log.addHandler(console)
76 self.log.removeHandler(console)
78 self.log.setLevel = logging.INFO
82 from pprint
import pformat
83 conf_dict = Configuration.configurationDict(all)
84 return pformat(conf_dict)
87 from pprint
import pformat
88 conf_dict = Configuration.configurationDict(all)
90 names = conf_dict.keys()
93 props = conf_dict[n].keys()
96 out.append(
'%s.%s = %s;' % (n, p,
toOpt(conf_dict[n][p])))
102 output = open(filename,
'wb')
104 from GaudiKernel.Proxy.Configurable
import getNeededConfigurables
107 to_dump[n] = Configuration.allConfigurables[n]
108 pickle.dump(to_dump, output, -1)
112 msg =
'Dumping all configurables and properties' 114 msg +=
' (different from default)' 116 conf_dict = Configuration.configurationDict(all)
123 write = {
".pkl":
lambda filename, all: self.
_writepickle(filename),
124 ".py":
lambda filename, all: open(filename,
"w").write(self.
generatePyOutput(all) +
"\n"),
125 ".opts":
lambda filename, all: open(filename,
"w").write(self.
generateOptsOutput(all) +
"\n"),
127 from os.path
import splitext
128 ext = splitext(filename)[1]
130 write[ext](filename, all)
132 log.error(
"Unknown file type '%s'. Must be any of %r.", ext,
138 def run(self, attach_debugger, ncpus=None):
140 if os.environ.get(
'GAUDIRUN_USE_OLDINIT'):
141 result = self.runSerialOld(attach_debugger)
152 self.log.info(
'attaching debugger to PID ' + str(os.getpid()))
153 pid = os.spawnvp(os.P_NOWAIT, debugger,
154 [debugger,
'-q',
'python',
162 os.waitpid(pid, os.WNOHANG)
168 from GaudiKernel.Proxy.Configurable
import expandvars
174 from GaudiKernel.Proxy.Configurable
import Configurable, getNeededConfigurables
176 self.log.debug(
'runSerial: apply options')
177 conf_dict = {
'ApplicationMgr.JobOptionsType':
'"NONE"'}
181 for c
in Configurable.allConfigurables.values():
182 if hasattr(c,
'getValuedProperties'):
183 c.getValuedProperties()
186 c = Configurable.allConfigurables[n]
187 for p, v
in c.getValuedProperties().items():
190 if hasattr(Configurable,
"PropertyReference")
and type(
191 v) == Configurable.PropertyReference:
197 elif type(v) == long:
199 conf_dict[
'{}.{}'.
format(n, p)] = str(v)
202 conf_dict[
'ApplicationMgr.PrintAlgsSequence'] =
'true' 204 if hasattr(Configurable,
"_configurationLocked"):
205 Configurable._configurationLocked =
True 210 self.log.debug(
'-' * 80)
211 self.log.debug(
'%s: running in serial mode', __name__)
212 self.log.debug(
'-' * 80)
219 sysTime =
time() - sysStart
220 self.log.debug(
'-' * 80)
221 self.log.debug(
'%s: serial system finished, time taken: %5.4fs',
223 self.log.debug(
'-' * 80)
231 c = Configurable.allConfigurables
232 self.log.info(
'-' * 80)
233 self.log.info(
'%s: Parallel Mode : %i ', __name__, ncpus)
235 (
'platrofm',
' '.join(os.uname())),
236 (
'config', os.environ.get(
'BINARY_TAG')
237 or os.environ.get(
'CMTCONFIG')),
238 (
'app. name', os.environ.get(
'GAUDIAPPNAME')),
239 (
'app. version', os.environ.get(
'GAUDIAPPVERSION')),
241 self.log.info(
'%s: %30s : %s ', __name__, name, value
244 events = str(c[
'ApplicationMgr'].EvtMax)
246 events =
"Undetermined" 247 self.log.info(
'%s: Events Specified : %s ', __name__, events)
248 self.log.info(
'-' * 80)
250 Parall = gpp.Coord(ncpus, c, self.
log)
253 self.log.info(
'MAIN.PY : received %s from Coordinator' % (sc))
256 sysTime =
time() - sysStart
257 self.log.name =
'Gaudi/Main.py Logger' 258 self.log.info(
'-' * 80)
259 self.log.info(
'%s: parallel system finished, time taken: %5.4fs',
261 self.log.info(
'-' * 80)
def run(self, attach_debugger, ncpus=None)
def setupParallelLogging(self)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
def _writepickle(self, filename)
def generateOptsOutput(self, all=False)
def runParallel(self, ncpus)
def hookDebugger(self, debugger='gdb')
def generatePyOutput(self, all=False)
struct GAUDI_API map
Parametrisation class for map-like implementation.
def create(cls, appType, opts)
The Application Manager class.
def printconfig(self, old_format=False, all=False)
def writeconfig(self, filename, all=False)
def runSerial(self, attach_debugger)