9 #ifndef ANAB_MVAWRITER_H 10 #define ANAB_MVAWRITER_H 51 FVector_ID
initOutputs(std::string
const & dataTag,
size_t dataSize,
52 std::vector< std::string >
const & names = std::vector< std::string >(N,
""));
56 std::vector< std::string >
const & names = std::vector< std::string >(N,
""))
57 {
return initOutputs<T>(dataTag.
encode(), dataSize, names); }
59 void setVector(FVector_ID
id,
size_t key, std::array<float, N>
const & values) { (*(
fVectors[id]))[key] = values; }
60 void setVector(FVector_ID
id,
size_t key, std::array<double, N>
const & values) { (*(
fVectors[id]))[key] = values; }
61 void setVector(FVector_ID
id,
size_t key, std::vector<float>
const & values) { (*(
fVectors[id]))[key] = values; }
62 void setVector(FVector_ID
id,
size_t key, std::vector<double>
const & values) { (*(
fVectors[id]))[key] = values; }
71 std::vector< std::string >
const & names = std::vector< std::string >(N,
""))
72 {
return initOutputs<T>(dataTag.
encode(), 0, names); }
76 std::vector< std::string >
const & names = std::vector< std::string >(N,
""))
77 {
return initOutputs<T>(std::string(
""), 0, names); }
79 void addVector(FVector_ID
id, std::array<float, N>
const & values) {
fVectors[id]->emplace_back(values); }
80 void addVector(FVector_ID
id, std::array<double, N>
const & values) {
fVectors[id]->emplace_back(values); }
81 void addVector(FVector_ID
id, std::vector<float>
const & values) {
fVectors[id]->emplace_back(values); }
82 void addVector(FVector_ID
id, std::vector<double>
const & values) {
fVectors[id]->emplace_back(values); }
100 std::array<float, N> vout;
101 auto const & src = ( *(
fVectors[getProductID<T>()]) )[key];
102 for (
size_t i = 0; i < N; ++i) vout[i] = src[i];
110 std::array<float, N> vout;
111 auto const & src = ( *(
fVectors[getProductID<T>()]) )[item.
key()];
112 for (
size_t i = 0; i < N; ++i) vout[i] = src[i];
118 o <<
"FVectorWriter for " << a.
fInstanceName <<
", " << N <<
" outputs";
121 o <<
", ready to write results made for:" << std::endl;
124 else { o <<
", nothing registered for writing to the events" << std::endl; }
132 std::vector< std::unique_ptr< std::vector< anab::FeatureVector<N> > > >
fVectors;
147 fTypeHashToID.clear(); fVectors.clear();
148 fDescriptions.reset(
nullptr);
199 std::vector<float>
const & weights)
const 208 std::function<
float (T
const &)> fweight)
const 213 std::function<
float (
art::Ptr<T> const &)> fweight)
const 235 auto const & ti =
typeid(T);
237 if (search !=
fTypeHashToID.end()) {
return search->second; }
250 if (
s == dname) {
return true; }
263 throw cet::exception(
"FVectorWriter") <<
"Type " << dataName <<
"was already registered." << std::endl;
285 if (
d.outputInstance() ==
n) {
return true; }
294 std::string
const & dataTag,
size_t dataSize,
295 std::vector< std::string >
const & names)
302 throw cet::exception(
"FVectorWriter") <<
"Type " << dataName <<
"not registered with produces_using() function." << std::endl;
307 fDescriptions = std::make_unique< std::vector< anab::FVecDescription<N> > >();
311 throw cet::exception(
"FVectorWriter") <<
"FVecDescription<N> already initialized for " << dataName << std::endl;
332 throw cet::exception(
"FVectorWriter") <<
"No FVecDescription<N> prepared for type " <<
n << std::endl;
338 throw cet::exception(
"FVectorWriter") <<
"FVecDescription<N> vector length not equal to the number of FeatureVector<N> vectors" << std::endl;
341 for (
size_t i = 0; i <
fVectors.size(); ++i)
343 auto const & outInstName = (*fDescriptions)[i].outputInstance();
346 throw cet::exception(
"FVectorWriter") <<
"FVecDescription<N> reco data tag not set for " << outInstName << std::endl;
355 #endif //ANAB_MVAREADER void addVector(FVector_ID id, std::vector< float > const &values)
void setOutput(FVector_ID id, size_t key, std::array< double, N > const &values)
std::array< float, N > getVector(art::Ptr< T > const &item) const
Get copy of the feature vector for the type T, idicated with art::Ptr::key().
std::unordered_map< size_t, FVector_ID > fTypeHashToID
size_t length() const
Get the length of a single feature vector.
void setVector(FVector_ID id, size_t key, std::vector< double > const &values)
std::array< float, N > getOutput(std::vector< art::Ptr< T > > const &items, std::function< float(art::Ptr< T > const &)> fweight) const
void setOutput(FVector_ID id, size_t key, std::array< float, N > const &values)
size_t size(FVector_ID id) const
Get the number of contained feature vectors.
std::array< float, N > getOutput(std::vector< art::Ptr< T > > const &items, std::vector< float > const &weights) const
void setVector(FVector_ID id, size_t key, std::array< double, N > const &values)
void setOutput(FVector_ID id, size_t key, std::vector< double > const &values)
bool descriptionExists(const std::string &tname) const
Check if the containers for results prepared for "tname" data type are ready.
size_t FVector_ID
Index to the MVA output / FeatureVector collection, used when result vectors are added or set...
std::string getProductName(std::type_info const &ti) const
FVector_ID initOutputs(std::vector< std::string > const &names=std::vector< std::string >(N,""))
void addVector(FVector_ID id, std::array< float, N > const &values)
void addVector(FVector_ID id, std::vector< double > const &values)
std::array< float, N > getVector(size_t key) const
Get copy of the feature vector for the type T, at index "key".
FVector_ID initOutputs(art::InputTag const &dataTag, size_t dataSize, std::vector< std::string > const &names=std::vector< std::string >(N,""))
ProductID put(std::unique_ptr< PROD > &&product)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
FVector_ID initOutputs(std::string const &dataTag, size_t dataSize, std::vector< std::string > const &names=std::vector< std::string >(N,""))
Helper functions for MVAReader and MVAWriter wrappers.
MVAWriter(art::EDProducer *module, const char *name="")
void addOutput(FVector_ID id, std::array< double, N > const &values)
std::array< float, N > getOutput(art::Ptr< T > const &item) const
Get copy of the MVA output vector for the type T, idicated with art::Ptr::key().
void addOutput(FVector_ID id, std::vector< double > const &values)
std::unique_ptr< std::vector< anab::FVecDescription< N > > > fDescriptions
FVectorWriter(art::EDProducer *module, const char *name="")
std::array< float, N > getOutput(std::vector< art::Ptr< T > > const &items) const
art::EDProducer * fProducer
void saveOutputs(art::Event &evt)
Check consistency and save all the results in the event.
std::array< float, N > getOutput(std::vector< art::Ptr< T > > const &items, std::function< float(T const &)> fweight) const
void addOutput(FVector_ID id, std::array< float, N > const &values)
Helper functions for MVAReader/Writer and FVecReader/Writer wrappers.
FVector_ID getProductID() const
std::vector< std::string > fRegisteredDataTypes
bool fIsDescriptionRegistered
FVector_ID initOutputs(art::InputTag const &dataTag, std::vector< std::string > const &names=std::vector< std::string >(N,""))
void setVector(FVector_ID id, size_t key, std::array< float, N > const &values)
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
void setOutput(FVector_ID id, size_t key, std::vector< float > const &values)
bool dataTypeRegistered(const std::string &dname) const
Check if the the writer is configured to write results for data product type name.
void setDataTag(FVector_ID id, art::InputTag const &dataTag)
Set tag of associated data products in case it was not ready at the initialization time...
std::string fInstanceName
std::array< float, N > getOutput(size_t key) const
Get copy of the MVA output vector for the type T, at index "key".
void setVector(FVector_ID id, size_t key, std::vector< float > const &values)
size_t getProductHash(std::type_info const &ti) const
void addOutput(FVector_ID id, std::vector< float > const &values)
void addVector(FVector_ID id, std::array< double, N > const &values)
cet::coded_exception< error, detail::translate > exception
friend std::ostream & operator<<(std::ostream &o, FVectorWriter const &a)