Removed spurious prints. Do better CosmoTool exception translation
This commit is contained in:
parent
22aa572370
commit
1fe8f58105
@ -44,9 +44,11 @@ cdef extern from "safe_gadget.hpp":
|
|||||||
SimuData **alloc_simudata(int num) nogil
|
SimuData **alloc_simudata(int num) nogil
|
||||||
void del_simudata(SimuData **d) nogil
|
void del_simudata(SimuData **d) nogil
|
||||||
|
|
||||||
cdef extern from "loadRamses.hpp" namespace "CosmoTool":
|
cdef extern from "cppHelper.hpp":
|
||||||
SimuData *loadRamsesSimu(const char *basename, int id, int cpuid, bool dp, int flags) except +
|
int customCosmotoolHandler() nogil
|
||||||
|
|
||||||
|
cdef extern from "loadRamses.hpp" namespace "CosmoTool":
|
||||||
|
SimuData *loadRamsesSimu(const char *basename, int id, int cpuid, bool dp, int flags) except +customCosmotoolHandler
|
||||||
|
|
||||||
class PySimulationBase(object):
|
class PySimulationBase(object):
|
||||||
"""
|
"""
|
||||||
@ -226,7 +228,6 @@ cdef class Simulation:
|
|||||||
|
|
||||||
def __dealloc__(Simulation self):
|
def __dealloc__(Simulation self):
|
||||||
if self.data != <SimuData *>0:
|
if self.data != <SimuData *>0:
|
||||||
print("Clearing simulation data")
|
|
||||||
del self.data
|
del self.data
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,6 +105,9 @@ def loadRamsesAll(basepath, snapshot_id, **kwargs):
|
|||||||
Args:
|
Args:
|
||||||
basepath (str): The base path of the snapshot (i.e. the directory holding the output_XXXXX directories)
|
basepath (str): The base path of the snapshot (i.e. the directory holding the output_XXXXX directories)
|
||||||
snapshot_id (int): The identifier of the snapshot to load.
|
snapshot_id (int): The identifier of the snapshot to load.
|
||||||
|
|
||||||
|
Keyword args:
|
||||||
|
verboseMulti (bool): If true, print some progress information on loading multiple files
|
||||||
|
|
||||||
See Also:
|
See Also:
|
||||||
cosmotool.loadRamses
|
cosmotool.loadRamses
|
||||||
@ -112,8 +115,15 @@ def loadRamsesAll(basepath, snapshot_id, **kwargs):
|
|||||||
"""
|
"""
|
||||||
cpu_id = 0
|
cpu_id = 0
|
||||||
output = None
|
output = None
|
||||||
|
verbose = kwargs.get('verboseMulti',False)
|
||||||
|
new_kw = dict(kwargs)
|
||||||
|
if 'verboseMulti' in new_kw:
|
||||||
|
del new_kw['verboseMulti']
|
||||||
while True:
|
while True:
|
||||||
s = loadRamses("%s/output_%05d" % (basepath,snapshot_id), snapshot_id, cpu_id, **kwargs)
|
base = "%s/output_%05d" % (basepath,snapshot_id)
|
||||||
|
if verbose:
|
||||||
|
print("Loading sub-snapshot %s (cpu_id=%d)" % (base,cpu_id))
|
||||||
|
s = loadRamses(base, snapshot_id, cpu_id, **new_kw)
|
||||||
if s == None:
|
if s == None:
|
||||||
break
|
break
|
||||||
if output == None:
|
if output == None:
|
||||||
|
45
python/cppHelper.hpp
Normal file
45
python/cppHelper.hpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include "config.hpp"
|
||||||
|
#include "fortran.hpp"
|
||||||
|
|
||||||
|
static void customCosmotoolHandler()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
;
|
||||||
|
else
|
||||||
|
throw;
|
||||||
|
} catch (const CosmoTool::InvalidArgumentException& e) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "Invalid argument");
|
||||||
|
} catch (const CosmoTool::NoSuchFileException& e) {
|
||||||
|
PyErr_SetString(PyExc_IOError, "No such file");
|
||||||
|
} catch (const CosmoTool::InvalidUnformattedAccess& e) {
|
||||||
|
PyErr_SetString(PyExc_RuntimeError, "Invalid fortran unformatted access");
|
||||||
|
} catch (const CosmoTool::Exception& e) {
|
||||||
|
PyErr_SetString(PyExc_RuntimeError, e.what());
|
||||||
|
} catch (const std::bad_alloc& exn) {
|
||||||
|
PyErr_SetString(PyExc_MemoryError, exn.what());
|
||||||
|
} catch (const std::bad_cast& exn) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, exn.what());
|
||||||
|
} catch (const std::domain_error& exn) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, exn.what());
|
||||||
|
} catch (const std::invalid_argument& exn) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, exn.what());
|
||||||
|
} catch (const std::ios_base::failure& exn) {
|
||||||
|
// Unfortunately, in standard C++ we have no way of distinguishing EOF
|
||||||
|
// from other errors here; be careful with the exception mask
|
||||||
|
PyErr_SetString(PyExc_IOError, exn.what());
|
||||||
|
} catch (const std::out_of_range& exn) {
|
||||||
|
// Change out_of_range to IndexError
|
||||||
|
PyErr_SetString(PyExc_IndexError, exn.what());
|
||||||
|
} catch (const std::overflow_error& exn) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError, exn.what());
|
||||||
|
} catch (const std::range_error& exn) {
|
||||||
|
PyErr_SetString(PyExc_ArithmeticError, exn.what());
|
||||||
|
} catch (const std::underflow_error& exn) {
|
||||||
|
PyErr_SetString(PyExc_ArithmeticError, exn.what());
|
||||||
|
} catch (const std::exception& exn) {
|
||||||
|
PyErr_SetString(PyExc_RuntimeError, exn.what());
|
||||||
|
} catch(...) {
|
||||||
|
PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
|
||||||
|
}
|
||||||
|
}
|
@ -60,7 +60,7 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
SimuData *p = loadGadgetMulti(fname, 0, 0);
|
SimuData *p = loadGadgetMulti(fname, 0, 0);
|
||||||
double L0 = p->BoxSize/1000;
|
double L0 = p->BoxSize;
|
||||||
CICFilter filter(res, L0);
|
CICFilter filter(res, L0);
|
||||||
|
|
||||||
delete p;
|
delete p;
|
||||||
|
@ -252,7 +252,7 @@ int readInfoFile(const char *basename, int outputId, InfoData& info)
|
|||||||
const char *pattern = "^([A-Za-z_]+)[ ]*=[ ]*([0-9\\.E+\\-]+)";
|
const char *pattern = "^([A-Za-z_]+)[ ]*=[ ]*([0-9\\.E+\\-]+)";
|
||||||
|
|
||||||
err = regcomp (&unit_l_rx, pattern, REG_EXTENDED);
|
err = regcomp (&unit_l_rx, pattern, REG_EXTENDED);
|
||||||
cout << unit_l_rx.re_nsub << endl;
|
// cout << unit_l_rx.re_nsub << endl;
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
char errString[255];
|
char errString[255];
|
||||||
@ -477,7 +477,7 @@ CosmoTool::SimuData *CosmoTool::loadRamsesSimu(const char *basename, int outputI
|
|||||||
}
|
}
|
||||||
catch (const NoSuchFileException& e)
|
catch (const NoSuchFileException& e)
|
||||||
{
|
{
|
||||||
cerr << "No such file " << fname << endl;
|
// cerr << "No such file " << fname << endl;
|
||||||
delete data;
|
delete data;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user