CMS 3D CMS Logo

Public Member Functions | Private Attributes

ora::MultiIndexDataTrie Class Reference

#include <MultiIndexDataTrie.h>

List of all members.

Public Member Functions

size_t branchSize (const std::vector< int > &indexes, size_t depth=0) const
void clear ()
void lookupAndClear (const std::vector< int > &indexes, Record &rec)
 MultiIndexDataTrie ()
size_t push (const std::vector< int > &indexes, Record &data)
size_t size () const
size_t totalSize () const
virtual ~MultiIndexDataTrie ()

Private Attributes

std::vector< MultiIndexDataTrie * > m_children
Record m_data

Detailed Description

Definition at line 14 of file MultiIndexDataTrie.h.


Constructor & Destructor Documentation

ora::MultiIndexDataTrie::MultiIndexDataTrie ( )

Definition at line 8 of file MultiIndexDataTrie.cc.

                                         :
  m_children(),
  m_data(){
  
}
ora::MultiIndexDataTrie::~MultiIndexDataTrie ( ) [virtual]

Definition at line 14 of file MultiIndexDataTrie.cc.

References hitfit::clear().

                                          {
  clear();
}

Member Function Documentation

size_t ora::MultiIndexDataTrie::branchSize ( const std::vector< int > &  indexes,
size_t  depth = 0 
) const

Definition at line 110 of file MultiIndexDataTrie.cc.

References i, m_children, and ora::throwException().

                                                                                           {
  if( depth > indexes.size() ) depth = indexes.size();
  const MultiIndexDataTrie* trie = this;
  for( size_t i=0;i<depth;i++){
    if( indexes[i]+1 > (int)(trie->m_children.size())){
      // empty leaf
      if( i+2>=indexes.size())  return 0;
      // empty branches are not expected!
      std::stringstream mess;
      mess << "1 Index["<<i<<"] is out of bound.";
      throwException( mess.str(),"MultiIndexDataTrie::branchSize" );
    }
    trie = trie->m_children[indexes[i]];
    if( !trie ){
      std::stringstream mess;
      mess << "Slot for index["<<i<<"] is empty.";
      throwException( mess.str(),"MultiIndexDataTrie::branchSize" );      
    }
  }
  return trie->m_children.size();  
}
void ora::MultiIndexDataTrie::clear ( void  )

Definition at line 101 of file MultiIndexDataTrie.cc.

References ora::Record::swap(), and tmp.

                                 {
  for(std::vector<MultiIndexDataTrie*>::iterator iT = m_children.begin();
      iT != m_children.end(); iT++){
    if(*iT) delete *iT;
  }
  m_children.clear();
  Record tmp; tmp.swap(m_data);
}
void ora::MultiIndexDataTrie::lookupAndClear ( const std::vector< int > &  indexes,
Record rec 
)

coral::AttributeList& ora::MultiIndexDataTrie::lookup( const std::vector<int>& indexes ){ MultiIndexDataTrie* trie = this; for( size_t i=0;i<indexes.size();i++){ if( trie->m_children.size()==0 || indexes[i] > (int)(trie->m_children.size()-1)){ std::stringstream mess; mess << "Index["<<i<<"] is out of bound."; throwException( mess.str(),"MultiIndexDataTrie::lookup" ); } trie = trie->m_children[indexes[i]]; if( !trie ){ std::stringstream mess; mess << "Slot for index["<<i<<"] is empty."; throwException( mess.str(),"MultiIndexDataTrie::lookup" ); } } if(!trie->m_data.get()){ throwException( "No Data for the specified index combination.", "MultiIndexDataTrie::lookup" ); } return *trie->m_data; }

Definition at line 69 of file MultiIndexDataTrie.cc.

References i, python::Node::leaf, m_children, m_data, ora::Record::size(), ora::Record::swap(), and ora::throwException().

                                                                                        {
  MultiIndexDataTrie* branch = this;
  MultiIndexDataTrie* trie = 0;
  size_t i=0;
  for( ;i<indexes.size();i++){
    if( branch->m_children.size()==0 || indexes[i] > (int)(branch->m_children.size()-1)){
      std::stringstream mess;
      mess << "Index["<<i<<"] is out of bound.";
      throwException( mess.str(),"MultiIndexDataTrie::lookupAndClear" );
    }
    trie = branch;
    branch = branch->m_children[indexes[i]];
    if( !branch ){
      std::stringstream mess;
      mess << "Slot for index["<<i<<"] is empty.";
      throwException( mess.str(),"MultiIndexDataTrie::lookupAndClear" );      
    }
  }
  MultiIndexDataTrie* leaf = trie->m_children[indexes[i-1]];
  if(0==leaf->m_data.size()){
    throwException( "No Data for the specified index combination.",
                    "MultiIndexDataTrie::lookupAndClear" );
  }
  rec.swap(leaf->m_data);
  delete leaf;
  trie->m_children[indexes[i-1]] = 0;
}
size_t ora::MultiIndexDataTrie::push ( const std::vector< int > &  indexes,
Record data 
)

Definition at line 18 of file MultiIndexDataTrie.cc.

References i, j, m_children, m_data, nt, alignCSCRings::s, ora::Record::swap(), and ora::throwException().

                                                     {
  size_t s=0;
  MultiIndexDataTrie* trie = this;
  for( size_t i=0;i<indexes.size();i++){
    size_t ts = trie->m_children.size();
    MultiIndexDataTrie* nt = 0;
    if( ts == 0 || indexes[i] > (int)(ts-1) ){
      for(size_t j=0;j<indexes[i]-ts+1;j++){
        ++s;
        nt = new MultiIndexDataTrie;
        trie->m_children.push_back(nt);
      }
    } else {
      nt = trie->m_children[indexes[i]];
      if( !nt ){
        std::stringstream mess;
        mess << "Slot for index["<<i<<"] is empty.";
        throwException( mess.str(),"MultiIndexDataTrie::push" );
      }
    }
    trie = nt;
  }
  trie->m_data.swap(data);
  return s;
}
size_t ora::MultiIndexDataTrie::size ( void  ) const

Definition at line 97 of file MultiIndexDataTrie.cc.

                                         {
  return m_children.size();
}
size_t ora::MultiIndexDataTrie::totalSize ( ) const

Definition at line 132 of file MultiIndexDataTrie.cc.

                                              {
  size_t sz = 0;
  for(std::vector<MultiIndexDataTrie*>::const_iterator iT = m_children.begin();
      iT != m_children.end(); iT++){
    sz++;
    if(*iT) sz += (*iT)->totalSize();
  }
  return sz;
}

Member Data Documentation

Definition at line 36 of file MultiIndexDataTrie.h.

Referenced by branchSize(), lookupAndClear(), and push().

Definition at line 37 of file MultiIndexDataTrie.h.

Referenced by lookupAndClear(), and push().