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

#include <JsonBlobSetSink.h>

Inheritance diagram for WireCell::Img::JsonBlobSetSink:
WireCell::IBlobSetSink WireCell::IConfigurable WireCell::ISinkNode< IBlobSet > WireCell::IComponent< IConfigurable > WireCell::ISinkNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 JsonBlobSetSink ()
 
virtual ~JsonBlobSetSink ()
 
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 IBlobSet::pointer &bs)
 The calling signature: More...
 
- Public Member Functions inherited from WireCell::IBlobSetSink
virtual ~IBlobSetSink ()
 
virtual std::string signature ()
 
- Public Member Functions inherited from WireCell::ISinkNode< IBlobSet >
virtual ~ISinkNode ()
 
virtual bool operator() (const boost::any &anyin)
 
virtual std::vector< std::stringinput_types ()
 
- Public Member Functions inherited from WireCell::ISinkNodeBase
virtual ~ISinkNodeBase ()
 
virtual NodeCategory category ()
 Return the behavior category type. More...
 
- Public Member Functions inherited from WireCell::INode
virtual ~INode ()
 
virtual int concurrency ()
 
virtual std::vector< std::stringoutput_types ()
 
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

double m_drift_speed
 
std::string m_filename
 
int m_face
 
Log::logptr_t l
 

Additional Inherited Members

- Public Types inherited from WireCell::ISinkNode< IBlobSet >
typedef IBlobSet input_type
 
typedef std::shared_ptr< const IBlobSetinput_pointer
 
- Public Types inherited from WireCell::ISinkNodeBase
typedef std::shared_ptr< ISinkNodeBasepointer
 
- 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 JsonBlobSetSink.h.

Constructor & Destructor Documentation

Img::JsonBlobSetSink::JsonBlobSetSink ( )

Definition at line 15 of file JsonBlobSetSink.cxx.

17  , m_filename("blobs-%02d.json")
18  , m_face(0)
19  , l(Log::logger("io"))
20 {
21 }
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::JsonBlobSetSink::~JsonBlobSetSink ( )
virtual

Definition at line 22 of file JsonBlobSetSink.cxx.

23 {
24 }

Member Function Documentation

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

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 27 of file JsonBlobSetSink.cxx.

28 {
29  m_face = get(cfg, "face", m_face);
30  m_drift_speed = get(cfg, "drift_speed", m_drift_speed);
31  m_filename = get(cfg, "filename", m_filename);
32 }
cfg
Definition: dbjson.py:29
WireCell::Configuration Img::JsonBlobSetSink::default_configuration ( ) const
virtual

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

Reimplemented from WireCell::IConfigurable.

Definition at line 34 of file JsonBlobSetSink.cxx.

35 {
37 
38  // File name for output files. A "%d" will be filled in with blob
39  // set ident number.
40  cfg["filename"] = m_filename;
41  // Set to -1 to not apply any face filter, otherwise only consider matching face number
42  cfg["face"] = m_face;
43  cfg["drift_speed"] = m_drift_speed;
44  return cfg;
45 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool Img::JsonBlobSetSink::operator() ( const IBlobSet::pointer in)
virtual

The calling signature:

Implements WireCell::ISinkNode< IBlobSet >.

Definition at line 47 of file JsonBlobSetSink.cxx.

48 {
49  if (!bs) {
50  l->debug("JsonBlobSetSink: eos");
51  return true;
52  }
53 
54  const auto& blobs = bs->blobs();
55  if (blobs.empty()) {
56  l->info("JsonBlobSetSink: no blobs");
57  return true;
58  }
59 
60  auto slice = blobs[0]->slice();
61  auto frame = slice->frame();
62  const double start = slice->start();
63  const double time = frame->time();
64  const double x = (start-time)*m_drift_speed;
65 
66  l->debug("JsonBlobSetSink: frame:{}, slice:{} set:{} time:{} ms, start={} ms x:{} nblobs:{}",
67  frame->ident(), slice->ident(), bs->ident(),
68  time/units::ms, start/units::ms,
69  x, blobs.size());
70 
71  Json::Value jblobs = Json::arrayValue;
72 
73 
74  for (const auto& iblob: blobs) {
75  if (m_face >= 0 and m_face != iblob->face()->ident()) {
76  continue; // filter
77  }
78  const auto& coords = iblob->face()->raygrid();
79  const auto& blob = iblob->shape();
80  Json::Value jcorners = Json::arrayValue;
81  for (const auto& corner : blob.corners()) {
82  Json::Value jcorner = Json::arrayValue;
83  auto pt = coords.ray_crossing(corner.first, corner.second);
84  jcorner.append(x);
85  jcorner.append(pt.y());
86  jcorner.append(pt.z());
87  jcorners.append(jcorner);
88  }
89  Json::Value jblob;
90  jblob["points"] = jcorners;
91  jblob["values"]["charge"] = iblob->value();
92  jblob["values"]["uncert"] = iblob->uncertainty();
93  jblob["values"]["ident"] = iblob->ident();
94  jblob["values"]["inset"] = jblobs.size();
95 
96  jblobs.append(jblob);
97  }
98 
99 
101 
102  top["blobs"] = jblobs;
103 
105  if (m_filename.find("%") != std::string::npos) {
106  fname = String::format(m_filename, bs->ident());
107  }
108  std::ofstream fstr(fname);
109  if (!fstr) {
110  l->error("Failed to open for writing: %s", fname);
111  return false;
112  }
113  fstr << top;
114 
115 
116  return true;
117 }
std::string string
Definition: nybbler.cc:12
def blobs(cm, hist)
Definition: plots.py:79
static const double ms
Definition: Units.h:104
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2106
std::string format(const std::string &form, TYPES...objs)
Definition: String.h:45
list x
Definition: train.py:276

Member Data Documentation

Log::logptr_t WireCell::Img::JsonBlobSetSink::l
private

Definition at line 29 of file JsonBlobSetSink.h.

double WireCell::Img::JsonBlobSetSink::m_drift_speed
private

Definition at line 26 of file JsonBlobSetSink.h.

int WireCell::Img::JsonBlobSetSink::m_face
private

Definition at line 28 of file JsonBlobSetSink.h.

std::string WireCell::Img::JsonBlobSetSink::m_filename
private

Definition at line 27 of file JsonBlobSetSink.h.


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