ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ItemListSvc Class Reference

This implementes the methods for IItemListSvc. More...

#include <ItemListSvc.h>

Inheritance diagram for ItemListSvc:
Collaboration diagram for ItemListSvc:

Public Member Functions

 ItemListSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor. More...
 
virtual ~ItemListSvc ()
 Destructor. More...
 
StatusCode initialize () override
 Gaudi Service Implementation. More...
 
StatusCode finalize () override
 
virtual StatusCode addStreamItem (const std::string &stream, const std::string &itemname) override
 
virtual StatusCode removeStreamItem (const std::string &stream, const std::string &itemname) override
 
virtual bool containsItem (const std::string &itemname, const std::string &stream="ANY") const override
 
virtual std::vector< std::string > getStreamsForItem (const std::string &itemname) const override
 
virtual std::vector< std::string > getItemsForStream (const std::string &stream) const override
 

Private Types

typedef std::lock_guard< std::mutex > lock_t
 

Private Member Functions

 ItemListSvc (const ItemListSvc &)
 
ItemListSvcoperator= (const ItemListSvc &)
 

Private Attributes

std::map< std::string, std::set< std::string > > m_streamItems
 
float m_verboseThresh
 
std::mutex m_mutex
 

Detailed Description

This implementes the methods for IItemListSvc.

Definition at line 55 of file ItemListSvc.h.

Member Typedef Documentation

◆ lock_t

typedef std::lock_guard<std::mutex> ItemListSvc::lock_t
private

Definition at line 95 of file ItemListSvc.h.

Constructor & Destructor Documentation

◆ ItemListSvc() [1/2]

ItemListSvc::ItemListSvc ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Constructor.

Definition at line 20 of file ItemListSvc.cxx.

21  :
22  base_class(name, pSvcLocator),
23  m_verboseThresh(0.20)
24 {
25  declareProperty("VerboseThreshold",m_verboseThresh,"overlaps above this fraction print their items, def=0.2");
26  assert( pSvcLocator );
27 }

◆ ~ItemListSvc()

ItemListSvc::~ItemListSvc ( )
virtual

Destructor.

Definition at line 29 of file ItemListSvc.cxx.

30 {
31 }

◆ ItemListSvc() [2/2]

ItemListSvc::ItemListSvc ( const ItemListSvc )
private

Member Function Documentation

◆ addStreamItem()

StatusCode ItemListSvc::addStreamItem ( const std::string &  stream,
const std::string &  itemname 
)
overridevirtual

Definition at line 74 of file ItemListSvc.cxx.

75 {
76  lock_t lock (m_mutex);
77  // Add to stream list
78  // Check if item is already present
79  std::map<std::string, std::set<std::string> >::iterator it = m_streamItems.find(stream);
80  // if so, then add stream name for that item
81  if (it != m_streamItems.end()) {
82  it->second.insert(itemname);
83  }
84  // otherwise add item and stream
85  else {
86  std::set<std::string> start;
87  start.insert(itemname);
88  std::pair<std::map<std::string, std::set<std::string> >::iterator,bool> retc = m_streamItems.insert(std::make_pair(stream,start));
89  if (!retc.second) {
90  ATH_MSG_ERROR("Problem inserting " << retc.first->first);
91  }
92  }
93  return StatusCode::SUCCESS;
94 }

◆ containsItem()

bool ItemListSvc::containsItem ( const std::string &  itemname,
const std::string &  stream = "ANY" 
) const
overridevirtual

Definition at line 113 of file ItemListSvc.cxx.

114 {
115  lock_t lock (m_mutex);
116  bool contains=false;
117  std::map<std::string, std::set<std::string> >::const_iterator it = m_streamItems.begin();
118  while (it != m_streamItems.end()) {
119  if (it->first == stream || stream == "ANY") {
120  if (it->second.find(itemname) != it->second.end()) contains = true;
121  }
122  ++it;
123  }
124  return contains;
125 }

◆ finalize()

StatusCode ItemListSvc::finalize ( )
override

Definition at line 39 of file ItemListSvc.cxx.

40 {
41  ATH_MSG_DEBUG("ItemListSvc finalize");
42  std::map<std::string, std::set<std::string> >::const_iterator it = m_streamItems.begin();
43  ATH_MSG_DEBUG("-- OUTPUT STREAM ITEM OVERLAP SUMMARY --");
44  while (it != m_streamItems.end()) {
45  ATH_MSG_DEBUG("STREAM " << it->first << " has (" << it->second.size() << ") items");
46  std::set<std::string>::const_iterator iprint = it->second.begin();
47  while (iprint != it->second.end()) {
48  ATH_MSG_DEBUG(" - " << *iprint);
49  ++iprint;
50  }
51  std::map<std::string, std::set<std::string> >::const_iterator it2 = m_streamItems.begin();
52  float inv_size = 1. / static_cast<float> (it->second.size());
53  while (it2 != m_streamItems.end()) {
54  if (it2->first != it->first) {
55  std::set<std::string> olist;
56  std::set_intersection(it->second.begin(),it->second.end(),it2->second.begin(),it2->second.end(),std::inserter(olist,olist.begin()));
57  if (olist.size()>0) {
58  ATH_MSG_DEBUG(" --> Overlap with " << it2->first << " (" << olist.size() << ") items");
59  if (float(olist.size()) * inv_size > m_verboseThresh) {
60  for (const std::string& ol : olist) {
61  ATH_MSG_DEBUG(" ----> item: " << ol);
62  }
63  }
64  }
65  }
66  ++it2;
67  }
68  ++it;
69  }
70  return StatusCode::SUCCESS;
71 }

◆ getItemsForStream()

std::vector< std::string > ItemListSvc::getItemsForStream ( const std::string &  stream) const
overridevirtual

Definition at line 141 of file ItemListSvc.cxx.

142 {
143  lock_t lock (m_mutex);
144  std::vector<std::string> t;
145  std::map<std::string, std::set<std::string> >::const_iterator it = m_streamItems.find(stream);
146  if (it != m_streamItems.end()) std::copy(it->second.begin(), it->second.end(),t.begin());
147  return t;
148 }

◆ getStreamsForItem()

std::vector< std::string > ItemListSvc::getStreamsForItem ( const std::string &  itemname) const
overridevirtual

Definition at line 128 of file ItemListSvc.cxx.

129 {
130  lock_t lock (m_mutex);
131  std::vector<std::string> t;
132  std::map<std::string, std::set<std::string> >::const_iterator it = m_streamItems.begin();
133  while (it != m_streamItems.end()) {
134  if (it->second.find(itemname) != it->second.end()) t.push_back(it->first);
135  ++it;
136  }
137  return t;
138 }

◆ initialize()

StatusCode ItemListSvc::initialize ( )
override

Gaudi Service Implementation.

Definition at line 32 of file ItemListSvc.cxx.

33 {
34  ATH_MSG_DEBUG("ItemListSvc initialize");
35  return StatusCode::SUCCESS;
36 }

◆ operator=()

ItemListSvc& ItemListSvc::operator= ( const ItemListSvc )
private

◆ removeStreamItem()

StatusCode ItemListSvc::removeStreamItem ( const std::string &  stream,
const std::string &  itemname 
)
overridevirtual

Definition at line 97 of file ItemListSvc.cxx.

98 {
99  lock_t lock (m_mutex);
100  std::map<std::string, std::set<std::string> >::iterator it = m_streamItems.find(stream);
101  if (it == m_streamItems.end()) {
102  ATH_MSG_INFO("Tried to remove non-existing item " << itemname << " for " << stream);
103  }
104  else {
105  // remove stream for item
106  int n = it->second.erase(itemname);
107  if (n<1) ATH_MSG_WARNING("Could not find stream " << stream << " for " << itemname);
108  }
109  return StatusCode::SUCCESS;
110 }

Member Data Documentation

◆ m_mutex

std::mutex ItemListSvc::m_mutex
mutableprivate

Definition at line 94 of file ItemListSvc.h.

◆ m_streamItems

std::map<std::string, std::set<std::string> > ItemListSvc::m_streamItems
private

Definition at line 92 of file ItemListSvc.h.

◆ m_verboseThresh

float ItemListSvc::m_verboseThresh
private

Definition at line 93 of file ItemListSvc.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ItemListSvc::m_mutex
std::mutex m_mutex
Definition: ItemListSvc.h:94
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
skel.it
it
Definition: skel.GENtoEVGEN.py:423
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ItemListSvc::m_streamItems
std::map< std::string, std::set< std::string > > m_streamItems
Definition: ItemListSvc.h:92
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
ItemListSvc::m_verboseThresh
float m_verboseThresh
Definition: ItemListSvc.h:93
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
calibdata.copy
bool copy
Definition: calibdata.py:27
set_intersection
Set * set_intersection(Set *set1, Set *set2)
Perform an intersection of two sets.
ItemListSvc::lock_t
std::lock_guard< std::mutex > lock_t
Definition: ItemListSvc.h:95