LazyFrameSource.cxx
Go to the documentation of this file.
1 #include "LazyFrameSource.h"
3 
4 // for tick
5 //#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
9 
10 #include "TTimeStamp.h"
11 
12 
13 #include "WireCellIface/IFrame.h"
14 
15 namespace wcls {
16 
17  class LazyTrace : public WireCell::ITrace {
19  size_t m_index;
20  int m_channel;
21 
22  mutable WireCell::ITrace::ChargeSequence m_charge;
23 
24 
25  public:
26  LazyTrace(art::Handle< std::vector<raw::RawDigit> > rdvh, size_t index)
27  : m_rdvh(rdvh), m_index(index), m_channel(rdvh->at(index).Channel()) {}
28 
29 
30  virtual int channel() const { return m_channel; }
31  virtual int tbin() const { return 0; }
32 
33  virtual const ChargeSequence& charge() const {
34  if (m_charge.empty()) {
35  auto const& rd = m_rdvh->at(m_index);
36  const raw::RawDigit::ADCvector_t& adcv = rd.ADCs();
37  //std::cerr << "trace " << m_index << " chan " << m_channel << " with " << adcv.size() << " samples\n";
38  m_charge.insert(m_charge.end(), adcv.begin(), adcv.end());
39  m_rdvh.clear(); // bye bye
40  }
41  return m_charge;
42  }
43 
44  };
45 
46  class LazyFrame : public WireCell::IFrame {
47  int m_ident;
48  double m_time, m_tick;
49  tag_list_t m_tags;
50  WireCell::ITrace::shared_vector m_traces;
51  public:
52  LazyFrame(art::Handle< std::vector<raw::RawDigit> > rdvh,
53  int ident, double time, double tick, const tag_list_t& tags)
54  : m_ident(ident), m_time(time), m_tick(tick), m_tags(tags.begin(), tags.end()) {
55  const size_t nrds = rdvh->size();
56  auto* traces = new std::vector<LazyTrace::pointer>(nrds);
57  for (size_t ind = 0; ind < nrds; ++ind) {
58  traces->at(ind) = std::make_shared<LazyTrace>(rdvh, ind);
59  }
60  m_traces = WireCell::ITrace::shared_vector(traces);
61  }
62 
63  virtual ~LazyFrame() { }
64 
65  virtual const tag_list_t& frame_tags() const {
66  return m_tags;
67  }
68 
69  virtual const tag_list_t& trace_tags() const {
70  static tag_list_t dummy; // this frame doesn't support trace tags
71  return dummy;
72  }
73 
74  virtual const trace_list_t& tagged_traces(const tag_t& tag) const {
75  static trace_list_t dummy; // this frame doesn't support trace tags
76  return dummy;
77  }
78 
79  virtual const trace_summary_t& trace_summary(const tag_t& tag) const {
80  static trace_summary_t dummy; // this frame doesn't support trace tags
81  return dummy;
82  }
83 
84 
85  virtual WireCell::ITrace::shared_vector traces() const {
86  return m_traces;
87  }
88 
89  virtual int ident() const {
90  return m_ident;
91  }
92 
93  virtual double time() const {
94  return m_time;
95  }
96 
97  virtual double tick() const {
98  return m_tick;
99  }
100 
101 
102  };
103 
104 }
105 
106 
107 
108 #include "WireCellUtil/NamedFactory.h"
109 
110 WIRECELL_FACTORY(wclsLazyFrameSource, wcls::LazyFrameSource,
111  wcls::IArtEventVisitor, WireCell::IFrameSource)
112 
113 
114 using namespace wcls;
115 using namespace WireCell;
116 
118  : m_nticks(0)
119 {
120 }
121 
123 {
124 }
125 
126 
128 {
129  Configuration cfg;
130  cfg["art_tag"] = ""; // how to look up the raw digits
131  cfg["tick"] = 0.5*WireCell::units::us;
132  cfg["frame_tags"][0] = "orig"; // the tags to apply to this frame
133  cfg["nticks"] = m_nticks; // if nonzero, truncate or baseline-pad frame to this number of ticks.
134  return cfg;
135 }
136 
138 {
139  const std::string art_tag = cfg["art_tag"].asString();
140  if (art_tag.empty()) {
141  THROW(ValueError() << errmsg{"LazyFrameSource requires a source_label"});
142  }
143  m_inputTag = cfg["art_tag"].asString();
144 
145  m_tick = cfg["tick"].asDouble();
146  for (auto jtag : cfg["frame_tags"]) {
147  m_frame_tags.push_back(jtag.asString());
148  }
149  m_nticks = get(cfg, "nticks", m_nticks);
150 }
151 
152 
153 
154 // is this the right way to diff an art::Timestamp?
155 static
156 double tdiff(const art::Timestamp& ts1, const art::Timestamp& ts2)
157 {
158  TTimeStamp tts1(ts1.timeHigh(), ts1.timeLow());
159  TTimeStamp tts2(ts2.timeHigh(), ts2.timeLow());
160  return tts2.AsDouble() - tts1.AsDouble();
161 }
162 
164 {
165  // fixme: want to avoid depending on DetectorPropertiesService for now.
166  const double tick = m_tick;
167 
169  bool okay = event.getByLabel(m_inputTag, rdvh);
170  if (!okay) {
171  std::string msg = "LazyFrameSource failed to get vector<raw::RawDigit>: " + m_inputTag.encode();
172  std::cerr << msg << std::endl;
173  THROW(RuntimeError() << errmsg{msg});
174  }
175  else if (rdvh->size() == 0) return;
176  const double time = tdiff(event.getRun().beginTime(), event.time());
177 
178  std::cerr << "LazyFrameSource: got " << rdvh->size() << " raw::RawDigit objects\n";
179 
180  m_frames.push_back(std::make_shared<LazyFrame>(rdvh, event.event(), time, tick, m_frame_tags));
181  m_frames.push_back(nullptr);
182 }
183 
184 bool LazyFrameSource::operator()(WireCell::IFrame::pointer& frame)
185 {
186  frame = nullptr;
187  if (m_frames.empty()) {
188  return false;
189  }
190  frame = m_frames.front();
191  m_frames.pop_front();
192  return true;
193 }
194 
195 // Local Variables:
196 // mode: c++
197 // c-basic-offset: 4
198 // End:
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
WireCell::ITrace::ChargeSequence m_charge
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
EventNumber_t event() const
Definition: DataViewImpl.cc:85
virtual double tick() const
virtual void configure(const WireCell::Configuration &config)
static constexpr double us
Definition: Units.h:97
void msg(const char *fmt,...)
Definition: message.cpp:107
std::string string
Definition: nybbler.cc:12
virtual bool operator()(WireCell::IFrame::pointer &frame)
IFrameSource.
virtual int channel() const
virtual WireCell::Configuration default_configuration() const
IConfigurable.
virtual void visit(art::Event &event)
IArtEventVisitor.
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
std::deque< WireCell::IFrame::pointer > m_frames
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:73
std::string encode() const
Definition: InputTag.cc:97
static double tdiff(const art::Timestamp &ts1, const art::Timestamp &ts2)
virtual const trace_list_t & tagged_traces(const tag_t &tag) const
virtual const tag_list_t & frame_tags() const
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
virtual double time() const
Run const & getRun() const
Definition: Event.cc:50
virtual WireCell::ITrace::shared_vector traces() const
WireCell::ITrace::shared_vector m_traces
art::Handle< std::vector< raw::RawDigit > > m_rdvh
void clear()
Definition: Handle.h:236
virtual int tbin() const
cet::LibraryManager dummy("noplugin")
virtual const trace_summary_t & trace_summary(const tag_t &tag) const
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
art::InputTag m_inputTag
LazyFrame(art::Handle< std::vector< raw::RawDigit > > rdvh, int ident, double time, double tick, const tag_list_t &tags)
virtual int ident() const
virtual const ChargeSequence & charge() const
WIRECELL_FACTORY(wclsLazyFrameSource, wcls::LazyFrameSource, wcls::IArtEventVisitor, WireCell::IFrameSource) using namespace wcls
std::vector< std::string > m_frame_tags
virtual const tag_list_t & trace_tags() const
Timestamp const & beginTime() const
Definition: DataViewImpl.cc:92
QTextStream & endl(QTextStream &s)
Event finding and building.
LazyTrace(art::Handle< std::vector< raw::RawDigit > > rdvh, size_t index)