test_persist.cxx
Go to the documentation of this file.
1 #include "WireCellUtil/Persist.h"
2 
3 #include <random>
4 #include <iostream>
5 #include <functional>
6 
7 using namespace std;
8 using namespace WireCell;
9 
10 int main(int argc, char* argv[])
11 {
12  std::string name = argv[0];
13 
14  std::default_random_engine generator;
15  std::uniform_real_distribution<double> distribution(0.0,1.0);
16  auto uni = std::bind(distribution, generator);
17 
18  const int nbins = 500;
19  const int narrays = 100;
20  Json::Value jroot;
21  for (int ind=0; ind<narrays; ++ind) {
22  Json::Value jarr;
23  for (int ibin=0; ibin<nbins; ++ibin) {
24  auto number = uni();
25  jarr.append(number);
26  }
27  jroot[ind] = jarr;
28  }
29 
30  // dump non-pretty in plain text and bzip2'ed to see size diff
31  Persist::dump(name + ".json", jroot);
32  Persist::dump(name + "-ugly.json.bz2", jroot);
33 
34  // dump pretty, read back and redump so can do a diff
35  Persist::dump(name + "-pretty.json", jroot, true);
36  Persist::dump(name + "-pretty.json.bz2", jroot, true);
37 
38  Json::Value jroot2 = Persist::load(name + "-pretty.json");
39  Json::Value jroot3 = Persist::load(name + "-pretty.json.bz2");
40 
41  Persist::dump(name + "-pretty2.json", jroot2, true);
42  Persist::dump(name + "-pretty3.json", jroot3, true);
43  return 0;
44 
45 }
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
STL namespace.
int main(int argc, char *argv[])
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2106
generator
Definition: train.py:468
Definition: Main.h:22
void dump(const IFrame::pointer frame)
Definition: Fourdee.cxx:120
def load(filename, jpath="depos")
Definition: depos.py:34