Public Member Functions | Private Attributes | List of all members
WireCell::Gen::Retagger Class Reference

#include <Retagger.h>

Inheritance diagram for WireCell::Gen::Retagger:
WireCell::IFrameFilter WireCell::IConfigurable WireCell::IFunctionNode< IFrame, IFrame > WireCell::IComponent< IConfigurable > WireCell::IFunctionNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 Retagger ()
 
virtual ~Retagger ()
 
virtual void configure (const WireCell::Configuration &config)
 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 &inframe, output_pointer &outframe)
 The calling signature: More...
 
- Public Member Functions inherited from WireCell::IFrameFilter
virtual ~IFrameFilter ()
 
virtual std::string signature ()
 Set the signature for all subclasses. More...
 
- Public Member Functions inherited from WireCell::IFunctionNode< IFrame, IFrame >
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

tagrules::Context m_trctx
 

Additional Inherited Members

- Public Types inherited from WireCell::IFrameFilter
typedef std::shared_ptr< IFrameFilterpointer
 
- Public Types inherited from WireCell::IFunctionNode< IFrame, IFrame >
typedef IFrame input_type
 
typedef IFrame output_type
 
typedef std::shared_ptr< const IFrameinput_pointer
 
typedef std::shared_ptr< const IFrameoutput_pointer
 
typedef IFunctionNode< IFrame, IFramesignature_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 40 of file Retagger.h.

Constructor & Destructor Documentation

Gen::Retagger::Retagger ( )

Definition at line 10 of file Retagger.cxx.

11 {
12 }
Gen::Retagger::~Retagger ( )
virtual

Definition at line 14 of file Retagger.cxx.

15 {
16 }

Member Function Documentation

void Gen::Retagger::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 18 of file Retagger.cxx.

19 {
20  // frame/trace/merge tagging.
21  m_trctx.configure(cfg["tag_rules"]);
22 }
cfg
Definition: dbjson.py:29
tagrules::Context m_trctx
Definition: Retagger.h:51
void configure(const Configuration &cfg)
Definition: TagRules.cxx:61
WireCell::Configuration Gen::Retagger::default_configuration ( ) const
virtual

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

Reimplemented from WireCell::IConfigurable.

Definition at line 24 of file Retagger.cxx.

25 {
27  cfg["tag_rules"] = Json::arrayValue;
28  return cfg;
29 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool Gen::Retagger::operator() ( const input_pointer in,
output_pointer out 
)
virtual

The calling signature:

Implements WireCell::IFunctionNode< IFrame, IFrame >.

Definition at line 31 of file Retagger.cxx.

32 {
33  outframe = nullptr;
34  if (!inframe) {
35  return true; // eos
36  }
37 
38 
39  // Basic frame data is just shunted across.
40  auto sfout = new SimpleFrame(inframe->ident(), inframe->time(), *inframe->traces(), inframe->tick());
41 
42  //
43  // frame
44  auto fintags = inframe->frame_tags();
45  // Add empty tag to allow rules to create an output tag even if none exist.
46  // No equivalent should be made for trace tags.
47  fintags.push_back("");
48  auto fouttags = m_trctx.transform(0, "frame", fintags);
49  for (auto ftag : fouttags) {
50  sfout->tag_frame(ftag);
51  }
52 
53  //
54  // trace
55  for (auto inttag : inframe->trace_tags()) {
56  tagrules::tagset_t touttags = m_trctx.transform(0, "trace", inttag);
57  if (touttags.empty()) {
58  continue;
59  }
60  const auto& traces = inframe->tagged_traces(inttag);
61  const auto& summary = inframe->trace_summary(inttag);
62  for (auto otag : touttags) {
63  sfout->tag_traces(otag, traces, summary);
64  }
65  }
66 
67  //
68  // merge
69  typedef std::tuple<tagrules::tag_t, IFrame::trace_list_t, IFrame::trace_summary_t> tag_trace_list_summary_t;
70  typedef std::vector< tag_trace_list_summary_t > ttls_stash_t;
71  typedef std::unordered_map<std::string, ttls_stash_t> ttls_stash_map_t;
72  ttls_stash_map_t stashmap;
73  for (auto inttag : inframe->trace_tags()) {
74  tagrules::tagset_t touttags = m_trctx.transform(0, "merge", inttag);
75  // std::cerr << "Retagger: " << inttag << " -> " << touttags.size() << " outtags\n";
76  if (touttags.empty()) {
77  continue;
78  }
79  const auto& traces = inframe->tagged_traces(inttag);
80  const auto& summary = inframe->trace_summary(inttag);
81  for (auto otag : touttags) {
82  stashmap[otag].push_back(std::make_tuple(inttag, traces, summary));
83  }
84  }
85  for (auto it : stashmap) {
86  auto& otag = it.first;
87  auto& stashv = it.second;
88  size_t ntraces = 0, nsummary=0;
89  // If at least one summary is not empty we must assure output
90  // summary is aligned with output trace index vector.
91  // Otherwise, we assume input plays by the rules and keeps
92  // size of traces and summary equal.
93  for (auto& ttls : stashv) {
94  ntraces += get<1>(ttls).size();
95  nsummary += get<2>(ttls).size();
96  }
97  IFrame::trace_list_t otraces;
98  otraces.reserve(ntraces);
99  IFrame::trace_summary_t osummary;
100  if (nsummary > 0) {
101  osummary.reserve(ntraces);
102  }
103  for (auto& ttls : stashv) { // one more time
104  auto& traces = get<1>(ttls);
105  otraces.insert(otraces.end(), traces.begin(), traces.end());
106 
107  // std::cerr << "Retagger: merge: " << get<0>(ttls) << " -> " << otag
108  // << " with " << otraces.size() << " / " << ntraces << std::endl;
109  if (!nsummary) {
110  continue;
111  }
112  auto& summary = get<2>(ttls);
113  if (summary.empty()) {
114  for (size_t ind=0; ind<traces.size(); ++ind) {
115  summary.push_back(0); // zero pad to cover missing summary and keep alignment with traces.
116  }
117  }
118  else {
119  osummary.insert(osummary.end(), summary.begin(), summary.end());
120  }
121  }
122  std::cerr << "Retagger: tagging trace set: " << otag
123  << " with " << otraces.size() << " traces, " << osummary.size() << " summary\n";
124 
125  sfout->tag_traces(otag, otraces, osummary);
126  }
127 
128 
129  outframe = IFrame::pointer(sfout);
130  return true;
131 }
std::shared_ptr< const IFrame > pointer
Definition: IData.h:19
std::unordered_set< tag_t > tagset_t
Definition: TagRules.h:48
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:87
std::vector< double > trace_summary_t
Definition: IFrame.h:39
tagset_t transform(size_t ind, const std::string &name, const tag_t &tag)
Definition: TagRules.cxx:80
tagrules::Context m_trctx
Definition: Retagger.h:51
def summary(store)
Definition: info.py:119
std::vector< size_t > trace_list_t
Definition: IFrame.h:36

Member Data Documentation

tagrules::Context WireCell::Gen::Retagger::m_trctx
private

Definition at line 51 of file Retagger.h.


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