9 #ifndef ANAB_FEATUREVECTORS_H 10 #define ANAB_FEATUREVECTORS_H 12 #include "cetlib_except/exception.h" 44 for (
size_t i = 0; i < N; ++i) {
50 for (
size_t i = 0; i < N; ++i) {
84 o <<
"FeatureVector values:";
85 for (
size_t i = 0; i < N; ++i) {
86 o <<
" " << a.
fData[i];
92 size_t size()
const {
return N; }
94 float at(
size_t index)
const 96 if (index < N) {
return fData[index]; }
98 throw cet::exception(
"FeatureVector") <<
"Index out of range: " << index << std::endl;
102 float operator[](
size_t index)
const {
return fData[index]; }
111 for (
size_t i = 0; i < N; ++i) {
115 void set(std::array<float, N>
const&
values)
117 for (
size_t i = 0; i < N; ++i) {
121 void set(std::array<double, N>
const&
values)
123 for (
size_t i = 0; i < N; ++i) {
127 void set(std::vector<float>
const&
values)
130 for (
size_t i = 0; i < N; ++i) {
136 <<
"Expected length: " << N <<
", provided: " <<
values.size() << std::endl;
139 void set(std::vector<double>
const&
values)
142 for (
size_t i = 0; i < N; ++i) {
148 <<
"Expected length: " << N <<
", provided: " <<
values.size() << std::endl;
167 std::string fOutputNames[N];
171 std::string
const& outputInstance,
172 std::vector<std::string>
const& outputNames = std::vector<std::string>(N,
""))
173 : fDataTag(dataTag), fOutputInstance(outputInstance)
175 setOutputNames(outputNames);
179 std::vector<std::string>
const& outputNames = std::vector<std::string>(N,
""))
182 fOutputInstance(outputInstance)
184 setOutputNames(outputNames);
190 <<
", " << N <<
" outputs:" << std::endl;
191 for (
size_t i = 0; i < N; ++i) {
199 size_t size()
const {
return N; }
201 const std::string&
dataTag()
const {
return fDataTag; }
204 if (fDataTag.empty()) { fDataTag = tag; }
207 <<
"Data tag already assigned: " << fDataTag << std::endl;
213 if (index < N) {
return fOutputNames[index]; }
215 throw cet::exception(
"MVADescription") <<
"Index out of range: " << index << std::endl;
220 if (outputNames.size() <= N) {
221 for (
size_t i = 0; i < outputNames.size(); ++i) {
222 fOutputNames[i] = outputNames[i];
226 throw cet::exception(
"FeatureVector") <<
"Expected max length of outputNames: " << N
227 <<
", provided: " << outputNames.size() << std::endl;
233 for (
size_t i = 0; i < N; ++i) {
234 if (fOutputNames[i] == name) {
return i; }
246 #endif //ANAB_FEATUREVECTORS void setDataTag(const std::string &tag)
FeatureVector & operator=(std::array< float, N > const &values)
static short Class_Version()
friend std::ostream & operator<<(std::ostream &o, FeatureVector const &a)
const std::string & dataTag() const
void setOutputNames(std::vector< std::string > const &outputNames)
std::string fOutputInstance
Instance name of the feature vector collection.
static short Class_Version()
int getIndex(const std::string &name) const
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
FeatureVector(float init)
FeatureVector(float const *values)
If you really have to use C arrays:
FeatureVector(std::vector< double > const &values)
float fData[N]
Vector values.
const std::string & outputInstance() const
const std::string & outputName(size_t index) const
MVADescription(std::string const &outputInstance, std::vector< std::string > const &outputNames=std::vector< std::string >(N,""))
FeatureVector(std::vector< float > const &values)
FeatureVector & operator=(std::vector< float > const &values)
std::string fOutputNames[N]
Feature vector entries names/meaning.
float at(size_t index) const
FeatureVector(std::array< double, N > const &values)
FeatureVector(std::array< float, N > const &values)
MVADescription(std::string const &dataTag, std::string const &outputInstance, std::vector< std::string > const &outputNames=std::vector< std::string >(N,""))
float operator[](size_t index) const
FeatureVector(double const *values)
FeatureVector & operator=(std::array< double, N > const &values)
std::string fDataTag
Tag of the reco data products (art::InputTag format)
friend std::ostream & operator<<(std::ostream &o, MVADescription const &a)
cet::coded_exception< error, detail::translate > exception
FeatureVector & operator=(float init)
Assignment operators, from the same types as constructors.
FeatureVector & operator=(std::vector< double > const &values)