Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
anab::FVectorReader< T, N > Class Template Reference

#include <MVAReader.h>

Inheritance diagram for anab::FVectorReader< T, N >:
anab::FVectorWrapperBase anab::MVAReader< T, N >

Public Member Functions

 FVectorReader (const art::Event &evt, const art::InputTag &tag)
 
T const & item (size_t key) const
 Access data product at index "key". More...
 
std::vector< T > const & items () const
 
std::vector< FeatureVector< N > > const & vectors () const
 Access the vector of the feature vectors. More...
 
std::array< float, N > getVector (size_t key) const
 Get copy of the feature vector at index "key". More...
 
std::array< float, N > getVector (art::Ptr< T > const &item) const
 Get copy of the feature vector idicated with art::Ptr::key(). More...
 
size_t size () const
 Get the number of contained items (no. of data product objects equal to no. of feature vectors). More...
 
size_t length () const
 Get the length of a single feature vector. More...
 
const std::stringdataTag () const
 Get the input tag (string representation) of data product used to calculate feature vectors. More...
 
const art::Handle< std::vector< T > > & dataHandle () const
 Access the data product handle. More...
 
const std::stringcolumnName (size_t index) const
 Meaning/name of the index'th column in the collection of feature vectors. More...
 
int getIndex (const std::string &name) const
 Index of column with given name, or -1 if name not found. More...
 

Static Public Member Functions

static std::unique_ptr< FVectorReadercreate (const art::Event &evt, const art::InputTag &tag)
 

Protected Member Functions

 FVectorReader (const art::Event &evt, const art::InputTag &tag, bool &success)
 Not-throwing constructor. More...
 
- Protected Member Functions inherited from anab::FVectorWrapperBase
std::string getProductName (std::type_info const &ti) const
 
size_t getProductHash (std::type_info const &ti) const
 

Private Attributes

FVecDescription< N > const * fDescription
 
std::vector< FeatureVector< N > > const * fVectors
 
art::Handle< std::vector< T > > fDataHandle
 

Friends

std::ostream & operator<< (std::ostream &o, FVectorReader const &a)
 

Detailed Description

template<class T, size_t N>
class anab::FVectorReader< T, N >

Helper for reading the reconstructed objects of type T together with associated N-ellement feature vectors with their metadata (this class is not a data product).

Definition at line 23 of file MVAReader.h.

Constructor & Destructor Documentation

template<class T , size_t N>
anab::FVectorReader< T, N >::FVectorReader ( const art::Event evt,
const art::InputTag tag 
)

Create the wrapper for feature vectors stored in the event evt with the provided input tag (the same tag which was used to save vectors with FVectorWriter class). Throws exception if data products not found in the event.

Definition at line 170 of file MVAReader.h.

170  :
171  fDescription(0)
172 {
173  if (!N) { throw cet::exception("FVectorReader") << "Vector size should be > 0." << std::endl; }
174 
175  auto descriptionHandle = evt.getValidHandle< std::vector< anab::FVecDescription<N> > >(tag);
176 
177  // search for FVecDescription<N> produced for the type T, with the instance name from the tag
178  std::string outputInstanceName = tag.instance() + getProductName(typeid(T));
179  for (auto const & dscr : *descriptionHandle)
180  {
181  if (dscr.outputInstance() == outputInstanceName)
182  {
183  fDescription = &dscr; break;
184  }
185  }
186  if (!fDescription) { throw cet::exception("FVectorReader") << "Vectors description not found for " << outputInstanceName << std::endl; }
187 
188  fVectors = &*(evt.getValidHandle< std::vector< FeatureVector<N> > >( art::InputTag(tag.label(), fDescription->outputInstance(), tag.process()) ));
189 
190  if (!evt.getByLabel( fDescription->dataTag(), fDataHandle ))
191  {
192  throw cet::exception("FVectorReader") << "Associated data product handle failed: " << *(fDataHandle.whyFailed()) << std::endl;
193  }
194 
195  if (fVectors->size() != fDataHandle->size())
196  {
197  throw cet::exception("FVectorReader") << "Feature vectors and data products sizes inconsistent: " << fVectors->size() << "!=" << fDataHandle->size() << std::endl;
198  }
199 }
art::Handle< std::vector< T > > fDataHandle
Definition: MVAReader.h:97
std::string string
Definition: nybbler.cc:12
std::string const & instance() const noexcept
Definition: InputTag.cc:85
std::string const & process() const noexcept
Definition: InputTag.cc:91
std::string getProductName(std::type_info const &ti) const
FVecDescription< N > const * fDescription
Definition: MVAReader.h:95
std::vector< FeatureVector< N > > const * fVectors
Definition: MVAReader.h:96
std::string const & label() const noexcept
Definition: InputTag.cc:79
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
std::shared_ptr< art::Exception const > whyFailed() const
Definition: Handle.h:219
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
template<class T , size_t N>
anab::FVectorReader< T, N >::FVectorReader ( const art::Event evt,
const art::InputTag tag,
bool success 
)
protected

Not-throwing constructor.

Definition at line 203 of file MVAReader.h.

203  :
204  fDescription(0)
205 {
206  success = false; // until all is done correctly
207 
208  if (!N) { std::cout << "FVectorReader: Vector size should be > 0." << std::endl; return; }
209 
211  if (!evt.getByLabel( tag, descriptionHandle )) { return; }
212 
213  // search for FVecDescription<N> produced for the type T, with the instance name from the tag
214  std::string outputInstanceName = tag.instance() + getProductName(typeid(T));
215  for (auto const & dscr : *descriptionHandle)
216  {
217  if (dscr.outputInstance() == outputInstanceName)
218  {
219  fDescription = &dscr; break;
220  }
221  }
222  if (!fDescription) { std::cout << "FVectorReader: Vectors description not found for " << outputInstanceName << std::endl; return; }
223 
224  fVectors = &*(evt.getValidHandle< std::vector< FeatureVector<N> > >( art::InputTag(tag.label(), fDescription->outputInstance(), tag.process()) ));
225 
226  if (!evt.getByLabel( fDescription->dataTag(), fDataHandle ))
227  {
228  std::cout << "FVectorReader: Associated data product handle failed: " << *(fDataHandle.whyFailed()) << std::endl; return;
229  }
230 
231  if (fVectors->size() != fDataHandle->size())
232  {
233  std::cout << "FVectorReader: Feature vectors and data products sizes inconsistent: " << fVectors->size() << "!=" << fDataHandle->size() << std::endl; return;
234  }
235 
236  success = true; // ok, all data found in the event
237 }
art::Handle< std::vector< T > > fDataHandle
Definition: MVAReader.h:97
std::string string
Definition: nybbler.cc:12
std::string const & instance() const noexcept
Definition: InputTag.cc:85
std::string const & process() const noexcept
Definition: InputTag.cc:91
std::string getProductName(std::type_info const &ti) const
FVecDescription< N > const * fDescription
Definition: MVAReader.h:95
std::vector< FeatureVector< N > > const * fVectors
Definition: MVAReader.h:96
std::string const & label() const noexcept
Definition: InputTag.cc:79
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
std::shared_ptr< art::Exception const > whyFailed() const
Definition: Handle.h:219
QTextStream & endl(QTextStream &s)

Member Function Documentation

template<class T , size_t N>
const std::string& anab::FVectorReader< T, N >::columnName ( size_t  index) const
inline

Meaning/name of the index'th column in the collection of feature vectors.

Definition at line 79 of file MVAReader.h.

79 { return fDescription->outputName(index); }
FVecDescription< N > const * fDescription
Definition: MVAReader.h:95
template<class T , size_t N>
static std::unique_ptr<FVectorReader> anab::FVectorReader< T, N >::create ( const art::Event evt,
const art::InputTag tag 
)
inlinestatic

Create the helper for feature vectors stored in the event evt with the provided input tag (the same tag which was used to save vectors with FVectorWriter class). Returns nullptr if data products not found in the event.

Definition at line 29 of file MVAReader.h.

30  {
31  bool success;
32  std::unique_ptr<FVectorReader> ptr(new FVectorReader(evt, tag, success));
33  if (success) { return ptr; }
34  else { return nullptr; }
35  }
FVectorReader(const art::Event &evt, const art::InputTag &tag)
Definition: MVAReader.h:170
template<class T , size_t N>
const art::Handle< std::vector<T> >& anab::FVectorReader< T, N >::dataHandle ( ) const
inline

Access the data product handle.

Definition at line 76 of file MVAReader.h.

76 { return fDataHandle; }
art::Handle< std::vector< T > > fDataHandle
Definition: MVAReader.h:97
template<class T , size_t N>
const std::string& anab::FVectorReader< T, N >::dataTag ( ) const
inline

Get the input tag (string representation) of data product used to calculate feature vectors.

Definition at line 73 of file MVAReader.h.

73 { return fDescription->dataTag(); }
FVecDescription< N > const * fDescription
Definition: MVAReader.h:95
template<class T , size_t N>
int anab::FVectorReader< T, N >::getIndex ( const std::string name) const
inline

Index of column with given name, or -1 if name not found.

Definition at line 82 of file MVAReader.h.

82 { return fDescription->getIndex(name); }
static QCString name
Definition: declinfo.cpp:673
FVecDescription< N > const * fDescription
Definition: MVAReader.h:95
template<class T , size_t N>
std::array<float, N> anab::FVectorReader< T, N >::getVector ( size_t  key) const
inline

Get copy of the feature vector at index "key".

Access feature vector data at index "key". *** WOULD LIKE TO CHANGE TYPE OF FVEC DATA MEMBER TO std::array AND THEN ENABLE THIS FUNCTION ***

Definition at line 54 of file MVAReader.h.

55  {
56  std::array<float, N> vout;
57  for (size_t i = 0; i < N; ++i) vout[i] = (*fVectors)[key][i];
58  return vout;
59  }
std::vector< FeatureVector< N > > const * fVectors
Definition: MVAReader.h:96
def key(type, name=None)
Definition: graph.py:13
template<class T , size_t N>
std::array<float, N> anab::FVectorReader< T, N >::getVector ( art::Ptr< T > const &  item) const
inline

Get copy of the feature vector idicated with art::Ptr::key().

Definition at line 62 of file MVAReader.h.

63  { return getVector(item.key()); }
std::array< float, N > getVector(size_t key) const
Get copy of the feature vector at index "key".
Definition: MVAReader.h:54
key_type key() const noexcept
Definition: Ptr.h:216
template<class T , size_t N>
T const& anab::FVectorReader< T, N >::item ( size_t  key) const
inline

Access data product at index "key".

Definition at line 43 of file MVAReader.h.

43 { return (*fDataHandle)[key]; }
art::Handle< std::vector< T > > fDataHandle
Definition: MVAReader.h:97
def key(type, name=None)
Definition: graph.py:13
template<class T , size_t N>
std::vector<T> const& anab::FVectorReader< T, N >::items ( ) const
inline

Definition at line 44 of file MVAReader.h.

44 { return *fDataHandle; }
art::Handle< std::vector< T > > fDataHandle
Definition: MVAReader.h:97
template<class T , size_t N>
size_t anab::FVectorReader< T, N >::length ( ) const
inline

Get the length of a single feature vector.

Definition at line 70 of file MVAReader.h.

template<class T , size_t N>
size_t anab::FVectorReader< T, N >::size ( void  ) const
inline

Get the number of contained items (no. of data product objects equal to no. of feature vectors).

Definition at line 67 of file MVAReader.h.

67 { return fVectors->size(); }
std::vector< FeatureVector< N > > const * fVectors
Definition: MVAReader.h:96
template<class T , size_t N>
std::vector< FeatureVector<N> > const& anab::FVectorReader< T, N >::vectors ( ) const
inline

Access the vector of the feature vectors.

Definition at line 47 of file MVAReader.h.

47 { return *fVectors; }
std::vector< FeatureVector< N > > const * fVectors
Definition: MVAReader.h:96

Friends And Related Function Documentation

template<class T , size_t N>
std::ostream& operator<< ( std::ostream &  o,
FVectorReader< T, N > const &  a 
)
friend

Definition at line 84 of file MVAReader.h.

85  {
86  o << "FVectorReader:" << std::endl << *(a.fDescription) << std::endl;
87  return o;
88  }
const double a
QTextStream & endl(QTextStream &s)

Member Data Documentation

template<class T , size_t N>
art::Handle< std::vector<T> > anab::FVectorReader< T, N >::fDataHandle
private

Definition at line 97 of file MVAReader.h.

template<class T , size_t N>
FVecDescription<N> const* anab::FVectorReader< T, N >::fDescription
private

Definition at line 95 of file MVAReader.h.

template<class T , size_t N>
std::vector< FeatureVector<N> > const* anab::FVectorReader< T, N >::fVectors
private

Definition at line 96 of file MVAReader.h.


The documentation for this class was generated from the following file: