ATLAS Offline Software
ItemListSvc.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // ItemListSvc.cxx
8 // Implementation file for class ItemListSvc
9 // Author: J.Cranshaw<cranshaw@anl.gov>
11 
12 
13 #include "ItemListSvc.h"
14 
15 // Gaudi include files
16 #include <algorithm>
17 #include <sstream>
18 
19 
20 ItemListSvc::ItemListSvc(const std::string& name,
21  ISvcLocator* pSvcLocator ) :
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 }
28 
30 {
31 }
33 {
34  ATH_MSG_DEBUG("ItemListSvc initialize");
35  return StatusCode::SUCCESS;
36 }
37 
38 // Just print out the streams for each item
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 }
72 
73 // add item to list for stream
74 StatusCode ItemListSvc::addStreamItem(const std::string& stream, const std::string& itemname)
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 }
95 
96 // remove item from list for stream
97 StatusCode ItemListSvc::removeStreamItem(const std::string& stream, const std::string& itemname)
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 }
111 
112 // simple test to see if item or (stream,item) is already being written
113 bool ItemListSvc::containsItem(const std::string& itemname, const std::string& stream) const
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 }
126 
127 // This returns all the streams that an item was written to
128 std::vector<std::string> ItemListSvc::getStreamsForItem(const std::string& itemname) const
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 }
139 
140 // This returns the items that were output to a certain stream
141 std::vector<std::string> ItemListSvc::getItemsForStream(const std::string& stream) const
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 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ItemListSvc::addStreamItem
virtual StatusCode addStreamItem(const std::string &stream, const std::string &itemname) override
Definition: ItemListSvc.cxx:74
ItemListSvc::m_mutex
std::mutex m_mutex
Definition: ItemListSvc.h:94
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ItemListSvc.h
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
skel.it
it
Definition: skel.GENtoEVGEN.py:396
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ItemListSvc::ItemListSvc
ItemListSvc(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: ItemListSvc.cxx:20
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ItemListSvc::initialize
StatusCode initialize() override
Gaudi Service Implementation.
Definition: ItemListSvc.cxx:32
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
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::getStreamsForItem
virtual std::vector< std::string > getStreamsForItem(const std::string &itemname) const override
Definition: ItemListSvc.cxx:128
ItemListSvc::m_verboseThresh
float m_verboseThresh
Definition: ItemListSvc.h:93
ItemListSvc::finalize
StatusCode finalize() override
Definition: ItemListSvc.cxx:39
ItemListSvc::removeStreamItem
virtual StatusCode removeStreamItem(const std::string &stream, const std::string &itemname) override
Definition: ItemListSvc.cxx:97
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ItemListSvc::~ItemListSvc
virtual ~ItemListSvc()
Destructor.
Definition: ItemListSvc.cxx:29
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
calibdata.copy
bool copy
Definition: calibdata.py:27
ItemListSvc::getItemsForStream
virtual std::vector< std::string > getItemsForStream(const std::string &stream) const override
Definition: ItemListSvc.cxx:141
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
ItemListSvc::containsItem
virtual bool containsItem(const std::string &itemname, const std::string &stream="ANY") const override
Definition: ItemListSvc.cxx:113