BeeDepoSource.cxx
Go to the documentation of this file.
2 
4 
7 
8 #include "WireCellUtil/Point.h"
9 #include "WireCellUtil/Persist.h"
10 
13 
14 #include <iostream>
15 #include <string>
16 #include <locale> // for std::tolower
17 
18 
19 using namespace WireCell;
20 
22  : m_policy("")
23 {
24 }
25 
27 {
28 }
29 
31 {
32  out = nullptr;
33 
34  if (m_depos.size() > 0) {
35  out = m_depos.back();
36  m_depos.pop_back();
37  return true;
38  }
39 
40  // refill
41  while (!m_filenames.empty()) {
42 
43  std::string fname = m_filenames.back();
44  m_filenames.pop_back();
45  Json::Value jdat = Persist::load(fname);
46  int ndepos = jdat["x"].size();
47  if (!ndepos) {
48  continue;
49  }
50 
51  m_depos.resize(ndepos, nullptr);
52  for (int idepo=0; idepo < ndepos; ++idepo) {
53  m_depos[idepo] = std::make_shared<SimpleDepo>(
54  jdat["t"][idepo].asDouble(),
55  Point(
56  jdat["x"][idepo].asDouble(),
57  jdat["y"][idepo].asDouble(),
58  jdat["z"][idepo].asDouble()),
59  jdat["q"][idepo].asDouble());
60  }
61  if (m_policy != "stream") {
62  m_depos.push_back(nullptr); // chunk by file
63  }
64  std::reverse(m_depos.begin(), m_depos.end());
65  break;
66  }
67 
68  if (m_depos.empty()) {
69  return false;
70  }
71 
72  out = m_depos.back();
73  m_depos.pop_back();
74  return true;
75 }
76 
78 {
80  cfg["filelist"] = Json::arrayValue; // list of input files, empties are skipped
81  cfg["policy"] = ""; // set to "stream" to avoid sending EOS after each file's worth of depos.
82  return cfg;
83 }
84 
85 
87 {
88  m_filenames = get< std::vector<std::string> >(cfg, "filelist");
89  std::reverse(m_filenames.begin(), m_filenames.end()); // to use pop_back().
90  m_policy = get<std::string>(cfg, "policy", "");
91 }
92 
93 
std::shared_ptr< const IDepo > pointer
Definition: IData.h:19
D3Vector< double > Point
A 3D Cartesian point in double precision.
Definition: Point.h:15
std::string string
Definition: nybbler.cc:12
virtual WireCell::Configuration default_configuration() const
IConfigurable.
cfg
Definition: dbjson.py:29
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2106
const int ndepos
virtual void configure(const WireCell::Configuration &config)
Accept a configuration.
Json::Value load(const std::string &filename, const externalvars_t &extvar=externalvars_t(), const externalvars_t &extcode=externalvars_t())
Definition: Persist.cxx:121
virtual bool operator()(IDepo::pointer &out)
IDepoSource.
Definition: Main.h:22
std::vector< std::string > m_filenames
Definition: BeeDepoSource.h:54
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
Definition: qstring.cpp:11649
Json::Value Configuration
Definition: Configuration.h:50
WIRECELL_FACTORY(BeeDepoSource, WireCell::Sio::BeeDepoSource, WireCell::IDepoSource, WireCell::IConfigurable) using namespace WireCell