add a getExternalObjects method to return a list/vector of objects
Propose to add a method called getExternalObjects
(with an s at the end) inside Detector.hpp.
This method functions in the same way as getExernalObject
but instead of returning only one object it would return a list of all the objects that contain a specific string. E.g use case where one has two sensors with logical volumes called sensor_log_0
and sensor_log_1
. A call to getExternalobjects would return a vector with both objects.
This is useful in the specific case where one has multiple sensors inside a detector. I am using for a personal application (and it works). Maybe this feature is relevant for other purposes and can be included in the general code.
/**
* @brief Fetch of all external objects linked to this detector
* @param name Name of the external objects
* @return External objects or null pointer if no objects contain the name
*/
template <typename T> std::vector<std::shared_ptr<T>> getExternalObjects(const std::string& name);
template <typename T> std::vector<std::shared_ptr<T>> Detector::getExternalObjects(const std::string& name) {
std::vector<std::shared_ptr<T>> objects;
for(auto& ext_obj : external_objects_) {
auto match_map = ext_obj.second;
for(auto& x : match_map) {
if((x.first).find(name) != std::string::npos) {
// push back the object
objects.push_back(std::static_pointer_cast<T>(x.second));
}
}
}
return objects;
}