All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
anab::FVectorWriter< N > Class Template Reference

#include <MVAWriter.h>

Inheritance diagram for anab::FVectorWriter< N >:
anab::FVectorWrapperBase anab::MVAWriter< N >

Public Member Functions

 FVectorWriter (art::ProducesCollector &collector, const char *name="")
 
template<class T >
void produces_using ()
 
template<class T >
FVector_ID initOutputs (std::string const &dataTag, size_t dataSize, std::vector< std::string > const &names=std::vector< std::string >(N,""))
 
template<class T >
FVector_ID initOutputs (art::InputTag const &dataTag, size_t dataSize, 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 setVector (FVector_ID id, size_t key, std::array< double, N > const &values)
 
void setVector (FVector_ID id, size_t key, std::vector< float > const &values)
 
void setVector (FVector_ID id, size_t key, std::vector< double > const &values)
 
template<class T >
FVector_ID initOutputs (art::InputTag const &dataTag, std::vector< std::string > const &names=std::vector< std::string >(N,""))
 
template<class T >
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::array< double, N > const &values)
 
void addVector (FVector_ID id, std::vector< float > const &values)
 
void addVector (FVector_ID id, std::vector< double > const &values)
 
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. More...
 
void saveOutputs (art::Event &evt)
 Check consistency and save all the results in the event. More...
 
size_t size (FVector_ID id) const
 Get the number of contained feature vectors. More...
 
size_t length () const
 Get the length of a single feature vector. More...
 
template<class T >
std::array< float, NgetVector (size_t key) const
 Get copy of the feature vector for the type T, at index "key". More...
 
template<class T >
std::array< float, NgetVector (art::Ptr< T > const &item) const
 Get copy of the feature vector for the type T, idicated with art::Ptr::key(). More...
 
template<class T >
anab::FVector_ID getProductID () const
 
template<class T >
anab::FVector_ID initOutputs (std::string const &dataTag, size_t dataSize, std::vector< std::string > const &names)
 

Protected Member Functions

template<class T >
FVector_ID getProductID () const
 
- 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
 

Protected Attributes

std::vector< std::unique_ptr
< std::vector
< anab::FeatureVector< N > > > > 
fVectors
 

Private Member Functions

void clearEventData ()
 
bool dataTypeRegistered (const std::string &dname) const
 Check if the the writer is configured to write results for data product type name. More...
 
bool descriptionExists (const std::string &tname) const
 Check if the containers for results prepared for "tname" data type are ready. More...
 

Private Attributes

art::ProducesCollector & fCollector
 
std::string fInstanceName
 
std::vector< std::string > fRegisteredDataTypes
 
bool fIsDescriptionRegistered
 
std::unordered_map< size_t,
FVector_ID
fTypeHashToID
 
std::unique_ptr< std::vector
< anab::FVecDescription< N > > > 
fDescriptions
 

Friends

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

Detailed Description

template<size_t N>
class anab::FVectorWriter< N >

Definition at line 25 of file MVAWriter.h.

Constructor & Destructor Documentation

template<size_t N>
anab::FVectorWriter< N >::FVectorWriter ( art::ProducesCollector &  collector,
const char *  name = "" 
)
inline

Name provided to the constructor is used as an instance name for FVecDescription<N> and FeatureVector<N> (for which it is combined with the processed data product names). The name is used as an instance name for the FVecDescription data product which lets you to save multiple vector collections from a single art module.

Definition at line 32 of file MVAWriter.h.

32  :
33  fCollector(collector), fInstanceName(name),
35  fDescriptions(nullptr)
36  { }
art::ProducesCollector & fCollector
Definition: MVAWriter.h:135
std::unique_ptr< std::vector< anab::FVecDescription< N > > > fDescriptions
Definition: MVAWriter.h:143
bool fIsDescriptionRegistered
Definition: MVAWriter.h:139
std::string fInstanceName
Definition: MVAWriter.h:136
then echo fcl name

Member Function Documentation

template<size_t N>
void anab::FVectorWriter< N >::addVector ( FVector_ID  id,
std::array< float, N > const &  values 
)
inline

Definition at line 78 of file MVAWriter.h.

78 { fVectors[id]->emplace_back(values); }
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
void anab::FVectorWriter< N >::addVector ( FVector_ID  id,
std::array< double, N > const &  values 
)
inline

Definition at line 79 of file MVAWriter.h.

79 { fVectors[id]->emplace_back(values); }
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
void anab::FVectorWriter< N >::addVector ( FVector_ID  id,
std::vector< float > const &  values 
)
inline

Definition at line 80 of file MVAWriter.h.

80 { fVectors[id]->emplace_back(values); }
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
void anab::FVectorWriter< N >::addVector ( FVector_ID  id,
std::vector< double > const &  values 
)
inline

Definition at line 81 of file MVAWriter.h.

81 { fVectors[id]->emplace_back(values); }
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
void anab::FVectorWriter< N >::clearEventData ( )
inlineprivate

Definition at line 144 of file MVAWriter.h.

145  {
146  fTypeHashToID.clear(); fVectors.clear();
147  fDescriptions.reset(nullptr);
148  }
std::unordered_map< size_t, FVector_ID > fTypeHashToID
Definition: MVAWriter.h:141
std::unique_ptr< std::vector< anab::FVecDescription< N > > > fDescriptions
Definition: MVAWriter.h:143
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
bool anab::FVectorWriter< N >::dataTypeRegistered ( const std::string &  dname) const
private

Check if the the writer is configured to write results for data product type name.

Definition at line 245 of file MVAWriter.h.

246 {
247  for (auto const & s : fRegisteredDataTypes)
248  {
249  if (s == dname) { return true; }
250  }
251  return false;
252 }
std::vector< std::string > fRegisteredDataTypes
Definition: MVAWriter.h:138
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
template<size_t N>
bool anab::FVectorWriter< N >::descriptionExists ( const std::string &  tname) const
private

Check if the containers for results prepared for "tname" data type are ready.

Definition at line 277 of file MVAWriter.h.

278 {
279  if (!fDescriptions) return false;
280 
281  std::string n = fInstanceName + tname;
282  for (auto const & d : *fDescriptions)
283  {
284  if (d.outputInstance() == n) { return true; }
285  }
286  return false;
287 }
std::unique_ptr< std::vector< anab::FVecDescription< N > > > fDescriptions
Definition: MVAWriter.h:143
string tname
Definition: names.py:3
std::string fInstanceName
Definition: MVAWriter.h:136
template<size_t N>
template<class T >
FVector_ID anab::FVectorWriter< N >::getProductID ( ) const
protected
template<size_t N>
template<class T >
anab::FVector_ID anab::FVectorWriter< N >::getProductID ( ) const

Definition at line 232 of file MVAWriter.h.

233 {
234  auto const & ti = typeid(T);
235  auto search = fTypeHashToID.find(getProductHash(ti));
236  if (search != fTypeHashToID.end()) { return search->second; }
237  else
238  {
239  throw cet::exception("FVectorWriter") << "Feature vectors not initialized for product " << getProductName(ti) << std::endl;
240  }
241 }
std::unordered_map< size_t, FVector_ID > fTypeHashToID
Definition: MVAWriter.h:141
std::string getProductName(std::type_info const &ti) const
size_t getProductHash(std::type_info const &ti) const
template<size_t N>
template<class T >
std::array<float, N> anab::FVectorWriter< N >::getVector ( size_t  key) const
inline

Get copy of the feature vector for the type T, at index "key".

Definition at line 97 of file MVAWriter.h.

98  {
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];
102  return vout;
103  }
process_name largeant stream1 can override from command line with o or output physics producers generator N
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
template<class T >
std::array<float, N> anab::FVectorWriter< N >::getVector ( art::Ptr< T > const &  item) const
inline

Get copy of the feature vector for the type T, idicated with art::Ptr::key().

Definition at line 107 of file MVAWriter.h.

108  {
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];
112  return vout;
113  }
process_name largeant stream1 can override from command line with o or output physics producers generator N
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
template<class T >
FVector_ID anab::FVectorWriter< N >::initOutputs ( std::string const &  dataTag,
size_t  dataSize,
std::vector< std::string > const &  names = std::vector< std::string >(N,"") 
)

Initialize container for FeatureVectors and, if not yet done, the container for metadata, then creates metadata for data products of type T. FeatureVector container is initialized to hold dataSize vectors (if dataSize > 0): use setOutput() to store values. Returns index of collection which should be used when saving actual output values.

template<size_t N>
template<class T >
FVector_ID anab::FVectorWriter< N >::initOutputs ( art::InputTag const &  dataTag,
size_t  dataSize,
std::vector< std::string > const &  names = std::vector< std::string >(N, "") 
)
inline

Definition at line 54 of file MVAWriter.h.

56  { return initOutputs<T>(dataTag.encode(), dataSize, names); }
static const std::vector< std::string > names
template<size_t N>
template<class T >
FVector_ID anab::FVectorWriter< N >::initOutputs ( art::InputTag const &  dataTag,
std::vector< std::string > const &  names = std::vector< std::string >(N, "") 
)
inline

Initialize container for FeatureVectors and, if not yet done, the container for metadata, then creates metadata for data products of type T. FeatureVector container is initialized as EMPTY and vectors should be added with addOutput() function. Returns index of collection which should be used when adding actual output values.

Definition at line 69 of file MVAWriter.h.

71  { return initOutputs<T>(dataTag.encode(), 0, names); }
static const std::vector< std::string > names
template<size_t N>
template<class T >
FVector_ID anab::FVectorWriter< N >::initOutputs ( std::vector< std::string > const &  names = std::vector< std::string >(N, ""))
inline

Definition at line 74 of file MVAWriter.h.

76  { return initOutputs<T>(std::string(""), 0, names); }
static const std::vector< std::string > names
template<size_t N>
template<class T >
anab::FVector_ID anab::FVectorWriter< N >::initOutputs ( std::string const &  dataTag,
size_t  dataSize,
std::vector< std::string > const &  names 
)

Definition at line 292 of file MVAWriter.h.

295 {
296  size_t dataHash = getProductHash(typeid(T));
297  std::string dataName = getProductName(typeid(T));
298 
299  if (!dataTypeRegistered(dataName))
300  {
301  throw cet::exception("FVectorWriter") << "Type " << dataName << "not registered with produces_using() function." << std::endl;
302  }
303 
304  if (!fDescriptions)
305  {
306  fDescriptions = std::make_unique< std::vector< anab::FVecDescription<N> > >();
307  }
308  else if (descriptionExists(dataName))
309  {
310  throw cet::exception("FVectorWriter") << "FVecDescription<N> already initialized for " << dataName << std::endl;
311  }
312  fDescriptions->emplace_back(dataTag, fInstanceName + dataName, names);
313 
314  fVectors.push_back( std::make_unique< std::vector< anab::FeatureVector<N> > >() );
315  anab::FVector_ID id = fVectors.size() - 1;
316  fTypeHashToID[dataHash] = id;
317 
318  if (dataSize) { fVectors[id]->resize(dataSize, anab::FeatureVector<N>(0.0F)); }
319 
320  return id;
321 }
std::unordered_map< size_t, FVector_ID > fTypeHashToID
Definition: MVAWriter.h:141
bool descriptionExists(const std::string &tname) const
Check if the containers for results prepared for &quot;tname&quot; data type are ready.
Definition: MVAWriter.h:277
size_t FVector_ID
Index to the MVA output / FeatureVector collection, used when result vectors are added or set...
Definition: MVAWriter.h:21
std::string getProductName(std::type_info const &ti) const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::unique_ptr< std::vector< anab::FVecDescription< N > > > fDescriptions
Definition: MVAWriter.h:143
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
bool dataTypeRegistered(const std::string &dname) const
Check if the the writer is configured to write results for data product type name.
Definition: MVAWriter.h:245
std::string fInstanceName
Definition: MVAWriter.h:136
size_t getProductHash(std::type_info const &ti) const
template<size_t N>
size_t anab::FVectorWriter< N >::length ( ) const
inline

Get the length of a single feature vector.

Definition at line 93 of file MVAWriter.h.

93 { return N; }
process_name largeant stream1 can override from command line with o or output physics producers generator N
template<size_t N>
template<class T >
void anab::FVectorWriter< N >::produces_using ( )

Register the collection of metadata type FVecDescription<N> (once for all data types for which vectors are saved) and the collection of FeatureVectors<N> (using data type name added to fInstanceName as instance name of the collection made for the type T).

Definition at line 257 of file MVAWriter.h.

258 {
259  std::string dataName = getProductName(typeid(T));
260  if (dataTypeRegistered(dataName))
261  {
262  throw cet::exception("FVectorWriter") << "Type " << dataName << "was already registered." << std::endl;
263  }
264 
266  {
267  fCollector.produces< std::vector< anab::FVecDescription<N> > >(fInstanceName);
269  }
270 
271  fCollector.produces< std::vector< anab::FeatureVector<N> > >(fInstanceName + dataName);
272  fRegisteredDataTypes.push_back(dataName);
273 }
std::string getProductName(std::type_info const &ti) const
art::ProducesCollector & fCollector
Definition: MVAWriter.h:135
std::vector< std::string > fRegisteredDataTypes
Definition: MVAWriter.h:138
bool fIsDescriptionRegistered
Definition: MVAWriter.h:139
bool dataTypeRegistered(const std::string &dname) const
Check if the the writer is configured to write results for data product type name.
Definition: MVAWriter.h:245
std::string fInstanceName
Definition: MVAWriter.h:136
template<size_t N>
void anab::FVectorWriter< N >::saveOutputs ( art::Event &  evt)

Check consistency and save all the results in the event.

Definition at line 325 of file MVAWriter.h.

326 {
327  for (auto const & n : fRegisteredDataTypes)
328  {
329  if (!descriptionExists(n))
330  {
331  throw cet::exception("FVectorWriter") << "No FVecDescription<N> prepared for type " << n << std::endl;
332  }
333  }
334 
335  if (fVectors.size() != fDescriptions->size())
336  {
337  throw cet::exception("FVectorWriter") << "FVecDescription<N> vector length not equal to the number of FeatureVector<N> vectors" << std::endl;
338  }
339 
340  for (size_t i = 0; i < fVectors.size(); ++i)
341  {
342  auto const & outInstName = (*fDescriptions)[i].outputInstance();
343  if ((*fDescriptions)[i].dataTag().empty())
344  {
345  throw cet::exception("FVectorWriter") << "FVecDescription<N> reco data tag not set for " << outInstName << std::endl;
346  }
347  evt.put(std::move(fVectors[i]), outInstName);
348  }
349  evt.put(std::move(fDescriptions), fInstanceName);
350  clearEventData();
351 }
bool descriptionExists(const std::string &tname) const
Check if the containers for results prepared for &quot;tname&quot; data type are ready.
Definition: MVAWriter.h:277
std::unique_ptr< std::vector< anab::FVecDescription< N > > > fDescriptions
Definition: MVAWriter.h:143
std::vector< std::string > fRegisteredDataTypes
Definition: MVAWriter.h:138
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
std::string fInstanceName
Definition: MVAWriter.h:136
TCEvent evt
Definition: DataStructs.cxx:8
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
template<size_t N>
void anab::FVectorWriter< N >::setDataTag ( FVector_ID  id,
art::InputTag const &  dataTag 
)
inline

Set tag of associated data products in case it was not ready at the initialization time.

Definition at line 84 of file MVAWriter.h.

84 { (*fDescriptions)[id].setDataTag(dataTag.encode()); }
template<size_t N>
void anab::FVectorWriter< N >::setVector ( FVector_ID  id,
size_t  key,
std::array< float, N > const &  values 
)
inline

Definition at line 58 of file MVAWriter.h.

58 { (*(fVectors[id]))[key] = values; }
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
void anab::FVectorWriter< N >::setVector ( FVector_ID  id,
size_t  key,
std::array< double, N > const &  values 
)
inline

Definition at line 59 of file MVAWriter.h.

59 { (*(fVectors[id]))[key] = values; }
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
void anab::FVectorWriter< N >::setVector ( FVector_ID  id,
size_t  key,
std::vector< float > const &  values 
)
inline

Definition at line 60 of file MVAWriter.h.

60 { (*(fVectors[id]))[key] = values; }
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
void anab::FVectorWriter< N >::setVector ( FVector_ID  id,
size_t  key,
std::vector< double > const &  values 
)
inline

Definition at line 61 of file MVAWriter.h.

61 { (*(fVectors[id]))[key] = values; }
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131
template<size_t N>
size_t anab::FVectorWriter< N >::size ( FVector_ID  id) const
inline

Get the number of contained feature vectors.

Definition at line 90 of file MVAWriter.h.

90 { return fVectors[id]->size(); }
std::vector< std::unique_ptr< std::vector< anab::FeatureVector< N > > > > fVectors
Definition: MVAWriter.h:131

Friends And Related Function Documentation

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

Definition at line 115 of file MVAWriter.h.

116  {
117  o << "FVectorWriter for " << a.fInstanceName << ", " << N << " outputs";
118  if (!a.fRegisteredDataTypes.empty())
119  {
120  o << ", ready to write results made for:" << std::endl;
121  for (auto const & n : a.fRegisteredDataTypes) { o << "\t" << n << std::endl; }
122  }
123  else { o << ", nothing registered for writing to the events" << std::endl; }
124  return o;
125  }
process_name gaushit a
process_name largeant stream1 can override from command line with o or output physics producers generator N

Member Data Documentation

template<size_t N>
art::ProducesCollector& anab::FVectorWriter< N >::fCollector
private

Definition at line 135 of file MVAWriter.h.

template<size_t N>
std::unique_ptr< std::vector< anab::FVecDescription<N> > > anab::FVectorWriter< N >::fDescriptions
private

Definition at line 143 of file MVAWriter.h.

template<size_t N>
std::string anab::FVectorWriter< N >::fInstanceName
private

Definition at line 136 of file MVAWriter.h.

template<size_t N>
bool anab::FVectorWriter< N >::fIsDescriptionRegistered
private

Definition at line 139 of file MVAWriter.h.

template<size_t N>
std::vector< std::string > anab::FVectorWriter< N >::fRegisteredDataTypes
private

Definition at line 138 of file MVAWriter.h.

template<size_t N>
std::unordered_map< size_t, FVector_ID > anab::FVectorWriter< N >::fTypeHashToID
private

Definition at line 141 of file MVAWriter.h.

template<size_t N>
std::vector< std::unique_ptr< std::vector< anab::FeatureVector<N> > > > anab::FVectorWriter< N >::fVectors
protected

Definition at line 131 of file MVAWriter.h.


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