FairShip
Loading...
Searching...
No Matches
pyFairModule.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5#include "pyFairModule.h"
6
7#include "FairVolume.h"
8#include "Python.h"
9#include "TObject.h"
10
11std::vector<std::string> pyFairModule::SensitiveVolumeNames(
12 const std::string& module) {
13 std::vector<std::string> names;
14 names.reserve(fAllSensitiveVolumes.size());
15 for (const FairVolume* volume : fAllSensitiveVolumes) {
16 if (!volume) {
17 continue;
18 }
19 if (!module.empty() &&
20 (!volume->GetModule() || module != volume->GetModule()->GetName())) {
21 continue;
22 }
23 std::string name = volume->GetName();
24 // Same cut as in FairDetector::Initialize()
25 const auto pos = name.find('#', 1);
26 if (pos != std::string::npos && pos > 1) {
27 name.resize(pos);
28 }
29 names.push_back(name);
30 }
31 return names;
32}
33
34void call_python_method(PyObject* self, const char* method) {
35 // check arguments
36 if (nullptr == self || nullptr == method) {
37 throw std::runtime_error("Invalid Python object and method");
38 }
39 // call Python
40 PyObject* r = PyObject_CallMethod(self, const_cast<char*>(method),
41 const_cast<char*>(""));
42 if (nullptr == r) {
43 PyErr_Print();
44 return;
45 }
46 // release used objects
47 Py_XDECREF(r);
48 //
49 return;
50}
static std::vector< std::string > SensitiveVolumeNames(const std::string &module="")
void call_python_method(PyObject *self, const char *method)
_object PyObject
Definition pyFairModule.h:9