Belle II Software  release-08-01-10
ParticleExtraInfoMap Class Reference

Internal class to store string -> index maps for extra info stored in Particle. More...

#include <ParticleExtraInfoMap.h>

Inheritance diagram for ParticleExtraInfoMap:
Collaboration diagram for ParticleExtraInfoMap:

Public Types

typedef std::map< std::string, unsigned int > IndexMap
 string -> index map.
 

Public Member Functions

const IndexMapgetMap (unsigned int mapID) const
 Return reference to map with given ID.
 
unsigned int getIndex (unsigned int mapID, const std::string &name) const
 Find index for name in the given map, or return 0 if not found.
 
unsigned int getMapForNewVar (const std::string &name)
 Return map ID to a map that has 'name' as first entry. More...
 
unsigned int getMapForNewVar (const std::string &name, unsigned int oldMapID, unsigned int insertIndex)
 Return map ID to a map that has 'name' at place 'insertIndex' and is compatible with previous map (in oldMapID) More...
 
unsigned int getNMaps () const
 How many maps do we use?
 

Private Member Functions

 ClassDef (ParticleExtraInfoMap, 1)
 Internal class to store string -> index maps for user-defined variables in Particle.
 

Static Private Member Functions

static bool isCompatible (const IndexMap &oldMap, const IndexMap &map, unsigned int insertIndex)
 check if all entries in 'oldMap' prior to insertIndex are found in 'map' (with same idx).
 

Private Attributes

std::vector< IndexMapm_maps
 List of string -> index maps.
 

Detailed Description

Internal class to store string -> index maps for extra info stored in Particle.

An object of this class is used to store all strings used to identify the values added using Particle::addExtraInfo() and keeps Particles fairly light (only values and a map ID are stored directly). The necessary indirection is handled automatically by Particle::getExtraInfo().

Modules registering a StoreArray<Particle> should always register a StoreObjPtr<ParticleExtraInfoMap> to allow storing additional information.

Definition at line 29 of file ParticleExtraInfoMap.h.

Member Function Documentation

◆ getMapForNewVar() [1/2]

unsigned int getMapForNewVar ( const std::string &  name)

Return map ID to a map that has 'name' as first entry.

Creates a new map if necessary.

Definition at line 25 of file ParticleExtraInfoMap.cc.

26 {
27  const unsigned int insertIndex = 1; //0 reserved
28  for (unsigned int iMap = 0; iMap < m_maps.size(); iMap++) {
29  const auto it = m_maps[iMap].find(name);
30  if (it != m_maps[iMap].end() and it->second == insertIndex)
31  return iMap;
32  }
33  //nothing found, add new map
34  IndexMap map;
35  map[name] = insertIndex;
36  m_maps.push_back(map);
37 
38  //return new index
39  return m_maps.size() - 1;
40 }
std::vector< IndexMap > m_maps
List of string -> index maps.
std::map< std::string, unsigned int > IndexMap
string -> index map.

◆ getMapForNewVar() [2/2]

unsigned int getMapForNewVar ( const std::string &  name,
unsigned int  oldMapID,
unsigned int  insertIndex 
)

Return map ID to a map that has 'name' at place 'insertIndex' and is compatible with previous map (in oldMapID)

Will reuse old map or another existing map if compatible, creates a new map if necessary.

Definition at line 42 of file ParticleExtraInfoMap.cc.


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