test_wireschema.cxx
Go to the documentation of this file.
2 #include "WireCellUtil/Testing.h"
3 #include "WireCellUtil/Units.h"
4 
5 #include <iostream>
6 using namespace std;
7 using namespace WireCell;
8 
9 void test_read(const char* filename)
10 {
11  /// BIG FAT NOTE: don't directly load() from user code. Use
12  /// IWireSchema component named WireSchemaFile instead.
13  cerr << "Loading twice, should read but once\n";
14  auto store1 = WireSchema::load(filename);
15  auto store2 = WireSchema::load(filename);
16 
17  Assert(store1.db().get() == store2.db().get());
18 
19  cerr << "Total store has:\n";
20  cerr << "\t" << store1.detectors().size() << " detectors\n";
21  cerr << "\t" << store1.anodes().size() << " anodes\n";
22  cerr << "\t" << store1.faces().size() << " faces\n";
23  cerr << "\t" << store1.planes().size() << " planes\n";
24  cerr << "\t" << store1.wires().size() << " wires\n";
25 
26  Assert(store1.wires().size() > 0);
27 
28  auto& a0 = store1.anode(0);
29  cerr << "Got anode 0 with " << store1.faces(a0).size() << " faces\n";
30 
31 
32  const int bogusid = 0xdeadbeaf;
33  try{
34  store1.anode(bogusid);
35  cerr << "Unexpectedly got bogus anode ID "<<bogusid<<"\n";
36  Assert(false);
37  }
38  catch (WireCell::Exception& e) {
39  cerr << "Correctly caught exception with unlikely anode id "<<bogusid<<":\n"
40  << "----\n"
41  << e.what()
42  << "----\n";
43  }
44 
45  for (const auto& anode : store1.anodes()) {
46  for (const auto& face: store1.faces(anode)) {
47  for (const auto& plane: store1.planes(face)) {
48 
49  auto bb = store1.bounding_box(plane);
50  auto wp = store1.wire_pitch(plane);
51  auto ex = wp.first.cross(wp.second);
52 
53  cerr << "anode:" << anode.ident
54  << " face:" << face.ident
55  << " plane:" << plane.ident << ":\n"
56  << "\tdrift: " << ex << "\n"
57  << "\twire: " << wp.first << "\n"
58  << "\tpitch: " << wp.second << "\n"
59  << "\tbb: " << bb.bounds()/units::cm << "cm\n";
60  }
61  auto wplane = store1.planes(face).back();
62  auto wires = store1.wires(wplane);
63  const double zmax = wires.back().head.z();
64  const double zmin = wires.front().head.z();
65  const double dd = zmax-zmin;
66  const int n = wires.size();
67  cerr << "\tW plane: " << n << " wires, "
68  << "["<<zmin/units::m<<","<<zmax/units::m<<"]m, "
69  << "extent=" << dd/units::cm << "cm, pitch=" << dd/(n-1)/units::mm << "mm\n";
70  }
71  }
72 }
73 
74 int main(int argc, char *argv[])
75 {
76  const char* filename = "microboone-celltree-wires-v2.1.json.bz2";
77  if (argc > 1) {
78  filename = argv[1];
79  }
80  test_read(filename);
81 
82  return 0;
83 
84 }
static const double m
Definition: Units.h:79
#define a0
STL namespace.
char const * what() const
Definition: Exceptions.h:32
string filename
Definition: train.py:213
#define Assert
Definition: Testing.h:7
const double e
static const double mm
Definition: Units.h:73
Definition: Main.h:22
void test_read(const char *filename)
int main(int argc, char *argv[])
The base wire cell exception.
Definition: Exceptions.h:31
static const double cm
Definition: Units.h:76
std::size_t n
Definition: format.h:3399
def load(filename, jpath="depos")
Definition: depos.py:34