ChannelSplitter.cxx
Go to the documentation of this file.
2 
7 
10 
11 
12 using namespace WireCell;
13 
14 SigProc::ChannelSplitter::ChannelSplitter(size_t multiplicity)
15  : m_multiplicity(multiplicity)
16  , log(Log::logger("glue"))
17 {
18 }
19 SigProc::ChannelSplitter::~ChannelSplitter()
20 {
21 }
22 
23 WireCell::Configuration SigProc::ChannelSplitter::default_configuration() const
24 {
26 
27  // A list of anode names
28  cfg["anodes"] = Json::arrayValue;
29  // Tag rules are an array, one element per output port. Each
30  // element is an object keyed with "frame" or "trace". Each of
31  // their values are an object keyed by a regular expression
32  // (regex) and with values that are a single tag or an array of
33  // tags. See util/test_tagrules for examples.
34  cfg["tag_rules"] = Json::arrayValue;
35 
36  return cfg;
37 }
39 {
40  m_multiplicity = 0;
41  m_c2p.clear();
42  for (auto janode : cfg["anodes"]) {
43  auto anode = Factory::find_tn<IAnodePlane>(janode.asString());
44  for (auto c : anode->channels()) {
45  m_c2p[c] = m_multiplicity;
46  }
47  ++m_multiplicity;
48  }
49  if (m_c2p.empty()) {
50  THROW(ValueError() << errmsg{"ChannelSplitter must have at least one annode"});
51  }
52  m_ft.configure(cfg["tag_rules"]);
53 }
54 
55 
56 std::vector<std::string> SigProc::ChannelSplitter::output_types()
57 {
58  const std::string tname = std::string(typeid(output_type).name());
59  std::vector<std::string> ret(m_multiplicity, tname);
60  return ret;
61 }
62 
63 
64 bool SigProc::ChannelSplitter::operator()(const input_pointer& in, output_vector& outv)
65 {
66  outv.resize(m_multiplicity);
67 
68  if (!in) { // pass on EOS
69  for (size_t ind=0; ind < m_multiplicity; ++ind) {
70  outv[ind] = in;
71  }
72  log->debug("ChannelSplitter: see EOS");
73  return true;
74  }
75 
76  std::vector<ITrace::vector> port_traces(m_multiplicity);
77 
78  for (const auto& itrace : *(in->traces())) {
79  int chan = itrace->channel();
80  const auto& it = m_c2p.find(chan);
81  if (it == m_c2p.end()) {
82  log->debug("ChannelSplitter: no port for channel {}, dropping", chan);
83  continue;
84  }
85  const int port = it->second;
86  port_traces[port].push_back(itrace);
87  }
88 
89  auto fintags = in->frame_tags();
90  std::stringstream taginfo;
91  for (size_t iport=0; iport<m_multiplicity; ++iport) {
92 
93  // Basic frame stays the same.
94  auto sfout = new SimpleFrame(in->ident(), in->time(), port_traces[iport], in->tick());
95 
96  // Transform any frame tags based on a per output port ruleset
97  auto fouttags = m_ft.transform(iport, "frame", fintags);
98 
99  for (auto ftag : fouttags) {
100  sfout->tag_frame(ftag);
101  taginfo << " ftag:" << ftag;
102  }
103 
104  for (auto inttag : in->trace_tags()) {
105  tagrules::tagset_t touttags = m_ft.transform(iport, "trace", inttag);
106  if (touttags.empty()) {
107  continue;
108  }
109  const auto& traces = in->tagged_traces(inttag);
110  const auto& summary = in->trace_summary(inttag);
111  for (auto otag : touttags) {
112  sfout->tag_traces(otag, traces, summary);
113  taginfo << " " << inttag << "->" << otag;
114  }
115  };
116 
117  outv[iport] = IFrame::pointer(sfout);
118  }
119 
120  std::string tagmsg = taginfo.str();
121  if (!tagmsg.empty()) {
122  log->debug("ChannelSplitter: tagnifo:{}", taginfo.str());
123  }
124  return true;
125 }
126 
127 
static QCString name
Definition: declinfo.cpp:673
std::unordered_set< tag_t > tagset_t
Definition: TagRules.h:48
std::string string
Definition: nybbler.cc:12
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
cfg
Definition: dbjson.py:29
WIRECELL_FACTORY(ChannelSplitter, WireCell::SigProc::ChannelSplitter, WireCell::IFrameFanout, WireCell::IConfigurable) using namespace WireCell
void tag_frame(const tag_t &tag)
Definition: SimpleFrame.cxx:71
def configure(cfg)
Definition: cuda.py:34
#define THROW(e)
Definition: Exceptions.h:25
std::vector< output_pointer > output_vector
Definition: IFanoutNode.h:45
logptr_t logger(std::string name)
Definition: Logging.cxx:71
Thrown when a wrong value has been encountered.
Definition: Exceptions.h:37
void log(source_loc source, level::level_enum lvl, const char *fmt, const Args &...args)
Definition: spdlog.h:165
Definition: Main.h:22
std::shared_ptr< const IFrame > input_pointer
Definition: IFanoutNode.h:43
Json::Value Configuration
Definition: Configuration.h:50
def summary(store)
Definition: info.py:119
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1124