ATLAS Offline Software
IOStats.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Local include(s):
8 
9 namespace xAOD {
10 
12 
14  return obj;
15  }
16 
18 
19  // Try to access a cached pointer:
20  ReadStats* stats = m_ptr.get();
21 
22  // If a pointer is not cached yet, do so now:
23  if( ! stats ) {
24  const std::thread::id id = std::this_thread::get_id();
25  std::lock_guard< std::mutex > lock( m_mutex );
26  stats = &( m_stats[ id ] );
27  m_ptr.reset( stats );
28  }
29 
30  // Return the (now) cached object:
31  return *stats;
32  }
33 
35 
36  // Get a lock on the map:
37  std::lock_guard< std::mutex > lock( m_mutex );
38 
39  // Merge the objects from all the threads:
41  for( const auto & pair : m_stats ) {
42  result += pair.second;
43  }
44 
45  // Return the merged object:
46  return result;
47  }
48 
50  : m_stats(),
51  // Make sure that the thread specific pointer doesn't try to delete
52  // the object it points to when the thread ends:
53  m_ptr( []( ReadStats* ){} ),
54  m_mutex() {
55 
56  }
57 
58 } // namespace xAOD
xAOD::IOStats::m_ptr
AthContainers_detail::thread_specific_ptr< ReadStats > m_ptr
Thread specific pointer to the ReadStats object of the current thread.
Definition: IOStats.h:75
get_generator_info.result
result
Definition: get_generator_info.py:21
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
IOStats.h
xAOD::IOStats::IOStats
IOStats()
The constructor of the object is made private.
Definition: IOStats.cxx:49
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
xAOD::IOStats
Singleton object holding on to the process's I/O statistics.
Definition: IOStats.h:34
xAOD::IOStats::merged
ReadStats merged() const
Access the statistics object, merging information from all threads.
Definition: IOStats.cxx:34
xAOD::IOStats::m_mutex
std::mutex m_mutex
Mutex for accessing the read statistics.
Definition: IOStats.h:78
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
xAOD::ReadStats
Class describing the access statistics of a collection of branches.
Definition: ReadStats.h:123
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:135
xAOD::IOStats::m_stats
std::map< std::thread::id, ReadStats > m_stats
Objects describing the file access pattern, per thread.
Definition: IOStats.h:72