9 #ifndef ANAB_MVAWRITER_H 10 #define ANAB_MVAWRITER_H 51 std::vector< std::string >
const &
names = std::vector< std::string >(
N,
""));
55 std::vector< std::string >
const &
names = std::vector< std::string >(
N,
""))
56 {
return initOutputs<T>(dataTag.
encode(), dataSize,
names); }
70 std::vector< std::string >
const &
names = std::vector< std::string >(
N,
""))
71 {
return initOutputs<T>(dataTag.
encode(), 0,
names); }
75 std::vector< std::string >
const &
names = std::vector< std::string >(
N,
""))
99 std::array<float, N> vout;
100 auto const & src = ( *(
fVectors[getProductID<T>()]) )[key];
101 for (
size_t i = 0; i <
N; ++i) vout[i] = src[i];
109 std::array<float, N> vout;
110 auto const & src = ( *(
fVectors[getProductID<T>()]) )[item.
key()];
111 for (
size_t i = 0; i <
N; ++i) vout[i] = src[i];
117 o <<
"FVectorWriter for " << a.
fInstanceName <<
", " <<
N <<
" outputs";
120 o <<
", ready to write results made for:" <<
std::endl;
123 else { o <<
", nothing registered for writing to the events" <<
std::endl; }
131 std::vector< std::unique_ptr< std::vector< anab::FeatureVector<N> > > >
fVectors;
146 fTypeHashToID.clear(); fVectors.clear();
147 fDescriptions.reset(
nullptr);
198 std::vector<float>
const & weights)
const 234 auto const & ti =
typeid(
T);
249 if (
s == dname) {
return true; }
284 if (
d.outputInstance() ==
n) {
return true; }
294 std::vector< std::string >
const &
names)
301 throw cet::exception(
"FVectorWriter") <<
"Type " << dataName <<
"not registered with produces_using() function." <<
std::endl;
306 fDescriptions = std::make_unique< std::vector< anab::FVecDescription<N> > >();
310 throw cet::exception(
"FVectorWriter") <<
"FVecDescription<N> already initialized for " << dataName <<
std::endl;
337 throw cet::exception(
"FVectorWriter") <<
"FVecDescription<N> vector length not equal to the number of FeatureVector<N> vectors" <<
std::endl;
340 for (
size_t i = 0; i <
fVectors.size(); ++i)
342 auto const & outInstName = (*fDescriptions)[i].outputInstance();
345 throw cet::exception(
"FVectorWriter") <<
"FVecDescription<N> reco data tag not set for " << outInstName <<
std::endl;
354 #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)
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,""))
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)
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().
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
void addOutput(FVector_ID id, std::vector< double > const &values)
std::unique_ptr< std::vector< anab::FVecDescription< N > > > fDescriptions
std::array< float, N > getOutput(std::vector< art::Ptr< T > > const &items) const
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
static std::vector< std::string > const names
void addOutput(FVector_ID id, std::vector< float > const &values)
void function(int client, int *resource, int parblock, int *test, int p)
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.
QTextStream & endl(QTextStream &s)
friend std::ostream & operator<<(std::ostream &o, FVectorWriter const &a)