9 #ifndef ANAB_MVAWRITER_H 10 #define ANAB_MVAWRITER_H 52 std::vector<std::string>
const& names = std::vector<std::string>(N,
""));
57 std::vector<std::string>
const& names = std::vector<std::string>(N,
""))
59 return initOutputs<T>(dataTag.
encode(), dataSize, names);
85 std::vector<std::string>
const& names = std::vector<std::string>(N,
""))
87 return initOutputs<T>(dataTag.
encode(), 0, names);
91 FVector_ID
initOutputs(std::vector<std::string>
const& names = std::vector<std::string>(N,
""))
93 return initOutputs<T>(std::string(
""), 0, names);
116 (*fDescriptions)[id].setDataTag(dataTag.
encode());
132 std::array<float, N> vout;
133 auto const& src = (*(
fVectors[getProductID<T>()]))[key];
134 for (
size_t i = 0; i < N; ++i)
143 std::array<float, N> vout;
144 auto const& src = (*(
fVectors[getProductID<T>()]))[item.
key()];
145 for (
size_t i = 0; i < N; ++i)
152 o <<
"FVectorWriter for " << a.
fInstanceName <<
", " << N <<
" outputs";
154 o <<
", ready to write results made for:" << std::endl;
156 o <<
"\t" <<
n << std::endl;
160 o <<
", nothing registered for writing to the events" << std::endl;
170 std::vector<std::unique_ptr<std::vector<anab::FeatureVector<N>>>>
fVectors;
185 fTypeHashToID.clear();
187 fDescriptions.reset(
nullptr);
253 return pAccumulate<T, N>(
263 std::vector<float>
const& weights)
const 265 return pAccumulate<T, N>(
277 std::function<
float(T
const&)> fweight)
const 279 return pAccumulate<T, N>(
287 std::function<
float(
art::Ptr<T> const&)> fweight)
const 289 return pAccumulate<T, N>(
319 auto const& ti =
typeid(T);
321 if (search !=
fTypeHashToID.end()) {
return search->second; }
324 <<
"Feature vectors not initialized for product " <<
getProductName(ti) << std::endl;
333 if (s == dname) {
return true; }
346 <<
"Type " << dataName <<
"was already registered." << std::endl;
366 if (
d.outputInstance() ==
n) {
return true; }
376 std::vector<std::string>
const& names)
383 <<
"Type " << dataName <<
"not registered with produces_using() function." << std::endl;
389 <<
"FVecDescription<N> already initialized for " << dataName << std::endl;
409 <<
"No FVecDescription<N> prepared for type " <<
n << std::endl;
415 <<
"FVecDescription<N> vector length not equal to the number of FeatureVector<N> vectors" 419 for (
size_t i = 0; i <
fVectors.size(); ++i) {
420 auto const& outInstName = (*fDescriptions)[i].outputInstance();
423 <<
"FVecDescription<N> reco data tag not set for " << outInstName << std::endl;
432 #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 > getOutput(std::vector< art::Ptr< T >> const &items, std::vector< float > const &weights) const
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().
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)
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::function< float(T const &)> fweight) 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)
MVAWriter(art::ProducesCollector &collector, const char *name="")
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,""))
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
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,""))
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
Helper functions for MVAReader and MVAWriter wrappers.
art::ProducesCollector & fCollector
void addOutput(FVector_ID id, std::array< double, N > const &values)
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
std::array< float, N > getOutput(std::vector< art::Ptr< T >> const &items) const
key_type key() const noexcept
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::array< float, N > getOutput(std::vector< art::Ptr< T >> const &items, std::function< float(art::Ptr< T > const &)> fweight) const
void saveOutputs(art::Event &evt)
Check consistency and save all the results in the event.
std::vector< std::string > fRegisteredDataTypes
void addOutput(FVector_ID id, std::array< float, N > const &values)
std::unordered_map< size_t, FVector_ID > fTypeHashToID
Helper functions for MVAReader/Writer and FVecReader/Writer wrappers.
FVector_ID getProductID() const
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)
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".
std::unique_ptr< std::vector< anab::FVecDescription< N > > > fDescriptions
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)
FVectorWriter(art::ProducesCollector &collector, const char *name="")
void addVector(FVector_ID id, std::array< double, N > const &values)
cet::coded_exception< error, detail::translate > exception
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
friend std::ostream & operator<<(std::ostream &o, FVectorWriter const &a)