MINT2
HyperBinningMemRes.cpp
Go to the documentation of this file.
2 
3 
6 {
7  WELCOME_LOG << "Hello from the HyperBinningMemRes() Constructor";
8 }
9 
10 
11 
12 
16 
17  if (getDimension() == 0){
19  }
20 
21 }
22 
23 
24 std::vector<int> HyperBinningMemRes::getLinkedHyperVolumes( int volumeNumber ) const{
25 
26  return _linkedHyperVolumes.at(volumeNumber);
27 
28 }
29 
30 
32 
33  return dynamic_cast<BinningBase*>(new HyperBinningMemRes(*this));
34 
35 }
36 
37 
38 
42  _primaryVolumeNumbers.push_back(volumeNumber);
43 }
44 
45 
46 
50  return _hyperVolumes.size();
51 }
52 
53 
54 
56  return _primaryVolumeNumbers.size();
57 }
58 
60  return _primaryVolumeNumbers.at(i);
61 }
62 
65 bool HyperBinningMemRes::addHyperVolume(const HyperVolume& hyperVolume, std::vector<int> linkedVolumes){
66 
67  //If this is the first volume that has been added, use it to set the dimension
68  if (_hyperVolumes.size() == 0){
69  setDimension( hyperVolume.getDimension() );
70  }
71 
72  if (hyperVolume.getDimension() == getDimension()) {
73  _hyperVolumes.push_back(hyperVolume);
74  _linkedHyperVolumes.push_back(linkedVolumes);
75  updateCash();
76  return true;
77  }
78 
79  ERROR_LOG << "This HyperVolume has the wrong dimensionality for this HyperBinningMemRes";
80  return false;
81 
82 }
83 
84 
85 
86 
90 
91  TTree* tree = dynamic_cast<TTree*>( file->Get("PrimaryVolumeNumbers") );
92 
93  if (tree == 0){
94  ERROR_LOG << "Could not open TTree in HyperBinningMemRes::loadPrimaryVolumeNumbers()";
95  return;
96  }
97 
98  //Define branch addresses
99  int volumeNumber = -1;
100 
101  tree->SetBranchAddress("volumeNumber", &volumeNumber);
102 
103  //Loop over each Primary Volume
104  for(int i = 0; i < tree->GetEntries(); i++ ){
105  tree->GetEntry(i);
106  _primaryVolumeNumbers.push_back(volumeNumber);
107  }
108 
109 }
110 
113 void HyperBinningMemRes::setBranchAddresses(TTree* tree, int* binNumber, double* lowCorner, double* highCorner, std::vector<int>** linkedBins) const{
114 
115  tree->SetBranchAddress("binNumber", binNumber);
116  tree->SetBranchAddress("linkedBins", linkedBins);
117  for (int i = 0; i < getDimension(); i++) {
118  TString lowCornerName = "lowCorner_"; lowCornerName += i;
119  TString highCornerName = "highCorner_"; highCornerName += i;
120  tree->SetBranchAddress(lowCornerName, lowCorner + i);
121  tree->SetBranchAddress(highCornerName, highCorner + i);
122  }
123 
124 }
125 
126 
128  return _hyperVolumes.at(volumeNumber);
129 }
130 
131 
135  return _primaryVolumeNumbers;
136 }
137 
138 
141 void HyperBinningMemRes::load(TString filename, TString option){
142 
143  if (option != "READ"){
144  INFO_LOG << "For a memory resident HyperBinning you should always use the READ option. Setting to READ" << std::endl;
145  option = "READ";
146  }
147 
148  TFile* file = new TFile(filename, "READ");
149 
150  if (file == 0){
151  ERROR_LOG << "Could not open TFile in HyperBinningMemRes::load(" << filename << ")";
152  return;
153  }
154 
156 
157  TTree* tree = (TTree*)file->Get("HyperBinning");
158 
159  if (tree == 0){
160  ERROR_LOG << "Could not open TTree in HyperBinningMemRes::load()";
161  return;
162  }
163 
164  //Figure out how many dimensions there are from the tree
166 
167  //Create branch addresses and link them to TTree
168  int binNumber = -1;
169  double* lowCorner = new double [getDimension()];
170  double* highCorner = new double [getDimension()];
171  std::vector<int>* linkedBins = new std::vector<int>();
172 
173  setBranchAddresses(tree, &binNumber, lowCorner, highCorner, &linkedBins);
174 
175 
176  //Loop over the TTree and fill the HyperBinningMemRes
177  int nEntries = tree->GetEntries();
178 
179  int currentBinNumber = -1;
180  HyperVolume* currentHyperVolume = new HyperVolume(getDimension());
181  std::vector<int> currentLinkedVolumes;
182 
183  //_verbose = true;
184 
185  for(int ent = 0; ent < nEntries; ent++){
186  tree->GetEntry(ent);
187 
188  //If the bin number hasn't changed, need to
189  //add HyperCube to previous HyperVolume
190  if(ent == 0 || currentBinNumber == binNumber){
191  currentBinNumber = binNumber;
192  currentLinkedVolumes = *linkedBins;
193  HyperPoint lowCornerVect (getDimension());
194  HyperPoint highCornerVect(getDimension());
195  for (int i = 0; i < getDimension(); i++){
196  lowCornerVect .at(i) = lowCorner [i];
197  highCornerVect.at(i) = highCorner[i];
198  }
199  VERBOSE_LOG << "Adding cuboid to volume";
200  currentHyperVolume->addHyperCuboid(lowCornerVect, highCornerVect);
201  }
202 
203  //if the bin number has changed, need to add
204  //previous HyperVolume to HyperBinningMemRes
205  //and start a new HyperVolume
206  else {
207  VERBOSE_LOG << "Adding volume to binning";
208  this->addHyperVolume(*currentHyperVolume, currentLinkedVolumes);
209  delete currentHyperVolume;
210  currentHyperVolume = new HyperVolume(getDimension());
211  currentLinkedVolumes = *linkedBins;
212  currentBinNumber = binNumber;
213  HyperPoint lowCornerVect (getDimension());
214  HyperPoint highCornerVect(getDimension());
215  for (int i = 0; i < getDimension(); i++){
216  lowCornerVect .at(i) = lowCorner [i];
217  highCornerVect.at(i) = highCorner[i];
218  }
219  VERBOSE_LOG << "Adding cuboid to volume";
220  currentHyperVolume->addHyperCuboid(lowCornerVect, highCornerVect);
221  VERBOSE_LOG << "Adding linked volumes";
222 
223  }
224 
225  //if it's the final iteration, need to add the final HyperVolume
226  if (ent == nEntries - 1) {
227  this->addHyperVolume(*currentHyperVolume);
228  }
229  }
230 
231  VERBOSE_LOG << "Binning loaded";
232 
233  //_verbose = false;
234 
235  delete currentHyperVolume;
236  delete[] lowCorner;
237  delete[] highCorner;
238  delete linkedBins;
239 
240  updateCash();
241 
242  file->Close();
243 
244 }
245 
248  _hyperVolumes .reserve(nElements);
249  _linkedHyperVolumes.reserve(nElements);
250 }
251 
255  GOODBYE_LOG << "Goodbye from the HyperBinningMemRes() Constructor";
256 }
257 
258 
259 
virtual TString filename() const
Definition: BinningBase.cpp:57
virtual void load(TString filename, TString option="READ")
int getHyperBinningDimFromTree(TTree *tree)
#define INFO_LOG
virtual std::vector< int > getPrimaryVolumeNumbers() const
virtual void reserveCapacity(int nElements)
virtual int getNumPrimaryVolumes() const
virtual void reserveCapacity(int nElements)
#define ERROR_LOG
std::vector< HyperVolume > _hyperVolumes
void updateCash() const
#define VERBOSE_LOG
virtual void setDimension(int dimension)
Definition: BinningBase.cpp:34
const int & getDimension() const
Definition: HyperVolume.h:44
virtual BinningBase * clone() const
void loadPrimaryVolumeNumbers(TFile *file)
#define GOODBYE_LOG
std::vector< std::vector< int > > _linkedHyperVolumes
const int & getDimension() const
Definition: BinningBase.cpp:30
const double & at(int i) const
Definition: HyperPoint.cpp:433
virtual std::vector< int > getLinkedHyperVolumes(int volumeNumber) const
virtual int getPrimaryVolumeNumber(int i) const
#define WELCOME_LOG
virtual int getNumHyperVolumes() const
void addHyperCuboid(const HyperPoint &lowCorner, const HyperPoint &highCorner)
Definition: HyperVolume.cpp:91
void setBranchAddresses(TTree *tree, int *binNumber, double *lowCorner, double *highCorner, std::vector< int > **linkedBins) const
std::vector< int > _primaryVolumeNumbers
virtual void setDimension(int dim)
virtual void addPrimaryVolumeNumber(int volumeNumber)
virtual HyperVolume getHyperVolume(int volumeNumber) const
virtual bool addHyperVolume(const HyperVolume &hyperVolume, std::vector< int > linkedVolumes=std::vector< int >(0, 0))
HyperBinningMemRes()
The only constructor.