Macros | Functions
cvnInspectLevelDB.cc File Reference
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "boost/program_options/options_description.hpp"
#include "boost/program_options/variables_map.hpp"
#include "boost/program_options/parsers.hpp"
#include "leveldb/db.h"
#include <TH1D.h>
#include <TH2D.h>
#include <TCanvas.h>
#include <TFile.h>

Go to the source code of this file.

Macros

#define CPU_ONLY
 

Functions

po::variables_map getOptions (int argc, char *argv[], std::string &dir)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

#define CPU_ONLY

Definition at line 16 of file cvnInspectLevelDB.cc.

Function Documentation

po::variables_map getOptions ( int  argc,
char *  argv[],
std::string dir 
)

Definition at line 31 of file cvnInspectLevelDB.cc.

32 {
33 
34 // Declare the supported options.
35  po::options_description desc("Allowed options");
36  desc.add_options()
37  ("help", "produce help message")
38  ("dir,d", po::value<std::string>(&dir)->required(),
39  "leveldb directory");
40  po::variables_map vm;
41 
42  try
43  {
44  po::store(po::parse_command_line(argc, argv, desc), vm);
45  po::notify(vm);
46 
47  }
48  catch(po::error& e)
49  {
50  std::cout << "ERROR: " << e.what() << std::endl;
51  exit(1);
52  }
53 
54 
55  if (vm.count("help")) {
56  std::cout << desc << "\n";
57  exit(1);
58  }
59 
60  return vm;
61 }
error
Definition: include.cc:26
string dir
const double e
QTextStream & endl(QTextStream &s)
int main ( int  argc,
char *  argv[] 
)

Definition at line 65 of file cvnInspectLevelDB.cc.

66 {
67 
69  po::variables_map vm = getOptions(argc, argv, directory);
70 
71  leveldb::DB* db;
72  leveldb::Options options;
73  leveldb::Status status = leveldb::DB::Open(options, directory, &db);
74 
75  if (!status.ok()) return 1;
76 
77  ofstream outFile("test.txt");
78 
79  TH1D* hLabels = new TH1D("hLabels", ";Event Type", 15, 0, 15);
80  TH1D* hPE = new TH1D("hPE", "Scaled PE", 256, 0, 256);
81  vector<TH2D*> XVec;
82  vector<TH2D*> YVec;
83  vector<TH2D*> ZVec;
84 
85  //caffe::Datum datum;
86 
87  int total(0);
88  leveldb::Iterator* itCount = db->NewIterator(leveldb::ReadOptions());
89  for (itCount->SeekToFirst(); itCount->Valid(); itCount->Next())
90  {
91  total++;
92  }
93  std::cout << "total: " << total << std::endl;
94 
95  int count(0);
96  leveldb::Iterator* it = db->NewIterator(leveldb::ReadOptions());
97  for (it->SeekToFirst(); it->Valid(); it->Next())
98  {
99  if (count < 10000)
100  {
101  datum.ParseFromString( it->value().ToString() );
102  int channels = datum.channels();
103  int height = datum.height();
104  int width = datum.width();
105  int label = datum.label();
106 
107  //std::cout<<"channels:"<<channels<<std::endl;
108  //std::cout<<"height:"<<height<<std::endl;
109  //std::cout<<"width:"<<width<<std::endl;
110  //std::cout<<"label:"<<label<<std::endl;
111 
112  const char* pixels = datum.data().data();
113  for (int iX = 0; iX < channels*height*width; ++iX)
114  {
115  hPE->Fill( (uint8_t)pixels[iX] );
116  hLabels->Fill(label);
117  }
118  if (count < 100)
119  {
120  outFile << "key " << it->key().ToString() << endl;
121  outFile << "count " << count << endl;
122  outFile << "label " << label << endl;
123 
124  TString hName = "PixelMap_";
125  hName += count;
126  hName += "_type";
127  hName += label;
128 
129  TH2D* xMap = new TH2D(hName + TString("_X"), ";Wire;TDC",
130  height, 0, height, width, 0, width);
131  XVec.push_back(xMap);
132  TH2D* yMap = new TH2D(hName + TString("_Y"), ";Wire;TDC",
133  height, 0, height, width, 0, width);
134  YVec.push_back(yMap);
135  TH2D* zMap = new TH2D(hName + TString("_Z"), ";Wire;TDC",
136  height, 0, height, width, 0, width);
137  ZVec.push_back(zMap);
138 
139  for (int iPix = 0; iPix < channels*height*width; ++iPix)
140  {
141  int iCell = iPix%width;
142  int iPlane = (iPix/width)%height;
143  int iChan = (iPix/width)/height;
144  int pixVal = (uint8_t)pixels[iPix];
145  if (iChan == 0)
146  {
147  xMap->SetBinContent(iPlane+1, iCell+1, pixVal);
148  }
149  if (iChan == 1)
150  {
151  yMap->SetBinContent(iPlane+1, iCell+1, pixVal);
152  }
153  if ( iChan == 2 )
154  {
155  zMap->SetBinContent(iPlane+1, iCell+1, pixVal);
156  }
157 
158  if (pixVal > 0)
159  {
160  if (iChan == 0)
161  {
162  outFile << "X " << iCell << " " << iPlane << endl;
163  }
164  else if (iChan == 1)
165  {
166  outFile << "Y " << iCell << " " << iPlane << endl;
167  }
168  else
169  {
170  outFile << "Z " << iCell << " " << iPlane << endl;
171  }
172  outFile << "[" << pixVal << "]" << endl;
173  }
174  }
175  }
176  }
177  else
178  {
179  break;
180  }
181  ++count;
182  }
183 
184  TFile* fOut = new TFile("test.root", "recreate");
185  fOut->WriteTObject(hPE);
186  fOut->WriteTObject(hLabels);
187  //gStyle->SetOptStat(0);
188  for (size_t i = 0; i < XVec.size(); ++i)
189  {
190  TString cName = "cPixelMap_";
191  cName += i;
192  TCanvas* canv = new TCanvas(cName, cName);
193  canv->Divide(3,1);
194  canv->cd(1);
195  std::cout<<XVec[i]->Integral()<<std::endl;
196  XVec[i]->Draw("colz");
197  canv->cd(2);
198  std::cout<<YVec[i]->Integral()<<std::endl;
199  YVec[i]->Draw("colz");
200  canv->cd(3);
201  std::cout<<ZVec[i]->Integral()<<std::endl;
202  ZVec[i]->Draw("colz");
203  fOut->WriteTObject(canv);
204  }
205 
206 
207  return 0;
208 }
std::string string
Definition: nybbler.cc:12
TFile * outFile
Definition: makeDST.cxx:36
po::variables_map getOptions(int argc, char *argv[], std::string &dir)
QTextStream & endl(QTextStream &s)