ATLAS Offline Software
ArenaHeader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: ArenaHeader.cxx 470529 2011-11-24 23:54:22Z ssnyder $
19 #include <algorithm>
20 #include <ostream>
21 #include <sstream>
22 #include <cassert>
23 
24 
25 namespace SG {
26 
27 
29 
30 
35  // m_arena doesn't own the objects to which it points.
36  // Need to pass in a dummy deleter to prevent them from being deleted.
37  : m_arena (null_arena_deleter)
38 {
39 }
40 
41 
48 {
49  // We don't own this.
50  m_arena.release();
51 }
52 
53 
60 {
61  ArenaBase* ret = m_arena.get();
62  m_arena.release();
63  m_arena.reset (arena);
64  return ret;
65 }
66 
67 
73 {
74  std::lock_guard<std::mutex> lock (m_mutex);
75  m_arenas.push_back (a);
76 }
77 
78 
85 {
86  if (slot < 0) return;
87  std::lock_guard<std::mutex> lock (m_mutex);
88  if (slot >= static_cast<int> (m_slots.size())) {
89  m_slots.resize (slot+1);
90  }
91  m_slots[slot] = a;
92 }
93 
94 
102 {
103  std::lock_guard<std::mutex> lock (m_mutex);
105  std::find (m_arenas.begin(), m_arenas.end(), a);
106  assert (it != m_arenas.end());
107  m_arenas.erase (it);
108 }
109 
110 
115 void ArenaHeader::report (std::ostream& os) const
116 {
117  std::lock_guard<std::mutex> lock (m_mutex);
118  // All Allocators in the group.
119  for (ArenaBase* arena : m_arenas) {
120  os << "=== " << arena->name() << " ===" << std::endl;
121  arena->report (os);
122  }
123 
124  // The default Arena.
125  os << "=== default ===" << std::endl;
127 }
128 
129 
137 std::string ArenaHeader::reportStr() const
138 {
139  std::ostringstream s;
140  report (s);
141  return s.str();
142 }
143 
144 
154 {
155  if (m_arena.get()) {
156  m_arena->reset();
157  }
158 }
159 
160 
165 {
167  return &head;
168 }
169 
170 
171 } // namespace SG
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
SG::ArenaHeader::~ArenaHeader
~ArenaHeader()
Destructor.
Definition: ArenaHeader.cxx:47
SG::null_arena_deleter
void null_arena_deleter(ArenaBase *)
Definition: ArenaHeader.cxx:28
SG::ArenaHeader::m_mutex
std::mutex m_mutex
Mutex to protect access to m_defaultArena, m_arenas, and m_slots.
Definition: ArenaHeader.h:171
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
SG::ArenaHeader::setArenaForSlot
void setArenaForSlot(int slot, ArenaBase *a)
Record the arena associated with an event slot.
Definition: ArenaHeader.cxx:84
skel.it
it
Definition: skel.GENtoEVGEN.py:396
SG::ArenaBase::report
void report(std::ostream &os) const
Generate a report of the memory in use by this Arena.
Definition: ArenaBase.cxx:76
SG::ArenaHeader::reportStr
std::string reportStr() const
Generate a report of all Arenas in the group, and return the result as a string.
Definition: ArenaHeader.cxx:137
ArenaHeader.h
Proxy for a group of Arenas. See Arena.h for an overview of the arena-based memory allocators.
SG::ArenaHeader::report
void report(std::ostream &os) const
Generate a report of all Arenas in the group.
Definition: ArenaHeader.cxx:115
SG::ArenaHeader
Proxy for a group of Arenas.
Definition: ArenaHeader.h:54
ArenaAllocatorBase.h
Common base class for arena allocator classes. See Arena.h for an overview of the arena-based memory ...
SG::ArenaHeader::reset
void reset()
Call reset on all Allocators in the current Arena.
Definition: ArenaHeader.cxx:153
SG::ArenaBase
Part of Arena dealing with the list of allocators.
Definition: ArenaBase.h:42
SG::ArenaHeader::m_arena
boost::thread_specific_ptr< ArenaBase > m_arena
Current Arena.
Definition: ArenaHeader.h:159
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
head
std::string head(std::string s, const std::string &pattern)
head of a string
Definition: computils.cxx:310
SG::ArenaHeader::ArenaHeader
ArenaHeader()
Constructor.
Definition: ArenaHeader.cxx:34
SG::ArenaHeader::m_slots
std::vector< ArenaBase * > m_slots
Arenas indexed by event slot.
Definition: ArenaHeader.h:168
SG::ArenaHeader::defaultHeader
static ArenaHeader * defaultHeader()
Return the global default Header instance.
Definition: ArenaHeader.cxx:164
ArenaBase.h
Part of Arena dealing with the list of allocators. Broken out from Arena to avoid a dependency loop w...
a
TList * a
Definition: liststreamerinfos.cxx:10
SG::ArenaHeader::m_arenas
std::vector< ArenaBase * > m_arenas
List of all Arenas in our group.
Definition: ArenaHeader.h:165
SG::ArenaHeader::delArena
void delArena(ArenaBase *a)
Remove an Arena from the group.
Definition: ArenaHeader.cxx:101
SG::ArenaHeader::setArena
ArenaBase * setArena(ArenaBase *arena)
Set the current Arena for the current thread.
Definition: ArenaHeader.cxx:59
SG::ArenaHeader::m_defaultArena
ArenaBase m_defaultArena
The default Arena.
Definition: ArenaHeader.h:162
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
ArenaAllocatorRegistry.h
Registry of allocator factories. See Arena.h for an overview of the arena-based memory allocators.
checker_macros.h
Define macros for attributes used to control the static checker.
SG::ArenaHeader::addArena
void addArena(ArenaBase *a)
Add a new Arena to the group.
Definition: ArenaHeader.cxx:72