3.1.8.6. c3po.services.tracer module
Contain the class wrapper tracer.
- c3po.services.tracer.buildTypeArgs(name, bases, dct)
INTERNAL
- c3po.services.tracer.getArgsString(*args, **kwargs)
INTERNAL
- c3po.services.tracer.getDtInput(dt)
INTERNAL
- c3po.services.tracer.getNameFieldInput(name, field)
INTERNAL
- c3po.services.tracer.getNameInput(name)
INTERNAL
- c3po.services.tracer.getRegularName(name)
INTERNAL
- c3po.services.tracer.getSaveInput(label, method)
INTERNAL
- c3po.services.tracer.getStationaryModeInput(stationaryMode)
INTERNAL
- c3po.services.tracer.getTimeInput(time_)
INTERNAL
- c3po.services.tracer.tracer(pythonFile=None, saveInputMED=False, saveOutputMED=False, stdoutFile=None, stderrFile=None, listingWriter=None, workingDir=None)
tracer()is a class wrapper allowing to trace the calls of the methods of the base class.tracer()is to be applied on a class (not an object) and return a new class that inherits from the provided one.It has different functions:
It can write all calls of the methods of the base class in a text file in python format in order to allow to replay what happened from the code point of view outside of the coupling.
It can save in .med files input or output MEDFields.
It can redirect code standard and error outputs in text files.
It can contribute (with
ListingWriter) to the writing of a global coupling listing file with calculation time measurement.
The parameters of tracer are added to the returned class (“static” attributes) with the names
static_pythonFile,static_saveInputMED,static_saveOutputMED,static_stdout,static_stderr,static_lWriterandstatic_wDir.One additional static attribute is added for internal use:
static_Objectcounter.Two additional attributes (not static!) are added for internal use:
tracerObjectNameandtracerRecurrenceDepth.tracer()can be used either as a python decorator (where the class is defined) in order to modify the class definition everywhere:@c3po.tracer(...) class MyClass(...): ...
or it can be used in order to redefined only locally the class like that:
MyNewClass = c3po.tracer(...)(MyClass)
Note
In case a method calls another method of self, tracer modifies only to the first method call.
Warning
tracer()can be applied to any class, but it is design for standard C3PO objects:PhysicsDriver,DataManagerandExchanger. It may be hazardous to use on “similar but not identical” classes (typically with the same methods but different inputs and/or outputs).tracer()looks for ICoCo methods (the methods to implement in order to define aPhysicsDriver) (plus__init__) in base classes and redefine them. Other inherited methods are invisible totracer().It is recommended not to overload a class: use “
MyNewClass = c3po.tracer(...)(MyClass)” and not “MyClass = c3po.tracer(...)(MyClass)”. Overloading a class may lead toTypeError, in particular in case of inheritance, if the mother class is not accessible any more.- Parameters:
pythonFile – A file object which has to be already open in written mode (
file = open("file.txt", "w")). The python script is written there. It has to be closed (file.close()) by caller. The script can be run only ifsaveInputMEDis set to True: otherwise, input MED fields are not stored.saveInputMED (bool) – If set to True, every time
setInputMED(Double/Int/String)Fieldis called, the input MED field is stored in a.medfile. IfpythonFileis activated, a MEDLoader reading instruction is also written in the Python file.saveOutputMED (bool) – If set to True, every time
getOutputMED(Double/Int/String)Fieldis called, the output MED field is stored in a.medfile.stdoutFile – A file object which has to be already open in written mode (
file = open("file.txt", "w")). The standard output is redirected there. It has to be closed (file.close()) by caller.stderrFile – A file object which has to be already open in written mode (
file = open("file.txt", "w")). The error output is redirected there. It has to be closed (file.close()) by caller.listingWriter (ListingWriter) – A
ListingWriterobject which will manage the writing of the coupling listing file. Refer to the documentation ofListingWriter.workingDir – Path to an existing directory which is used as working directory when calling the methods of the traced object.
- Raises:
Exception – If applied to a class already modified by
tracer(), because it could result in an unexpected behavior.