CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultiIndexDataTrie.cc
Go to the documentation of this file.
2 #include "MultiIndexDataTrie.h"
3 //
4 #include <sstream>
5 // externals
6 #include "CoralBase/AttributeList.h"
7 
9  m_children(),
10  m_data(){
11 
12 }
13 
15  clear();
16 }
17 
18 size_t ora::MultiIndexDataTrie::push( const std::vector<int>& indexes,
19  Record & data ){
20  size_t s=0;
21  MultiIndexDataTrie* trie = this;
22  for( size_t i=0;i<indexes.size();i++){
23  size_t ts = trie->m_children.size();
25  if( ts == 0 || indexes[i] > (int)(ts-1) ){
26  for(size_t j=0;j<indexes[i]-ts+1;j++){
27  ++s;
28  nt = new MultiIndexDataTrie;
29  trie->m_children.push_back(nt);
30  }
31  } else {
32  nt = trie->m_children[indexes[i]];
33  if( !nt ){
34  std::stringstream mess;
35  mess << "Slot for index["<<i<<"] is empty.";
36  throwException( mess.str(),"MultiIndexDataTrie::push" );
37  }
38  }
39  trie = nt;
40  }
41  trie->m_data.swap(data);
42  return s;
43 }
44 
69 void ora::MultiIndexDataTrie::lookupAndClear( const std::vector<int>& indexes, Record & rec ) {
70  MultiIndexDataTrie* branch = this;
71  MultiIndexDataTrie* trie = 0;
72  size_t i=0;
73  for( ;i<indexes.size();i++){
74  if( branch->m_children.size()==0 || indexes[i] > (int)(branch->m_children.size()-1)){
75  std::stringstream mess;
76  mess << "Index["<<i<<"] is out of bound.";
77  throwException( mess.str(),"MultiIndexDataTrie::lookupAndClear" );
78  }
79  trie = branch;
80  branch = branch->m_children[indexes[i]];
81  if( !branch ){
82  std::stringstream mess;
83  mess << "Slot for index["<<i<<"] is empty.";
84  throwException( mess.str(),"MultiIndexDataTrie::lookupAndClear" );
85  }
86  }
87  MultiIndexDataTrie* leaf = trie->m_children[indexes[i-1]];
88  if(0==leaf->m_data.size()){
89  throwException( "No Data for the specified index combination.",
90  "MultiIndexDataTrie::lookupAndClear" );
91  }
92  rec.swap(leaf->m_data);
93  delete leaf;
94  trie->m_children[indexes[i-1]] = 0;
95 }
96 
98  return m_children.size();
99 }
100 
102  for(std::vector<MultiIndexDataTrie*>::iterator iT = m_children.begin();
103  iT != m_children.end(); iT++){
104  if(*iT) delete *iT;
105  }
106  m_children.clear();
107  Record tmp; tmp.swap(m_data);
108 }
109 
110 size_t ora::MultiIndexDataTrie::branchSize( const std::vector<int>& indexes, size_t depth ) const{
111  if( depth > indexes.size() ) depth = indexes.size();
112  const MultiIndexDataTrie* trie = this;
113  for( size_t i=0;i<depth;i++){
114  if( indexes[i]+1 > (int)(trie->m_children.size())){
115  // empty leaf
116  if( i+2>=indexes.size()) return 0;
117  // empty branches are not expected!
118  std::stringstream mess;
119  mess << "1 Index["<<i<<"] is out of bound.";
120  throwException( mess.str(),"MultiIndexDataTrie::branchSize" );
121  }
122  trie = trie->m_children[indexes[i]];
123  if( !trie ){
124  std::stringstream mess;
125  mess << "Slot for index["<<i<<"] is empty.";
126  throwException( mess.str(),"MultiIndexDataTrie::branchSize" );
127  }
128  }
129  return trie->m_children.size();
130 }
131 
133  size_t sz = 0;
134  for(std::vector<MultiIndexDataTrie*>::const_iterator iT = m_children.begin();
135  iT != m_children.end(); iT++){
136  sz++;
137  if(*iT) sz += (*iT)->totalSize();
138  }
139  return sz;
140 }
141 
142 
int i
Definition: DBlmapReader.cc:9
size_t push(const std::vector< int > &indexes, Record &data)
size_t size() const
Definition: Record.cc:85
void lookupAndClear(const std::vector< int > &indexes, Record &rec)
void swap(Record &lh)
Definition: Record.cc:79
std::vector< MultiIndexDataTrie * > m_children
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
tuple leaf
Definition: Node.py:62
int j
Definition: DBlmapReader.cc:9
size_t branchSize(const std::vector< int > &indexes, size_t depth=0) const
int nt
Definition: AMPTWrapper.h:32
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10