ATLAS Offline Software
CollectionPool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef COLLECTIONUTILITIES_COLLECTIONPOOL_H
6 #define COLLECTIONUTILITIES_COLLECTIONPOOL_H
7 
11 
12 #include <string>
13 #include <queue>
14 
15 
16 namespace pool
17 {
18 
19 /* This is a utility class to prevent running out of memory when too many
20  output collections are created.
21  It keeps a "window" of open collections, closing "old" ones when a new
22  one needs to be opened and reopening them on demand.
23  Rows are cached up to a certain limit if the collection is not opened.
24 
25  @author Marcin.Nowak@cern.ch
26 */
27 
28 
30  {
31  typedef std::vector< pool::CollectionRowBuffer > rowVect_t;
32 
33 
34  public:
35 
38  friend class CollectionPool;
39  public:
41  : m_cpool( cp ), m_iter( cp->m_rowCache.begin() ), m_end( cp->m_rowCache.end() ),
42  m_forceOpen( false )
43  {}
44 
45  void forceOpen( bool fo=true ) { m_forceOpen = fo; }
46 
49  bool isValid() { return m_iter != m_end; }
52  ICollection* ptr () { return operator->(); }
53 
54  protected:
58  };
59 
60 
61 
62  CollectionPool( unsigned maxOpen=50, unsigned cacheSize=100 ) ;
63  virtual ~CollectionPool();
64 
66  virtual void addCollection( const std::string& guid, ICollection* coll );
68  virtual ICollection* get( const std::string& guid );
70  virtual void insertRow( const std::string& guid , const pool::CollectionRowBuffer& row );
71 
72  virtual pool::CollectionRowBuffer& getRowBuffer( const std::string& );
73  virtual const std::string& getDstRefName();
74 
75  protected:
76 
78  void reduceQueue();
80 
81 
82  unsigned m_maxOpen;
83  unsigned m_rowCacheSize;
84  std::queue< pool::ICollection* > m_queue;
85  std::map< std::string, pool::ICollection* > m_map;
86  std::map< pool::ICollection*, rowVect_t > m_rowCache;
88  std::string m_dstRefName;
89  };
90 
91 }
92 
93 #endif
94 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
pool::CollectionPool::flushing_iterator::m_forceOpen
bool m_forceOpen
Definition: CollectionPool.h:57
query_example.row
row
Definition: query_example.py:24
pool::CollectionPool::m_rowBuffer
pool::CollectionRowBuffer m_rowBuffer
Definition: CollectionPool.h:87
pool::CollectionPool::flushing_iterator::flushing_iterator
flushing_iterator(CollectionPool *cp)
Definition: CollectionPool.h:40
TokenList.h
pool::CollectionPool::CollectionPool
CollectionPool(unsigned maxOpen=50, unsigned cacheSize=100)
pool::CollectionPool::flushing_iterator::isValid
bool isValid()
Definition: CollectionPool.h:49
pool
pool namespace
Definition: libname.h:15
pool::CollectionPool::m_dstRefName
std::string m_dstRefName
Definition: CollectionPool.h:88
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
pool::CollectionPool::m_rowCache
std::map< pool::ICollection *, rowVect_t > m_rowCache
Definition: CollectionPool.h:86
pool::CollectionPool::get
virtual ICollection * get(const std::string &guid)
get back which collection corresponds to a GUID
pool::CollectionPool::flushing_iterator::forceOpen
void forceOpen(bool fo=true)
Definition: CollectionPool.h:45
pool::CollectionPool::~CollectionPool
virtual ~CollectionPool()
pool::CollectionPool
Definition: CollectionPool.h:30
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SGout2dot.fo
fo
Definition: SGout2dot.py:88
pool::CollectionPool::flushing_iterator::operator++
flushing_iterator & operator++()
NOTE - the current collection can NOT be deleted before calling ++.
CollectionRowBuffer.h
pool::CollectionPool::insertRow
virtual void insertRow(const std::string &guid, const pool::CollectionRowBuffer &row)
insert row to a connection designated for a given GUID
ICollection.h
pool::CollectionPool::getDstRefName
virtual const std::string & getDstRefName()
pool::CollectionPool::m_queue
std::queue< pool::ICollection * > m_queue
Definition: CollectionPool.h:84
pool::CollectionPool::m_maxOpen
unsigned m_maxOpen
Definition: CollectionPool.h:82
pool::CollectionPool::flushing_iterator::m_end
std::map< ICollection *, rowVect_t >::iterator m_end
Definition: CollectionPool.h:56
pool_uuid.guid
guid
Definition: pool_uuid.py:112
pool::CollectionRowBuffer
Definition: CollectionRowBuffer.h:31
pool::CollectionPool::m_rowCacheSize
unsigned m_rowCacheSize
Definition: CollectionPool.h:83
LArNewCalib_PedestalAutoCorr.cp
cp
Definition: LArNewCalib_PedestalAutoCorr.py:175
pool::CollectionPool::getRowBuffer
virtual pool::CollectionRowBuffer & getRowBuffer(const std::string &)
pool::CollectionPool::flushing_iterator
iterator that flushes and closes all collections
Definition: CollectionPool.h:37
pool::CollectionPool::rowVect_t
std::vector< pool::CollectionRowBuffer > rowVect_t
Definition: CollectionPool.h:31
pool::CollectionPool::m_map
std::map< std::string, pool::ICollection * > m_map
Definition: CollectionPool.h:85
pool::CollectionPool::flushing_iterator::ptr
ICollection * ptr()
Definition: CollectionPool.h:52
pool::CollectionPool::flushing_iterator::operator*
ICollection & operator*()
Definition: CollectionPool.h:50
pool::CollectionPool::queueOpenColl
void queueOpenColl(pool::ICollection *coll)
pool::CollectionPool::flushing_iterator::m_iter
std::map< ICollection *, rowVect_t >::iterator m_iter
Definition: CollectionPool.h:56
pool::CollectionPool::flushing_iterator::operator->
ICollection * operator->()
pool::CollectionPool::flushing_iterator::m_cpool
CollectionPool * m_cpool
Definition: CollectionPool.h:55
pool::CollectionPool::reduceQueue
void reduceQueue()
pool::ICollection
Definition: ICollection.h:24
pool::CollectionPool::writeCache
void writeCache(pool::ICollection *coll)
pool::CollectionPool::addCollection
virtual void addCollection(const std::string &guid, ICollection *coll)
add GUID -> collection mapping