9 #ifndef ANAB_FEATUREVECTORS_H 10 #define ANAB_FEATUREVECTORS_H 12 #include "cetlib_except/exception.h" 45 FeatureVector(
float const * values) {
for (
size_t i = 0; i < N; ++i) { fData[i] = values[i]; } }
46 FeatureVector(
double const * values) {
for (
size_t i = 0; i < N; ++i) { fData[i] = values[i]; } }
57 o <<
"FeatureVector values:";
58 for (
size_t i = 0; i < N; ++i) { o <<
" " << a.
fData[i]; }
63 size_t size()
const {
return N; }
65 float at(
size_t index)
const 67 if (index < N) {
return fData[index]; }
68 else {
throw cet::exception(
"FeatureVector") <<
"Index out of range: " << index << std::endl; }
71 float operator[] (
size_t index)
const {
return fData[index]; }
79 void set(
float init) {
for (
size_t i = 0; i < N; ++i) { fData[i] = init; } }
80 void set(std::array<float, N>
const & values) {
for (
size_t i = 0; i < N; ++i) { fData[i] = values[i]; } }
81 void set(std::array<double, N>
const & values) {
for (
size_t i = 0; i < N; ++i) { fData[i] = values[i]; } }
82 void set(std::vector<float>
const & values)
84 if (values.size() == N) {
for (
size_t i = 0; i < N; ++i) { fData[i] = values[i]; } }
85 else {
throw cet::exception(
"FeatureVector") <<
"Expected length: " << N <<
", provided: " << values.size() << std::endl; }
87 void set(std::vector<double>
const & values)
89 if (values.size() == N) {
for (
size_t i = 0; i < N; ++i) { fData[i] = values[i]; } }
90 else {
throw cet::exception(
"FeatureVector") <<
"Expected length: " << N <<
", provided: " << values.size() << std::endl; }
110 std::string fOutputNames[N];
115 std::vector< std::string >
const & outputNames = std::vector< std::string >(N,
"")) :
117 fOutputInstance(outputInstance)
119 setOutputNames(outputNames);
123 std::vector< std::string >
const & outputNames = std::vector< std::string >(N,
"")) :
125 fOutputInstance(outputInstance)
127 setOutputNames(outputNames);
132 o <<
"MVADescription: prepared for " << a.
fDataTag <<
", instance name " << a.
fOutputInstance <<
", " << N <<
" outputs:" << std::endl;
133 for (
size_t i = 0; i < N; ++i) { o <<
" " << a.
fOutputNames[i] << std::endl; }
139 size_t size()
const {
return N; }
141 const std::string &
dataTag()
const {
return fDataTag; }
144 if (fDataTag.empty()) { fDataTag = tag; }
145 else {
throw cet::exception(
"MVADescription") <<
"Data tag already assigned: " << fDataTag << std::endl; }
150 if (index < N) {
return fOutputNames[index]; }
151 else {
throw cet::exception(
"MVADescription") <<
"Index out of range: " << index << std::endl; }
155 if (outputNames.size() <= N) {
for (
size_t i = 0; i < outputNames.size(); ++i) { fOutputNames[i] = outputNames[i]; } }
156 else {
throw cet::exception(
"FeatureVector") <<
"Expected max length of outputNames: " << N <<
", provided: " << outputNames.size() << std::endl; }
161 for (
size_t i = 0; i < N; ++i) {
if (fOutputNames[i] == name) {
return i; } }
172 #endif //ANAB_FEATUREVECTORS void setDataTag(const std::string &tag)
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
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)
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)
std::string fDataTag
Tag of the reco data products (art::InputTag format)
cet::coded_exception< error, detail::translate > exception
FeatureVector & operator=(float init)
Assignment operators, from the same types as constructors.