Public Member Functions | Private Attributes | List of all members
WireCell::Img::JsonClusterTap Class Reference

#include <JsonClusterTap.h>

Inheritance diagram for WireCell::Img::JsonClusterTap:
WireCell::IClusterFilter WireCell::IConfigurable WireCell::IFunctionNode< ICluster, ICluster > WireCell::IComponent< IConfigurable > WireCell::IFunctionNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 JsonClusterTap ()
 
virtual ~JsonClusterTap ()
 
virtual void configure (const WireCell::Configuration &cfg)
 Accept a configuration. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
virtual bool operator() (const input_pointer &in, output_pointer &out)
 The calling signature: More...
 
- Public Member Functions inherited from WireCell::IClusterFilter
virtual ~IClusterFilter ()
 
virtual std::string signature ()
 Set the signature for all subclasses. More...
 
- Public Member Functions inherited from WireCell::IFunctionNode< ICluster, ICluster >
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

std::string m_filename
 
double m_drift_speed
 
Log::logptr_t log
 

Additional Inherited Members

- Public Types inherited from WireCell::IClusterFilter
typedef std::shared_ptr< IClusterFilterpointer
 
- Public Types inherited from WireCell::IFunctionNode< ICluster, ICluster >
typedef ICluster input_type
 
typedef ICluster output_type
 
typedef std::shared_ptr< const IClusterinput_pointer
 
typedef std::shared_ptr< const IClusteroutput_pointer
 
typedef IFunctionNode< ICluster, IClustersignature_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 34 of file JsonClusterTap.h.

Constructor & Destructor Documentation

Img::JsonClusterTap::JsonClusterTap ( )

Definition at line 23 of file JsonClusterTap.cxx.

24  : m_filename("cluster-%03d.json")
26  , log(Log::logger("io"))
27 {
28 }
logptr_t logger(std::string name)
Definition: Logging.cxx:71
static const double mm
Definition: Units.h:55
static const double us
Definition: Units.h:105
Img::JsonClusterTap::~JsonClusterTap ( )
virtual

Definition at line 30 of file JsonClusterTap.cxx.

31 {
32 }

Member Function Documentation

void Img::JsonClusterTap::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 34 of file JsonClusterTap.cxx.

35 {
36  m_filename = get(cfg, "filename", m_filename);
37  m_drift_speed = get(cfg, "drift_speed", m_drift_speed);
38 }
cfg
Definition: dbjson.py:29
WireCell::Configuration Img::JsonClusterTap::default_configuration ( ) const
virtual

Optional, override to return a hard-coded default configuration.

Reimplemented from WireCell::IConfigurable.

Definition at line 40 of file JsonClusterTap.cxx.

41 {
43  // output json file. A "%d" type format code may be included to be resolved by a cluster identifier.
44  cfg["filename"] = m_filename;
45  // for conversion between time and "x" coordinate
46  cfg["drift_speed"] = m_drift_speed;
47  return cfg;
48 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool Img::JsonClusterTap::operator() ( const input_pointer in,
output_pointer out 
)
virtual

The calling signature:

Implements WireCell::IFunctionNode< ICluster, ICluster >.

Definition at line 190 of file JsonClusterTap.cxx.

191 {
192  out = in;
193  if (!in) {
194  return true;
195  }
196 
197  std::vector< std::function< Json::Value(const cluster_node_t& ptr) > > jsoners{
200  wire_jsoner,
202  slice_jsoner,
204  };
205  auto asjson = [&](const cluster_node_t& n) {
206  return jsoners[n.ptr.index()](n);
207  };
208 
209 
210 /*
211  * - vertices :: a list of graph vertices
212  * - edges :: a list of graph edges
213  *
214  * A vertex is represented as a JSON object with the following attributes
215  * - ident :: an indexable ID number for the node, and referred to in "edges"
216  * - type :: the letter "code" used in ICluster: one in "sbcwm"
217  * - data :: an object holding information about the corresponding vertex object
218  *
219  * An edge is a pair of vertex ident numbers.
220  *
221 */
222  const auto& gr = in->graph();
223 
224  Json::Value jvertices = Json::arrayValue;
225  for (auto vtx : boost::make_iterator_range(boost::vertices(gr))) {
226  const auto& vobj = gr[vtx];
227  if (!vobj.ptr.index()) {
228  // warn?
229  continue;
230  }
231  Json::Value jvtx = Json::objectValue;
232  jvtx["ident"] = (int)vtx;
233  jvtx["type"] = String::format("%c", vobj.code());
234  jvtx["data"] = asjson(vobj);
235 
236  jvertices.append(jvtx);
237  }
238 
239  Json::Value jedges = Json::arrayValue;
240  for (auto eit : boost::make_iterator_range(boost::edges(gr))) {
241  Json::Value jedge = Json::arrayValue;
242  jedge[0] = (int) boost::source(eit, gr);
243  jedge[1] = (int)boost::target(eit, gr);
244  jedges.append(jedge);
245  }
246 
247  Json::Value top = Json::objectValue;
248  top["vertices"] = jvertices;
249  top["edges"] = jedges;
250 
252  if (m_filename.find("%") != std::string::npos) {
253  fname = String::format(m_filename, in->ident());
254  log->debug("JsonClusterTap: {} -> {}", m_filename, fname);
255  }
256  std::ofstream fstr(fname);
257  if (!fstr) {
258  log->error("JsonClusterTap failed to open for writing: {}", fname);
259  return false;
260  }
261  log->info("JsonClusterTap writing: {}", fname);
262  fstr << top;
263 
264  return true;
265 }
static Json::Value size_stringer(const cluster_node_t &n)
std::string string
Definition: nybbler.cc:12
static Json::Value wire_jsoner(const cluster_node_t &n)
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2106
Json::Value measurement_jsoner(const cluster_node_t &n)
Json::Value slice_jsoner(const cluster_node_t &n)
std::string format(const std::string &form, TYPES...objs)
Definition: String.h:45
static Json::Value channel_jsoner(const cluster_node_t &n)
std::size_t n
Definition: format.h:3399

Member Data Documentation

Log::logptr_t WireCell::Img::JsonClusterTap::log
private

Definition at line 47 of file JsonClusterTap.h.

double WireCell::Img::JsonClusterTap::m_drift_speed
private

Definition at line 45 of file JsonClusterTap.h.

std::string WireCell::Img::JsonClusterTap::m_filename
private

Definition at line 44 of file JsonClusterTap.h.


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