663.9.40
by Chris Rogers
Python interface and calls to start of run |
1 |
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
|
2 |
*
|
|
3 |
* MAUS is free software: you can redistribute it and/or modify
|
|
4 |
* it under the terms of the GNU General Public License as published by
|
|
5 |
* the Free Software Foundation, either version 3 of the License, or
|
|
6 |
* (at your option) any later version.
|
|
7 |
*
|
|
8 |
* MAUS is distributed in the hope that it will be useful,
|
|
9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
* GNU General Public License for more details.
|
|
12 |
*
|
|
13 |
* You should have received a copy of the GNU General Public License
|
|
14 |
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
||
18 |
#include <string> |
|
19 |
||
20 |
#include "src/common_cpp/DataStructure/RunHeader.hh" |
|
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
21 |
#include "src/common_cpp/JsonCppProcessors/RunHeaderProcessor.hh" |
663.9.40
by Chris Rogers
Python interface and calls to start of run |
22 |
#include "src/common_cpp/DataStructure/RunFooter.hh" |
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
23 |
#include "src/common_cpp/JsonCppProcessors/RunFooterProcessor.hh" |
663.9.40
by Chris Rogers
Python interface and calls to start of run |
24 |
|
25 |
#include "src/common_cpp/Utils/Globals.hh" |
|
26 |
#include "src/common_cpp/Utils/RunActionManager.hh" |
|
27 |
||
28 |
#include "src/py_cpp/PyRunActionManager.hh" |
|
29 |
||
30 |
namespace MAUS { |
|
31 |
namespace PyRunActionManager { |
|
32 |
std::string StartOfRun_DocString = |
|
33 |
std::string("start_of_run(run_number)\n\n")+ |
|
34 |
std::string("Call the start of run action for all RunActions registered ")+ |
|
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
35 |
std::string("with the run action manager.\n\n")+ |
36 |
std::string("\\param run_number is an integer corresponding to the run ")+ |
|
37 |
std::string("number of the new run.\n\n")+ |
|
38 |
std::string("\\returns string representation of the RunHeader (json format)"); |
|
663.9.40
by Chris Rogers
Python interface and calls to start of run |
39 |
|
40 |
std::string EndOfRun_DocString = |
|
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
41 |
std::string("end_of_run(run_number)\n\n")+ |
663.9.40
by Chris Rogers
Python interface and calls to start of run |
42 |
std::string("Call the end of run action for all RunActions registered ")+ |
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
43 |
std::string("with the run action manager.\n\n")+ |
44 |
std::string("\\param run_number is an integer corresponding to the run ")+ |
|
45 |
std::string("number of the new run.\n\n")+ |
|
46 |
std::string("\\returns string representation of the RunFooter (json format)"); |
|
663.9.40
by Chris Rogers
Python interface and calls to start of run |
47 |
|
48 |
PyObject* StartOfRun(PyObject *dummy, PyObject *args) { |
|
49 |
int run_number; |
|
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
50 |
std::string head_str; |
663.9.40
by Chris Rogers
Python interface and calls to start of run |
51 |
if (!PyArg_ParseTuple(args, "i", &run_number)) { |
52 |
PyErr_SetString(PyExc_TypeError, |
|
53 |
"Failed to interpret start_of_run argument as an integer"); |
|
54 |
return NULL; |
|
55 |
}
|
|
56 |
try { |
|
57 |
RunActionManager* maus_run_action_manager = |
|
58 |
Globals::GetInstance()->GetRunActionManager(); |
|
59 |
if (maus_run_action_manager == NULL) { |
|
60 |
PyErr_SetString(PyExc_RuntimeError, |
|
61 |
"Error - somehow MAUS library was initialised but run action is not."); |
|
62 |
return NULL; |
|
63 |
}
|
|
64 |
RunHeader* run_header = new RunHeader(); |
|
65 |
run_header->SetRunNumber(run_number); |
|
663.9.41
by Chris Rogers
Passes unit tests |
66 |
maus_run_action_manager->StartOfRun(run_header); |
663.9.164
by Chris Rogers
Working through the problems... now falling over because ROOT doesnt like my test class |
67 |
Json::Value* head_json = RunHeaderProcessor().CppToJson(*run_header, ""); |
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
68 |
Py_BuildValue("s", head_str.c_str()); |
69 |
head_str = JsonWrapper::JsonToString(*head_json); |
|
70 |
delete head_json; |
|
663.9.40
by Chris Rogers
Python interface and calls to start of run |
71 |
delete run_header; |
600.1.174
by Peter Lane
Added unit tests for new PhaseSpaceVector constructors. Implemented issue #872 (treat catch like other control statements in cpplint.py). Modified existing files with now non-compliant catch statements to pass style checks. |
72 |
} catch (std::exception& exc) { |
663.9.40
by Chris Rogers
Python interface and calls to start of run |
73 |
PyErr_SetString(PyExc_RuntimeError, (&exc)->what()); |
74 |
return NULL; |
|
75 |
}
|
|
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
76 |
return Py_BuildValue("s", head_str.c_str()); |
663.9.40
by Chris Rogers
Python interface and calls to start of run |
77 |
}
|
78 |
||
79 |
PyObject* EndOfRun(PyObject *dummy, PyObject *args) { |
|
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
80 |
int run_number; |
81 |
std::string foot_str; |
|
82 |
if (!PyArg_ParseTuple(args, "i", &run_number)) { |
|
83 |
PyErr_SetString(PyExc_TypeError, |
|
84 |
"Failed to interpret end_of_run argument as an integer"); |
|
85 |
return NULL; |
|
86 |
}
|
|
663.9.40
by Chris Rogers
Python interface and calls to start of run |
87 |
try { |
88 |
RunActionManager* maus_run_action_manager = |
|
89 |
Globals::GetInstance()->GetRunActionManager(); |
|
90 |
if (maus_run_action_manager == NULL) { |
|
91 |
PyErr_SetString(PyExc_RuntimeError, |
|
92 |
"Error - somehow MAUS library was initialised but run action is not."); |
|
93 |
return NULL; |
|
94 |
}
|
|
95 |
RunFooter* run_footer = new RunFooter(); |
|
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
96 |
run_footer->SetRunNumber(run_number); |
663.9.41
by Chris Rogers
Passes unit tests |
97 |
maus_run_action_manager->EndOfRun(run_footer); |
663.9.164
by Chris Rogers
Working through the problems... now falling over because ROOT doesnt like my test class |
98 |
Json::Value* foot_json = RunFooterProcessor().CppToJson(*run_footer, ""); |
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
99 |
Py_BuildValue("s", foot_str.c_str()); |
100 |
foot_str = JsonWrapper::JsonToString(*foot_json); |
|
101 |
delete foot_json; |
|
663.9.40
by Chris Rogers
Python interface and calls to start of run |
102 |
delete run_footer; |
600.1.174
by Peter Lane
Added unit tests for new PhaseSpaceVector constructors. Implemented issue #872 (treat catch like other control statements in cpplint.py). Modified existing files with now non-compliant catch statements to pass style checks. |
103 |
} catch (std::exception& exc) { |
663.9.40
by Chris Rogers
Python interface and calls to start of run |
104 |
PyErr_SetString(PyExc_RuntimeError, (&exc)->what()); |
105 |
return NULL; |
|
106 |
}
|
|
663.9.113
by Chris Rogers
Now able to write job header. job footer, run header, run footer - but some fails in integration tests |
107 |
return Py_BuildValue("s", foot_str.c_str()); |
663.9.40
by Chris Rogers
Python interface and calls to start of run |
108 |
}
|
109 |
||
110 |
static PyMethodDef methods[] = { |
|
111 |
{"start_of_run", (PyCFunction)StartOfRun, |
|
112 |
METH_VARARGS, StartOfRun_DocString.c_str()}, |
|
113 |
{"end_of_run", (PyCFunction)EndOfRun, |
|
114 |
METH_VARARGS, EndOfRun_DocString.c_str()}, |
|
115 |
{NULL, NULL, 0, NULL} |
|
116 |
};
|
|
117 |
||
118 |
PyMODINIT_FUNC initrun_action_manager(void) { |
|
119 |
Py_Initialize(); |
|
120 |
PyObject* maus_module = Py_InitModule("run_action_manager", methods); |
|
121 |
if (maus_module == NULL) return; |
|
122 |
}
|
|
123 |
} // namespace PyRunActionManager |
|
124 |
} // namespace MAUS |
|
125 |
||
126 |