Public Member Functions | Private Attributes | List of all members
WireCell::Sio::NumpyDepoSaver Class Reference

#include <NumpyDepoSaver.h>

Inheritance diagram for WireCell::Sio::NumpyDepoSaver:
WireCell::IDepoFilter WireCell::IConfigurable WireCell::IFunctionNode< IDepo, IDepo > WireCell::IComponent< IConfigurable > WireCell::IFunctionNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 NumpyDepoSaver ()
 
virtual ~NumpyDepoSaver ()
 
virtual bool operator() (const WireCell::IDepo::pointer &indepo, WireCell::IDepo::pointer &outdepo)
 
virtual WireCell::Configuration default_configuration () const
 IConfigurable. More...
 
virtual void configure (const WireCell::Configuration &config)
 Accept a configuration. More...
 
- Public Member Functions inherited from WireCell::IDepoFilter
virtual ~IDepoFilter ()
 
virtual std::string signature ()
 Set the signature for all subclasses. More...
 
- Public Member Functions inherited from WireCell::IFunctionNode< IDepo, IDepo >
virtual ~IFunctionNode ()
 
virtual bool operator() (const boost::any &anyin, boost::any &anyout)
 The calling signature: More...
 
virtual std::vector< std::stringinput_types ()
 
virtual std::vector< std::stringoutput_types ()
 
- Public Member Functions inherited from WireCell::IFunctionNodeBase
virtual ~IFunctionNodeBase ()
 
virtual NodeCategory category ()
 Return the behavior category type. More...
 
virtual int concurrency ()
 By default assume all subclasses are stateless. More...
 
- Public Member Functions inherited from WireCell::INode
virtual ~INode ()
 
virtual void reset ()
 
- Public Member Functions inherited from WireCell::IComponent< INode >
virtual ~IComponent ()
 
- Public Member Functions inherited from WireCell::Interface
virtual ~Interface ()
 
- Public Member Functions inherited from WireCell::IConfigurable
virtual ~IConfigurable ()
 
- Public Member Functions inherited from WireCell::IComponent< IConfigurable >
virtual ~IComponent ()
 

Private Attributes

Configuration m_cfg
 
int m_save_count
 
std::vector< WireCell::IDepo::pointerm_depos
 

Additional Inherited Members

- Public Types inherited from WireCell::IDepoFilter
typedef std::shared_ptr< IDepoFilterpointer
 
- Public Types inherited from WireCell::IFunctionNode< IDepo, IDepo >
typedef IDepo input_type
 
typedef IDepo output_type
 
typedef std::shared_ptr< const IDepoinput_pointer
 
typedef std::shared_ptr< const IDepooutput_pointer
 
typedef IFunctionNode< IDepo, IDeposignature_type
 
- Public Types inherited from WireCell::IFunctionNodeBase
typedef std::shared_ptr< IFunctionNodeBasepointer
 
- Public Types inherited from WireCell::INode
enum  NodeCategory {
  unknown, sourceNode, sinkNode, functionNode,
  queuedoutNode, joinNode, splitNode, faninNode,
  fanoutNode, multioutNode, hydraNode
}
 
- Public Types inherited from WireCell::IComponent< INode >
typedef std::shared_ptr< INodepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 
- Public Types inherited from WireCell::Interface
typedef std::shared_ptr< Interfacepointer
 
- Public Types inherited from WireCell::IComponent< IConfigurable >
typedef std::shared_ptr< IConfigurablepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 

Detailed Description

Definition at line 13 of file NumpyDepoSaver.h.

Constructor & Destructor Documentation

Sio::NumpyDepoSaver::NumpyDepoSaver ( )

Definition at line 18 of file NumpyDepoSaver.cxx.

19  : m_save_count(0)
20 {
21 }
Sio::NumpyDepoSaver::~NumpyDepoSaver ( )
virtual

Definition at line 23 of file NumpyDepoSaver.cxx.

24 {
25 }

Member Function Documentation

void Sio::NumpyDepoSaver::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 41 of file NumpyDepoSaver.cxx.

42 {
43  m_cfg = config;
44 }
static Config * config
Definition: config.cpp:1054
WireCell::Configuration Sio::NumpyDepoSaver::default_configuration ( ) const
virtual

IConfigurable.

Reimplemented from WireCell::IConfigurable.

Definition at line 28 of file NumpyDepoSaver.cxx.

29 {
31 
32  // The output file name to write. Only compressed (zipped) Numpy
33  // files are supported. Writing is always in "append" mode. It's
34  // up to the user to delete a previous instance of the file if
35  // it's old contents are not wanted.
36  cfg["filename"] = "wct-frame.npz";
37 
38  return cfg;
39 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool Sio::NumpyDepoSaver::operator() ( const WireCell::IDepo::pointer indepo,
WireCell::IDepo::pointer outdepo 
)
virtual

IDepoFilter. This works by buffering depos and saving them at the same time a frame is saved.

Implements WireCell::IFunctionNode< IDepo, IDepo >.

Definition at line 69 of file NumpyDepoSaver.cxx.

71 {
72  if (indepo) {
73  outdepo = indepo;
74  m_depos.push_back(indepo);
75  return true;
76  }
77  outdepo = nullptr;
78 
79  const size_t ndepos = m_depos.size();
80  if (!ndepos) {
81  std::cerr << "NumpyDepoSaver: warning: EOS and no depos seen.\n";
82  return true;
83  }
84 
85  auto fdepos = flatten_depos(m_depos);
86  const size_t nfdepos = fdepos.size();
87 
88  // time, charge, x, y, z, dlong, dtran
89  const size_t ndata=7;
90  Array::array_xxf data(nfdepos, ndata);
91  // ID, pdg, gen, child
92  const size_t ninfo = 4;
93  Array::array_xxi info(nfdepos, ninfo);
94  for (size_t idepo=0; idepo != nfdepos; ++idepo) {
95  auto depogc = fdepos[idepo];
96  auto depo = std::get<0>(depogc);
97  auto gen = std::get<1>(depogc);
98  auto child = std::get<2>(depogc);
99  data(idepo, 0) = depo->time();
100  data(idepo, 1) = depo->charge();
101  data(idepo, 2) = depo->pos().x();
102  data(idepo, 3) = depo->pos().y();
103  data(idepo, 4) = depo->pos().z();
104  data(idepo, 5) = depo->extent_long();
105  data(idepo, 6) = depo->extent_tran();
106  info(idepo, 0) = depo->id();
107  info(idepo, 1) = depo->pdg();
108  info(idepo, 2) = gen;
109  info(idepo, 3) = child;
110  }
111  const std::string data_name = String::format("depo_data_%d", m_save_count);
112  const std::string info_name = String::format("depo_info_%d", m_save_count);
113 
114  const std::string fname = m_cfg["filename"].asString();
115  const std::string mode = "a";
116  cnpy::npz_save(fname, data_name, data.data(), {ndata, ndepos}, mode);
117  cnpy::npz_save(fname, info_name, info.data(), {ninfo, ndepos}, mode);
118  m_depos.clear();
119 
120  ++m_save_count;
121  return true;
122 }
static depos_with_prior flatten_depos(std::vector< WireCell::IDepo::pointer > depos)
std::string string
Definition: nybbler.cc:12
void npz_save(std::string zipname, std::string fname, const T *data, const std::vector< size_t > &shape, std::string mode="w")
Definition: cnpy.h:138
std::vector< WireCell::IDepo::pointer > m_depos
basic_data data
Definition: format.h:764
const int ndepos
std::string format(const std::string &form, TYPES...objs)
Definition: String.h:45
Eigen::Array< int, Eigen::Dynamic, Eigen::Dynamic > array_xxi
Integer.
Definition: Array.h:48
Eigen::ArrayXXf array_xxf
A real, 2D array.
Definition: Array.h:54

Member Data Documentation

Configuration WireCell::Sio::NumpyDepoSaver::m_cfg
private

Definition at line 29 of file NumpyDepoSaver.h.

std::vector<WireCell::IDepo::pointer> WireCell::Sio::NumpyDepoSaver::m_depos
private

Definition at line 31 of file NumpyDepoSaver.h.

int WireCell::Sio::NumpyDepoSaver::m_save_count
private

Definition at line 30 of file NumpyDepoSaver.h.


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