The Gaudi Framework  v36r1 (3e2fb5a8)
Tuples::ItemStore< VALUE > Class Template Referencefinal

#include <GaudiAlg/TuplePut.h>

Collaboration diagram for Tuples::ItemStore< VALUE >:

Public Member Functions

 ItemStore ()=default
 constructor : create empty map More...
 

Private Member Functions

NTuple::Item< VALUE > * getItem (std::string_view key, Tuples::TupleObj *tuple)
 the only one method: More...
 
 ItemStore (const ItemStore &)=delete
 
ItemStoreoperator= (const ItemStore &)=delete
 

Private Attributes

std::unordered_map< std::string_view, std::pair< NTuple::Item< VALUE >, std::string > > m_map
 the underlying map More...
 

Friends

class TupleObj
 

Detailed Description

template<class VALUE>
class Tuples::ItemStore< VALUE >

Simple class, which represents the local storage of N-tuple items of the given type. Essentially it is a restricted std::unordered_map with ownership of the newly created entries

Author
Vanya BELYAEV ibely.nosp@m.aev@.nosp@m.physi.nosp@m.cs.s.nosp@m.yr.ed.nosp@m.u
Date
2007-04-08

Definition at line 35 of file TuplePut.h.

Constructor & Destructor Documentation

◆ ItemStore() [1/2]

template<class VALUE >
Tuples::ItemStore< VALUE >::ItemStore ( )
default

constructor : create empty map

◆ ItemStore() [2/2]

template<class VALUE >
Tuples::ItemStore< VALUE >::ItemStore ( const ItemStore< VALUE > &  )
privatedelete

Member Function Documentation

◆ getItem()

template<class VALUE >
NTuple::Item<VALUE>* Tuples::ItemStore< VALUE >::getItem ( std::string_view  key,
Tuples::TupleObj tuple 
)
inlineprivate

the only one method:

Definition at line 44 of file TuplePut.h.

44  {
45  // find the item by name
46  auto ifound = m_map.find( key );
47  // existing item?
48  if ( m_map.end() != ifound ) return &ifound->second.first; // RETURN
49 
50  // check the tuple for booking:
51  if ( !tuple ) return nullptr;
52  // check the existence of the name
53  if ( !tuple->goodItem( key ) ) {
54  tuple->Error( fmt::format( "ItemStore::getItem('{}') item name is not unique", key ) ).ignore();
55  return nullptr; // RETURN
56  }
57  // get the underlying object
58  NTuple::Tuple* tup = tuple->tuple();
59  if ( !tup ) {
60  tuple->Error( fmt::format( "ItemStore::getItem('{}') invalid NTuple::Tuple*", key ) ).ignore();
61  return nullptr; // RETURN
62  }
63  // create new item:
64  // add the newly created item into the store -- and point the key view into the mapped value...
65  auto [iter, ok] = m_map.try_emplace( key, NTuple::Item<VALUE>{}, std::string{key} );
66  if ( ok ) {
67  auto nh = m_map.extract( iter );
68  nh.key() = nh.mapped().second; // "re-point" key to the string contained value_type
69  // std::tie( iter,ok,std::ignore) = m_map.insert( std::move( nh ) );
70  auto r = m_map.insert( std::move( nh ) );
71  iter = r.position;
72  ok = r.inserted;
73  }
74  if ( !ok ) {
75  tuple->Warning( fmt::format( "ItemStore::getItem('{}') item already exists, new one not inserted!", key ) )
76  .ignore();
77  return nullptr;
78  }
79  auto& item = iter->second.first;
80  // add it into N-tuple
81  StatusCode sc = tup->addItem( iter->second.second, item ); // ATTENTION!
82  if ( sc.isFailure() ) {
83  tuple->Error( fmt::format( "ItemStore::getItem('{}') cannot addItem", key ), sc ).ignore();
84  m_map.erase( iter );
85  return nullptr; // RETURN
86  }
87  // check the name again
88  if ( !tuple->addItem( iter->second.second, System::typeinfoName( typeid( VALUE ) ) ) ) {
89  tuple->Warning( fmt::format( "ItemStore::getItem('{}') the item not unique ", key ) ).ignore();
90  m_map.erase( iter );
91  return nullptr;
92  }
93  //
94  return &item; // RETURN
95  }

◆ operator=()

template<class VALUE >
ItemStore& Tuples::ItemStore< VALUE >::operator= ( const ItemStore< VALUE > &  )
privatedelete

Friends And Related Function Documentation

◆ TupleObj

template<class VALUE >
friend class TupleObj
friend

Definition at line 36 of file TuplePut.h.

Member Data Documentation

◆ m_map

template<class VALUE >
std::unordered_map<std::string_view, std::pair<NTuple::Item<VALUE>, std::string> > Tuples::ItemStore< VALUE >::m_map
private

the underlying map

Definition at line 102 of file TuplePut.h.


The documentation for this class was generated from the following file:
std::string
STL class.
std::move
T move(T... args)
Tuples::TupleObj::tuple
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
Definition: TupleObj.h:1862
Tuples::TupleObj::Error
virtual StatusCode Error(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
std::unordered_map::find
T find(T... args)
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:308
StatusCode
Definition: StatusCode.h:65
HistoDumpEx.r
r
Definition: HistoDumpEx.py:20
Tuples::ItemStore::m_map
std::unordered_map< std::string_view, std::pair< NTuple::Item< VALUE >, std::string > > m_map
the underlying map
Definition: TuplePut.h:102
std::unordered_map::erase
T erase(T... args)
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
NTuple::Tuple::addItem
StatusCode addItem(const std::string &name, Item< TYPE > &itm)
Add a scalar data item a N tuple.
Definition: NTuple.h:515
Tuples::TupleObj::goodItem
bool goodItem(std::string_view name) const
check the uniqueness of the name
Definition: TupleObj.h:1905
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:156
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:142
Tuples::TupleObj::addItem
bool addItem(std::string name, std::string type)
add the item name into the list of known items
Definition: TupleObj.h:1897
Tuples::TupleObj::Warning
virtual StatusCode Warning(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
NTuple::Tuple
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:387
std::unordered_map::insert
T insert(T... args)
std::unordered_map::end
T end(T... args)
ProduceConsume.key
key
Definition: ProduceConsume.py:52
NTuple::Item
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:58