2 #include "art/Framework/Principal/Handle.h"
4 #include "art/Framework/Principal/Event.h"
5 #include "art/Framework/Principal/Run.h"
8 #include "TTimeStamp.h"
10 #include "WireCellAux/SimpleFrame.h"
11 #include "WireCellAux/SimpleTrace.h"
12 #include "WireCellUtil/NamedFactory.h"
17 WireCell::IFrameSource)
20 using namespace WireCell;
21 using WireCell::Aux::SimpleTrace;
22 using WireCell::Aux::SimpleFrame;
26 CookedFrameSource::~CookedFrameSource() {}
28 WireCell::Configuration
29 CookedFrameSource::default_configuration()
const
33 cfg[
"tick"] = 0.5 * WireCell::units::us;
34 cfg[
"frame_tags"][0] =
"orig";
35 cfg[
"nticks"] = m_nticks;
40 CookedFrameSource::configure(
const WireCell::Configuration& cfg)
42 const std::string art_tag = cfg[
"art_tag"].asString();
43 if (art_tag.empty()) {
44 THROW(ValueError() << errmsg{
"WireCell::CookedFrameSource requires a source_label"});
46 m_inputTag = cfg[
"art_tag"].asString();
48 m_tick = cfg[
"tick"].asDouble();
49 for (
auto jtag : cfg[
"frame_tags"]) {
50 m_frame_tags.push_back(jtag.asString());
52 m_nticks =
get(cfg,
"nticks", m_nticks);
58 tdiff(
const art::Timestamp& ts1,
const art::Timestamp& ts2)
60 TTimeStamp tts1(ts1.timeHigh(), ts1.timeLow());
61 TTimeStamp tts2(ts2.timeHigh(), ts2.timeLow());
62 return tts2.AsDouble() - tts1.AsDouble();
71 const std::vector<float> sig = rw.
Signal();
74 unsigned int nsamp = sig.size();
75 if (nticks_want > 0) { nsamp = std::min(nsamp, nticks_want); }
80 auto strace =
new SimpleTrace(chid, tbin, nticks_want);
81 auto&
q = strace->charge();
82 for (
unsigned int itick = 0; itick < nsamp; ++itick) {
83 q[itick] = sig[itick];
85 for (
unsigned int itick = nsamp; itick < nticks_want; ++itick) {
92 CookedFrameSource::visit(art::Event&
e)
94 auto const&
event =
e;
96 const double tick = m_tick;
97 art::Handle<std::vector<recob::Wire>> rwvh;
98 bool okay =
event.getByLabel(m_inputTag, rwvh);
101 "WireCell::CookedFrameSource failed to get vector<recob::Wire>: " + m_inputTag.encode();
103 THROW(RuntimeError() << errmsg{msg});
105 else if (rwvh->size() == 0)
108 const std::vector<recob::Wire>& rwv(*rwvh);
109 const size_t nchannels = rwv.size();
110 std::cerr <<
"CookedFrameSource: got " << nchannels <<
" recob::Wire objects\n";
113 for (
size_t ind = 0; ind < nchannels; ++ind) {
114 auto const& rw = rwv.at(ind);
115 traces[ind] = ITrace::pointer(
make_trace(rw, m_nticks));
118 std::cerr <<
"\tinput nticks=" << rw.NSignal() <<
" setting to " << m_nticks << std::endl;
121 std::cerr <<
"\tinput nticks=" << rw.NSignal() <<
" keeping as is" << std::endl;
126 const double time =
tdiff(event.getRun().beginTime(),
event.time());
127 auto sframe =
new SimpleFrame(event.event(), time, traces,
tick);
128 for (
auto tag : m_frame_tags) {
130 sframe->tag_frame(tag);
132 m_frames.push_back(WireCell::IFrame::pointer(sframe));
133 m_frames.push_back(
nullptr);
137 CookedFrameSource::operator()(WireCell::IFrame::pointer& frame)
140 if (m_frames.empty()) {
return false; }
141 frame = m_frames.front();
142 m_frames.pop_front();
BEGIN_PROLOG could also be cerr
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
WIRECELL_FACTORY(wclsChannelNoiseDB, wcls::ChannelNoiseDB, wcls::IArtEventVisitor, WireCell::IChannelNoiseDatabase) using namespace WireCell
std::vector< float > Signal() const
Return a zero-padded full length vector filled with RoI signal.
static SimpleTrace * make_trace(const recob::Wire &rw, unsigned int nticks_want)
static double tdiff(const art::Timestamp &ts1, const art::Timestamp &ts2)
Class holding the regions of interest of signal from a channel.
Declaration of basic channel signal object.
unsigned int ChannelID_t
Type representing the ID of a readout channel.