ral 0.0.1
Loading...
Searching...
No Matches
LogicalOperators.h
Go to the documentation of this file.
1#ifndef LOGICAL_OPERATORS_RAL_H
2#define LOGICAL_OPERATORS_RAL_H
3
4// std
5#include <type_traits>
6
7// ROOT
8#include "ROOT/RVec.hxx"
9
10// PODIO
11#include "podio/CollectionBase.h"
12
13namespace k4::ral {
14
15namespace LogicalOperators {
16
18
19template <typename C, typename = std::enable_if<
20 std::is_base_of<podio::CollectionBase, C>::value>>
21C filter(const ROOT::VecOps::RVec<bool> &mask, const C &collection) {
22 if (mask.size() != collection.size()) {
23 auto msg = "Different vector lengths: " + std::to_string(mask.size()) +
24 " vs. " + std::to_string(collection.size()) + "!";
25 throw std::length_error(msg);
26 }
27
28 C result;
29 result.setSubsetCollection();
30 for (int i = 0; i < collection.size(); i++) {
31 if (mask[i]) {
32 result.push_back(collection[i]);
33 }
34 }
35
36 return result;
37}
38
39template <typename T>
40ROOT::VecOps::RVec<T> filter(const ROOT::VecOps::RVec<bool> &mask,
41 const ROOT::VecOps::RVec<T> &collection) {
42 if (mask.size() != collection.size()) {
43 auto msg = "Different vector lengths: " + std::to_string(mask.size()) +
44 " vs. " + std::to_string(collection.size()) + "!";
45 throw std::length_error(msg);
46 }
47
48 ROOT::VecOps::RVec<T> result;
49 for (int i = 0; i < collection.size(); i++) {
50 if (mask[i]) {
51 result.emplace_back(collection[i]);
52 }
53 }
54
55 return result;
56}
57
58ROOT::VecOps::RVec<bool> operator&&(const ROOT::VecOps::RVec<bool> &vec1,
59 const ROOT::VecOps::RVec<bool> &vec2);
60
61ROOT::VecOps::RVec<bool> operator||(const ROOT::VecOps::RVec<bool> &vec1,
62 const ROOT::VecOps::RVec<bool> &vec2);
63
64ROOT::VecOps::RVec<bool> operator!(const ROOT::VecOps::RVec<bool> &vec1);
65
66} // namespace LogicalOperators
67} // namespace k4::ral
68#endif
ROOT::VecOps::RVec< bool > operator||(const ROOT::VecOps::RVec< bool > &vec1, const ROOT::VecOps::RVec< bool > &vec2)
Definition LogicalOperators.cc:25
ComparisonOperator
Definition LogicalOperators.h:17
ROOT::VecOps::RVec< bool > operator!(const ROOT::VecOps::RVec< bool > &vec1)
Definition LogicalOperators.cc:40
ROOT::VecOps::RVec< bool > operator&&(const ROOT::VecOps::RVec< bool > &vec1, const ROOT::VecOps::RVec< bool > &vec2)
Definition LogicalOperators.cc:10
C filter(const ROOT::VecOps::RVec< bool > &mask, const C &collection)
Definition LogicalOperators.h:21
Definition CalorimeterHit.cc:2