MINT2
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
HyperBinningDiskRes Class Reference

#include <HyperBinningDiskRes.h>

Inheritance diagram for HyperBinningDiskRes:
HyperBinning BinningBase

Public Member Functions

 HyperBinningDiskRes ()
 
 HyperBinningDiskRes (const HyperBinningDiskRes &other)
 
virtual ~HyperBinningDiskRes ()
 
virtual void reserveCapacity (int nElements)
 
virtual void setDimension (int dim)
 
virtual void addPrimaryVolumeNumber (int volumeNumber)
 
virtual bool addHyperVolume (const HyperVolume &hyperVolume, std::vector< int > linkedVolumes=std::vector< int >(0, 0))
 
virtual int getNumHyperVolumes () const
 
virtual HyperVolume getHyperVolume (int volumeNumber) const
 Get a HyperVolume from its volume number. More...
 
virtual std::vector< int > getLinkedHyperVolumes (int volumeNumber) const
 
virtual int getNumPrimaryVolumes () const
 
virtual int getPrimaryVolumeNumber (int i) const
 
virtual bool isDiskResident () const
 
virtual TString filename () const
 
virtual void load (TString filename, TString option="READ")
 
virtual BinningBaseclone () const
 Create a clone of the object and return a pointer to it. More...
 
- Public Member Functions inherited from HyperBinning
 HyperBinning ()
 The only constructor. More...
 
bool isPrimaryVolume (int volumeNumber) const
 
int getHyperVolumeNumber (int binNumber) const
 
int getBinNum (int volumeNumber) const
 
virtual std::vector< int > getPrimaryVolumeNumbers () const
 
virtual ~HyperBinning ()
 
virtual void save (TString filename) const
 
virtual void save () const
 
virtual void mergeBinnings (const BinningBase &other)
 
virtual int getNumBins () const
 
virtual int getBinNum (const HyperPoint &coords) const
 
virtual std::vector< int > getBinNum (const HyperPointSet &coords) const
 
std::vector< int > getBinNumAlt (const HyperPointSet &coords) const
 
virtual HyperVolume getBinHyperVolume (int binNumber) const
 
virtual HyperPoint getAverageBinWidth () const
 
virtual HyperCuboid getLimits () const
 
- Public Member Functions inherited from BinningBase
 BinningBase ()
 
void setNames (HyperName names)
 
HyperName getNames () const
 
const int & getDimension () const
 
double getMin (int dimension) const
 
double getMax (int dimension) const
 
TString getBinningType () const
 
bool isSameBinningType (const BinningBase &other) const
 
virtual ~BinningBase ()
 

Protected Member Functions

void getEntry (int volumeNumber) const
 
void loadHyperBinningTree ()
 
void loadPrimaryVolumeTree ()
 
void createHyperBinningTree ()
 
void createPrimaryVolumeTree ()
 
- Protected Member Functions inherited from HyperBinning
int followBinLinks (const HyperPoint &coords, int binNumber) const
 
void updateCash () const
 
void updateBinNumbering () const
 
void updateAverageBinWidth () const
 
void updateMinMax () const
 
int getHyperBinningDimFromTree (TTree *tree)
 
void createBranches (TTree *tree, int *binNumber, double *lowCorner, double *highCorner, std::vector< int > **linkedBins) const
 
void saveHyperVolumeToTree (TTree *tree, double *lowCorner, double *highCorner, const HyperVolume &hyperVolume) const
 
void savePrimaryVolumeNumbers () const
 
- Protected Member Functions inherited from BinningBase
void setBinningType (TString binningType)
 

Private Attributes

TFile * _file
 
bool _writeable
 
TTree * _tree
 
HyperCuboid _cuboid
 
std::vector< int > * _linkedBins
 
int _volumeNumber
 
int _currentEntry
 
TTree * _treePrimVol
 
int _primVolNum
 

Detailed Description

HyperPlot, Author: Sam Harnew, sam.h.nosp@m.arne.nosp@m.w@gma.nosp@m.il.c.nosp@m.om , Date: Dec 2015

HyperBinningDiskRes is a binning scheme where each bin volume is defined by a HyperVolume.

Finding the correct bin number is quite a compuationally slow process if one has to loop over every bin and check if a HyperPoint falls within that bin volume. It's not unusual to have millions of HyperPoints that need to be sorted into tens of thousands of bins. This would require billions of calulations. To speed this process up there is the option to build a hierarchy of bins. A schematic below shows a 1D example.

HyperVolume Numbers
|-------------0-------------|
|------1------|------2------|
|--3---|---4--|---5---|--6--|
|-7-|-8|
Bin Numbers
| 0 | 1| 2 | 3 | 4 |

Imagine we have a HyperPoint that falls into Bin 0. One would first check if it falls into HyperVolume 0 (note the distiction here between Bin/HyperVolume Numbers as indicated by the figure). First we check if it falls into HyperVolume 0, then HyperVolume 1 or 2, then HyperVolume 3 or 4, then HyperVolume 7 or 8.

In this simple example, it took 7 operations, whereas checking each Bin would have taken

  1. Clearly as the number of bins increases, it becomes computationally much less expensive to follow this hierarchy approach.

The

Definition at line 81 of file HyperBinningDiskRes.h.

Constructor & Destructor Documentation

◆ HyperBinningDiskRes() [1/2]

HyperBinningDiskRes::HyperBinningDiskRes ( )

The empty constuctor. Must call the load function to associate this object to a file

Definition at line 6 of file HyperBinningDiskRes.cpp.

6  :
7  _file(0),
8  _writeable(false),
9  _tree(0),
10  _cuboid(0),
11  _linkedBins(new std::vector<int>()),
12  _volumeNumber(-1),
13  _currentEntry(-1),
14  _treePrimVol(0),
15  _primVolNum(-1)
16 {
17  WELCOME_LOG << "Hello from the HyperBinningDiskRes() Constructor";
18 }
#define WELCOME_LOG
std::vector< int > * _linkedBins

◆ HyperBinningDiskRes() [2/2]

HyperBinningDiskRes::HyperBinningDiskRes ( const HyperBinningDiskRes other)

The copy constuctor. Essentially just calls the empty constuctor, then loads from the same file as the other binning.

Definition at line 22 of file HyperBinningDiskRes.cpp.

22  :
23  _file(0),
24  _writeable(false),
25  _tree(0),
26  _cuboid(0),
27  _linkedBins(new std::vector<int>()),
28  _volumeNumber(-1),
29  _currentEntry(-1),
30  _treePrimVol(0),
31  _primVolNum(-1)
32 {
33  if (other._writeable == true){
34  other._file->Write();
35  }
36  load(other._file->GetName(), "READ");
37 }
virtual void load(TString filename, TString option="READ")
std::vector< int > * _linkedBins

◆ ~HyperBinningDiskRes()

HyperBinningDiskRes::~HyperBinningDiskRes ( )
virtual

Destructor

Definition at line 334 of file HyperBinningDiskRes.cpp.

334  {
335  GOODBYE_LOG << "Goodbye from the HyperBinningDiskRes() Constructor";
336 
337  if (_file != 0) {
338  _file->cd();
339  if (_writeable == true){
340  _tree ->Write();
341  _treePrimVol->Write();
342  }
343  _file->Close();
344  _file = 0;
345  }
346 
347  delete _linkedBins;
348 
349 }
#define GOODBYE_LOG
std::vector< int > * _linkedBins

Member Function Documentation

◆ addHyperVolume()

bool HyperBinningDiskRes::addHyperVolume ( const HyperVolume hyperVolume,
std::vector< int >  linkedVolumes = std::vector<int>(0, 0) 
)
virtual

Add a HyperVolume and its linked bins to the HyperBinning

Implements HyperBinning.

Definition at line 133 of file HyperBinningDiskRes.cpp.

133  {
134 
135  if (_writeable == false){
136  ERROR_LOG << "HyperBinningDiskRes::addHyperVolume - Cannot write, you must have opened in READ mode" << std::endl;
137  return false;
138  }
139 
140  //If dimension hasn't been set, and it's a writeable, we can now
141  //set the dimesnion and create the tree
142 
143  if (getDimension() == 0 && _writeable == true){
144  setDimension(hyperVolume.getDimension());
146  }
147 
148  if (_tree == 0){
149  ERROR_LOG << "HyperBinningDiskRes::addHyperVolume - Cannot find tree" << std::endl;
150  return false;
151  }
152 
153  int nVolumes = getNumHyperVolumes();
154  for (int i = 0; i < hyperVolume.size(); i++){
155  *_linkedBins = linkedVolumes;
156  _cuboid = hyperVolume.at(i);
157  _volumeNumber = nVolumes;
158  _tree->Fill();
159  }
160 
161  updateCash();
162 
163  return true;
164 }
virtual void setDimension(int dim)
const HyperCuboid & at(int i) const
Definition: HyperVolume.h:55
int size() const
Definition: HyperVolume.h:60
#define ERROR_LOG
void updateCash() const
const int & getDimension() const
Definition: HyperVolume.h:44
const int & getDimension() const
Definition: BinningBase.cpp:30
virtual int getNumHyperVolumes() const
std::vector< int > * _linkedBins

◆ addPrimaryVolumeNumber()

void HyperBinningDiskRes::addPrimaryVolumeNumber ( int  volumeNumber)
virtual

Add a primary volume number

Implements HyperBinning.

Definition at line 104 of file HyperBinningDiskRes.cpp.

104  {
105 
106  if (_writeable == false){
107  ERROR_LOG << "HyperBinningDiskRes::addPrimaryVolumeNumber - Cannot write, you must have opened in READ mode" << std::endl;
108  return;
109  }
110  if (_treePrimVol == 0){
111  ERROR_LOG << "HyperBinningDiskRes::addPrimaryVolumeNumber - Cannot find tree" << std::endl;
112  return;
113  }
114 
115  _primVolNum = volumeNumber;
116  _treePrimVol->Fill();
117 }
#define ERROR_LOG

◆ clone()

BinningBase * HyperBinningDiskRes::clone ( ) const
virtual

Create a clone of the object and return a pointer to it.

Implements HyperBinning.

Definition at line 80 of file HyperBinningDiskRes.cpp.

80  {
81 
82  BinningBase* ret = dynamic_cast<BinningBase*>(new HyperBinningDiskRes());
83 
84  if (_file != 0) {
85 
86  TString filenm = filename();
87  _file->cd();
88 
89  if (_writeable == true){
90  _file->Write();
91  }
92 
93  ret->load(filenm, "READ");
94 
95  }
96 
97  return ret;
98 
99 }
virtual void load(TString filename, TString option="READ")=0
virtual TString filename() const

◆ createHyperBinningTree()

void HyperBinningDiskRes::createHyperBinningTree ( )
protected

Definition at line 228 of file HyperBinningDiskRes.cpp.

228  {
229 
230  _file->cd();
231  _tree = new TTree("HyperBinning", "HyperBinning");
232 
233  if (_treePrimVol == 0){
234  ERROR_LOG << "HyperBinningDiskRes::createHyperBinningTree - could not open TTree";
235  return;
236  }
237 
238  //Figure out how many dimensions there are from the tree
239  int dim = getDimension();
240  if (dim == 0){
241  ERROR_LOG << "The dimesion has not yet been set, so I cannot createHyperBinningTree!!" << std::endl;
242  return;
243  }
244 
245  _tree->Branch("binNumber" , &_volumeNumber );
246  _tree->Branch("linkedBins", &_linkedBins );
247 
248  for (int i = 0; i < dim; i++){
249  TString lowCornerName = "lowCorner_" ; lowCornerName += i;
250  TString highCornerName = "highCorner_"; highCornerName += i;
251  _tree->Branch(lowCornerName , &_cuboid.getLowCorner ().at(i) );
252  _tree->Branch(highCornerName, &_cuboid.getHighCorner().at(i) );
253  }
254 
255  //random access is really slow. Thought this might help
256  //_tree->SetMaxVirtualSize(1000);
257 
258  _currentEntry = -1;
259  updateCash();
260 
261 }
#define ERROR_LOG
void updateCash() const
const HyperPoint & getHighCorner() const
Definition: HyperCuboid.h:89
const int & getDimension() const
Definition: BinningBase.cpp:30
const double & at(int i) const
Definition: HyperPoint.cpp:433
const HyperPoint & getLowCorner() const
Definition: HyperCuboid.h:87
std::vector< int > * _linkedBins

◆ createPrimaryVolumeTree()

void HyperBinningDiskRes::createPrimaryVolumeTree ( )
protected

Definition at line 263 of file HyperBinningDiskRes.cpp.

263  {
264 
265  _file->cd();
266  _treePrimVol = new TTree("PrimaryVolumeNumbers", "PrimaryVolumeNumbers");
267 
268  if (_treePrimVol == 0){
269  ERROR_LOG << "HyperBinningDiskRes::createPrimaryVolumeTree - could not open TTree";
270  return;
271  }
272 
273  _treePrimVol->Branch("volumeNumber", &_primVolNum);
274 
275 }
#define ERROR_LOG

◆ filename()

TString HyperBinningDiskRes::filename ( ) const
virtual

Reimplemented from BinningBase.

Definition at line 317 of file HyperBinningDiskRes.cpp.

317  {
318  if (_file == 0){
319  ERROR_LOG << "HyperBinningDiskRes::filename - there is no file associated to this object yet" << std::endl;
320  return "";
321  }
322  return _file->GetName();
323 }
#define ERROR_LOG

◆ getEntry()

void HyperBinningDiskRes::getEntry ( int  volumeNumber) const
protected

Get a HyperVolume from the tree and load it into memory

Definition at line 55 of file HyperBinningDiskRes.cpp.

55  {
56  if (_tree == 0){
57  ERROR_LOG << "HyperBinningDiskRes::getEntry - tree doesn't exist" << std::endl;
58  return;
59  }
60  if ( _currentEntry != volumeNumber ){
61  _currentEntry = volumeNumber;
62  _tree->GetEntry(volumeNumber);
63  }
64 }
#define ERROR_LOG

◆ getHyperVolume()

HyperVolume HyperBinningDiskRes::getHyperVolume ( int  volumeNumber) const
virtual

Get a HyperVolume from its volume number.

get one of the HyperVolumes

Implements HyperBinning.

Definition at line 67 of file HyperBinningDiskRes.cpp.

67  {
68  getEntry(volumeNumber);
69  return HyperVolume(_cuboid);
70 }
void getEntry(int volumeNumber) const

◆ getLinkedHyperVolumes()

std::vector< int > HyperBinningDiskRes::getLinkedHyperVolumes ( int  volumeNumber) const
virtual

Get all HyperVolumes linked to a specific volume number i.e. from the binning hiearcy

Implements HyperBinning.

Definition at line 74 of file HyperBinningDiskRes.cpp.

74  {
75  getEntry(volumeNumber);
76  return *_linkedBins;
77 }
void getEntry(int volumeNumber) const
std::vector< int > * _linkedBins

◆ getNumHyperVolumes()

int HyperBinningDiskRes::getNumHyperVolumes ( ) const
virtual

Get the number of HyperVolumes (this is not the number of bins)

Implements HyperBinning.

Definition at line 123 of file HyperBinningDiskRes.cpp.

123  {
124  if (_tree == 0){
125  return 0;
126  }
127  return _tree->GetEntries();
128 }

◆ getNumPrimaryVolumes()

int HyperBinningDiskRes::getNumPrimaryVolumes ( ) const
virtual

Get the number of primary volumes

Implements HyperBinning.

Definition at line 169 of file HyperBinningDiskRes.cpp.

169  {
170  if (_treePrimVol == 0) return 0;
171  return _treePrimVol->GetEntries();
172 }

◆ getPrimaryVolumeNumber()

int HyperBinningDiskRes::getPrimaryVolumeNumber ( int  i) const
virtual

Get the primary volume numbers

Implements HyperBinning.

Definition at line 176 of file HyperBinningDiskRes.cpp.

176  {
177  if (_treePrimVol == 0) {
178  ERROR_LOG << "HyperBinningDiskRes::getPrimaryVolumeNumber - No tree found" << std::endl;
179  }
180  _treePrimVol->GetEntry(i);
181  return _primVolNum;
182 }
#define ERROR_LOG

◆ isDiskResident()

bool HyperBinningDiskRes::isDiskResident ( ) const
virtual

Reimplemented from BinningBase.

Definition at line 314 of file HyperBinningDiskRes.cpp.

314  {
315  return true;
316 }

◆ load()

void HyperBinningDiskRes::load ( TString  filename,
TString  option = "READ" 
)
virtual

Load HyperBinningDiskRes from a file

Implements HyperBinning.

Definition at line 279 of file HyperBinningDiskRes.cpp.

279  {
280 
281  _writeable = false;
282  if (option == "UPDATE" || option == "RECREATE") {
283  _writeable = true;
284  }
285 
286  if (_file != 0) _file->Close();
287 
288  _file = new TFile(filename, option);
289 
290  if (_file == 0){
291  ERROR_LOG << "Could not open TFile in HyperBinningDiskRes::load(" << filename << ")";
292  return;
293  }
294 
295  if (option == "UPDATE" || option == "READ"){
298  }
299  else if (option == "RECREATE"){
300  //if we're opening a new file, we don't know the dimension yet.
301  //wait until the dimension is set explicitly with setDimension().
302  //createHyperBinningTree ();
304  }
305  else{
306  ERROR_LOG << "There are only three load options (READ, RECREATE, UPDATE) - You have selected " << option << std::endl;
307  return;
308  }
309 
310  INFO_LOG << "Sucessfully attached Disk Resident HyperBinning to file " << filename << std::endl;
311 
312 }
#define INFO_LOG
#define ERROR_LOG
virtual TString filename() const

◆ loadHyperBinningTree()

void HyperBinningDiskRes::loadHyperBinningTree ( )
protected

Definition at line 185 of file HyperBinningDiskRes.cpp.

185  {
186 
187  _tree = dynamic_cast<TTree*>(_file->Get("HyperBinning"));
188 
189  if (_tree == 0){
190  ERROR_LOG << "Could not open TTree in HyperBinningDiskRes::load()";
191  return;
192  }
193 
194  //Figure out how many dimensions there are from the tree
196 
197  _tree->SetBranchAddress("binNumber" , &_volumeNumber);
198  _tree->SetBranchAddress("linkedBins", &_linkedBins );
199 
200  for (int i = 0; i < getDimension(); i++){
201  TString lowCornerName = "lowCorner_" ; lowCornerName += i;
202  TString highCornerName = "highCorner_"; highCornerName += i;
203  _tree->SetBranchAddress(lowCornerName , &_cuboid.getLowCorner ().at(i) );
204  _tree->SetBranchAddress(highCornerName, &_cuboid.getHighCorner().at(i) );
205  }
206 
207  //_tree->SetMaxVirtualSize(1000);
208  _currentEntry = -1;
209  updateCash();
210 
211 }
int getHyperBinningDimFromTree(TTree *tree)
virtual void setDimension(int dim)
#define ERROR_LOG
void updateCash() const
const HyperPoint & getHighCorner() const
Definition: HyperCuboid.h:89
const int & getDimension() const
Definition: BinningBase.cpp:30
const double & at(int i) const
Definition: HyperPoint.cpp:433
const HyperPoint & getLowCorner() const
Definition: HyperCuboid.h:87
std::vector< int > * _linkedBins

◆ loadPrimaryVolumeTree()

void HyperBinningDiskRes::loadPrimaryVolumeTree ( )
protected

Definition at line 215 of file HyperBinningDiskRes.cpp.

215  {
216 
217  _treePrimVol = dynamic_cast<TTree*>( _file->Get("PrimaryVolumeNumbers") );
218 
219  if (_treePrimVol == 0){
220  ERROR_LOG << "HyperBinningDiskRes::loadPrimaryVolumeNumbers - could not open TTree";
221  return;
222  }
223 
224  _treePrimVol->SetBranchAddress("volumeNumber", &_primVolNum);
225 
226 }
#define ERROR_LOG

◆ reserveCapacity()

void HyperBinningDiskRes::reserveCapacity ( int  nElements)
virtual

Reimplemented from HyperBinning.

Definition at line 325 of file HyperBinningDiskRes.cpp.

325  {
326  HyperBinning::reserveCapacity(nElements);
327 
328 }
virtual void reserveCapacity(int nElements)

◆ setDimension()

void HyperBinningDiskRes::setDimension ( int  dim)
virtual

Set the dimension of the HyperBinningDiskRes. This can only be called once, when it is known what the dimension is i.e. either when loading from a file, or the first time a HyperVolume is added to an empty file

Reimplemented from HyperBinning.

Definition at line 44 of file HyperBinningDiskRes.cpp.

44  {
45 
46  if (getDimension() == 0){
48  _cuboid = HyperCuboid(dim);
49  }
50 
51 }
const int & getDimension() const
Definition: BinningBase.cpp:30
virtual void setDimension(int dim)

Member Data Documentation

◆ _cuboid

HyperCuboid HyperBinningDiskRes::_cuboid
mutableprivate

Definition at line 89 of file HyperBinningDiskRes.h.

◆ _currentEntry

int HyperBinningDiskRes::_currentEntry
mutableprivate

Definition at line 92 of file HyperBinningDiskRes.h.

◆ _file

TFile* HyperBinningDiskRes::_file
mutableprivate

Definition at line 85 of file HyperBinningDiskRes.h.

◆ _linkedBins

std::vector<int>* HyperBinningDiskRes::_linkedBins
mutableprivate

Definition at line 90 of file HyperBinningDiskRes.h.

◆ _primVolNum

int HyperBinningDiskRes::_primVolNum
mutableprivate

Definition at line 95 of file HyperBinningDiskRes.h.

◆ _tree

TTree* HyperBinningDiskRes::_tree
mutableprivate

Definition at line 88 of file HyperBinningDiskRes.h.

◆ _treePrimVol

TTree* HyperBinningDiskRes::_treePrimVol
mutableprivate

Definition at line 94 of file HyperBinningDiskRes.h.

◆ _volumeNumber

int HyperBinningDiskRes::_volumeNumber
mutableprivate

Definition at line 91 of file HyperBinningDiskRes.h.

◆ _writeable

bool HyperBinningDiskRes::_writeable
private

Definition at line 86 of file HyperBinningDiskRes.h.


The documentation for this class was generated from the following files: