FrameFanout.cxx
Go to the documentation of this file.
2 
6 
9 
10 
11 using namespace WireCell;
12 
13 Gen::FrameFanout::FrameFanout(size_t multiplicity)
14  : m_multiplicity(multiplicity)
15  , log(Log::logger("glue"))
16 {
17 }
18 Gen::FrameFanout::~FrameFanout()
19 {
20 }
21 
22 WireCell::Configuration Gen::FrameFanout::default_configuration() const
23 {
25  // How many output ports
26  cfg["multiplicity"] = (int)m_multiplicity;
27  // Tag rules are an array, one element per output port. Each
28  // element is an object keyed with "frame" or "trace". Each of
29  // their values are an object keyed by a regular expression
30  // (regex) and with values that are a single tag or an array of
31  // tags. See util/test_tagrules for examples.
32  cfg["tag_rules"] = Json::arrayValue;
33  return cfg;
34 }
36 {
37  int m = get<int>(cfg, "multiplicity", (int)m_multiplicity);
38  if (m<=0) {
39  THROW(ValueError() << errmsg{"FrameFanout multiplicity must be positive"});
40  }
41  m_multiplicity = m;
42 
43  m_ft.configure(cfg["tag_rules"]);
44 }
45 
46 
47 std::vector<std::string> Gen::FrameFanout::output_types()
48 {
49  const std::string tname = std::string(typeid(output_type).name());
50  std::vector<std::string> ret(m_multiplicity, tname);
51  return ret;
52 }
53 
54 
55 bool Gen::FrameFanout::operator()(const input_pointer& in, output_vector& outv)
56 {
57  outv.resize(m_multiplicity);
58 
59  if (!in) { // pass on EOS
60  for (size_t ind=0; ind<m_multiplicity; ++ind) {
61  outv[ind] = in;
62  }
63  log->debug("FrameFanout: see EOS");
64  return true;
65  }
66 
67  auto fintags = in->frame_tags();
68  // Add empty tag to allow rules to create an output tag even if none exist.
69  // No equivalent should be made for trace tags.
70  fintags.push_back("");
71 
72 
73  std::stringstream taginfo;
74 
75  for (size_t ind=0; ind<m_multiplicity; ++ind) {
76 
77  // Basic frame stays the same.
78  auto sfout = new SimpleFrame(in->ident(), in->time(), *in->traces(), in->tick());
79 
80  // Transform any frame tags based on a per output port ruleset
81  auto fouttags = m_ft.transform(ind, "frame", fintags);
82 
83  for (auto ftag : fouttags) {
84  sfout->tag_frame(ftag);
85  taginfo << " ftag:" << ftag;
86  }
87 
88  for (auto inttag : in->trace_tags()) {
89  tagrules::tagset_t touttags = m_ft.transform(ind, "trace", inttag);
90  if (touttags.empty()) {
91  continue;
92  }
93  const auto& traces = in->tagged_traces(inttag);
94  const auto& summary = in->trace_summary(inttag);
95  for (auto otag : touttags) {
96  sfout->tag_traces(otag, traces, summary);
97  taginfo << " " << inttag << "->" << otag;
98  }
99  };
100 
101  outv[ind] = IFrame::pointer(sfout);
102  }
103 
104  std::string tagmsg = taginfo.str();
105  if (!tagmsg.empty()) {
106  log->debug("FrameFanout: tagnifo:{}", taginfo.str());
107  }
108  return true;
109 }
110 
111 
static QCString name
Definition: declinfo.cpp:673
static const double m
Definition: Units.h:79
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
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
WIRECELL_FACTORY(FrameFanout, WireCell::Gen::FrameFanout, WireCell::IFrameFanout, WireCell::IConfigurable) using namespace WireCell
def summary(store)
Definition: info.py:119
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1124