ATLAS Offline Software
Loading...
Searching...
No Matches
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
9namespace xAOD {
10
12
13 static IOStats obj ATLAS_THREAD_SAFE;
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
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
STL class.
std::map< std::thread::id, ReadStats > m_stats
Objects describing the file access pattern, per thread.
Definition IOStats.h:73
ReadStats & stats()
Access the object belonging to the current thread.
Definition IOStats.cxx:17
AthContainers_detail::thread_specific_ptr< ReadStats > m_ptr
Thread specific pointer to the ReadStats object of the current thread.
Definition IOStats.h:76
ReadStats merged() const
Access the statistics object, merging information from all threads.
Definition IOStats.cxx:34
IOStats()
The constructor of the object is made private.
Definition IOStats.cxx:49
std::mutex m_mutex
Mutex for accessing the read statistics.
Definition IOStats.h:79
static IOStats & instance()
Singleton object accessor.
Definition IOStats.cxx:11
Class describing the access statistics of a collection of branches.
Definition ReadStats.h:123
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.