ATLAS Offline Software
TagInfo.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3  */
4 
13 #include "EventInfo/TagInfo.h"
14 #include "GaudiKernel/MsgStream.h"
15 #include <algorithm>
16 
17 
18 namespace{
21  findTagIt(const std::string& name,TagInfo::NameTagPairVec& tags){
22  // Use lower_bound to find tag
24  pair.first = name;
25  TagInfo::NameTagPairVec::iterator it = std::lower_bound(tags.begin(),tags.end(),pair);
26  // We are now just below the tag, check whether we have found it
27  if (it != tags.end()) {
28  if (it->first == name) {
29  return(it);
30  }
31  }
32  return(tags.end());
33  }
34 
35 
37  TagInfo::NameTagPairVec::const_iterator
38  findTagIt(const std::string& name,const TagInfo::NameTagPairVec& tags){
39  // Use lower_bound to find tag
41  pair.first = name;
42  TagInfo::NameTagPairVec::const_iterator it = std::lower_bound(tags.begin(),tags.end(),pair);
43  // We are now just below the tag, check whether we have found it
44  if (it != tags.end()) {
45  if (it->first == name) {
46  return(it);
47  }
48  }
49  return(tags.end());
50  }
51 
52  std::string
53  findTagImpl(const std::string & name, const TagInfo::NameTagPairVec & thisVec){
54  std::string result{};
55  const auto & it = findTagIt(name, thisVec);
56  if (it != thisVec.end()) result = it->second;
57  return result;
58  }
59 
60  bool
61  addTagImpl(const TagInfo::NameTagPair& pair, TagInfo::NameTagPairVec & thisVec, const bool override = false){
63  TagInfo::NameTagPairVec::iterator it = findTagIt(pair.first, thisVec);
64  if (it != thisVec.end()) {
65  // Tag name exists - check override
66  if (override) {
67  // Over ride the existing tag value
68  it->second = pair.second;
69  return true;
70  } else {
71  return false;
72  }
73  }
74  // New tag - add to vector and sort
75  thisVec.push_back(pair);
76  std::sort(thisVec.begin(), thisVec.end());
77  return true;
78  }
79  std::string
80  formatTagPair(const TagInfo::NameTagPair& pair){
81  return std::string(" ") + pair.first + " " + pair.second;
82  }
83 
84 
85 }
86 
88 
90 
91 
92 
93 // Access to DetDescr tags
94 void
95 TagInfo::findTag(const std::string& name, std::string& tag) const {
96  tag = findTag(name);
97 }
98 
99 std::string
100 TagInfo::findTag(const std::string& name) const {
101  return findTagImpl(name, m_tags);
102 }
103 
104 // Access to DetDescr tags
105 void
106 TagInfo::findInputTag(const std::string& name, std::string& tag) const {
107  tag = findInputTag(name);
108 }
109 
110 std::string
111 TagInfo::findInputTag(const std::string& name) const {
112  return findTagImpl(name, m_inputTags);;
113 }
114 
115 
116 void
118  pairs = m_tags;
119 }
120 
123  return m_tags;
124 }
125 
126 void
128  pairs = m_inputTags;
129 }
130 
133  return m_inputTags;
134 }
135 
136 std::string
138  return(m_myTag);
139 }
140 
141 bool
142 TagInfo::operator < (const TagInfo& rhs) const {
143  if (this->tagInfoTag() != rhs.tagInfoTag()) {
144  return(this->tagInfoTag() < rhs.tagInfoTag());
145  }
146  if (this->m_tags.size() != rhs.m_tags.size()) {
147  return(this->m_tags.size() < rhs.m_tags.size());
148  }
149  for (NameTagPairVec::const_iterator i = this->m_tags.begin(), j = rhs.m_tags.begin();
150  i != this->m_tags.end(); ++i, ++j) {
151  if (i->first != j->first) {
152  return(i->first < j->first);
153  }
154  if (i->second != j->second) {
155  return(i->second < j->second);
156  }
157  }
158  if (this->m_inputTags.size() != rhs.m_inputTags.size()) {
159  return(this->m_inputTags.size() < rhs.m_inputTags.size());
160  }
161  for (NameTagPairVec::const_iterator i = this->m_inputTags.begin(), j = rhs.m_inputTags.begin();
162  i != this->m_inputTags.end(); ++i, ++j) {
163  if (i->first != j->first) {
164  return(i->first < j->first);
165  }
166  if (i->second != j->second) {
167  return(i->second < j->second);
168  }
169  }
170  return(false);
171 }
172 
173 // Set methods:
175 TagInfo::addTag(const NameTagPair& pair, bool override) {
177  return addTagImpl(pair,m_tags,override)? (StatusCode::SUCCESS): (StatusCode::FAILURE);
178 }
179 
181 TagInfo::addInputTag(const NameTagPair& pair, bool override) {
183  return addTagImpl(pair,m_inputTags,override)? (StatusCode::SUCCESS): (StatusCode::FAILURE);
184 }
185 
186 void
187 TagInfo::setTagInfoTag(const std::string& tag) {
188  m_myTag = tag;
189 }
190 
191 void
192 TagInfo::printTags(MsgStream& log) const {
193  if (log.level() <= MSG::DEBUG) {
194  log << MSG::DEBUG << "TagInfo tag: " << m_myTag << endmsg;
195  log << MSG::DEBUG << "Current tags: " << endmsg;
196  for (const auto &thisPair : m_tags) {
197  log << MSG::DEBUG << formatTagPair(thisPair) << endmsg;
198  }
199  log << MSG::DEBUG << "Input tags: " << endmsg;
200  for (const auto &thisPair : m_inputTags) {
201  log << MSG::DEBUG << formatTagPair(thisPair) << endmsg;
202  }
203  }
204 }
205 
206 std::string
207 TagInfo::str() const {
208  std::string m{};
209  m+="TagInfo tag: " + m_myTag + "\n";
210  m+="Current tags: \n";
211  for (const auto &thisPair : m_tags) {
212  m+= formatTagPair(thisPair) + "\n";
213  }
214  m+= "Input tags: \n";
215  for (const auto &thisPair : m_inputTags) {
216  m += formatTagPair(thisPair) + "\n";
217  }
218  return m;
219 }
220 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TagInfo::getInputTags
NameTagPairVec getInputTags() const
Return a vector with all current input tags.
Definition: TagInfo.cxx:132
get_generator_info.result
result
Definition: get_generator_info.py:21
TagInfo::TagInfo
TagInfo()
Definition: TagInfo.cxx:87
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
TagInfo::addTag
StatusCode addTag(const NameTagPair &pair, bool override=false)
addTag for current tags - returns failure if tag name exists and override == false
Definition: TagInfo.cxx:175
TagInfo::findInputTag
void findInputTag(const std::string &name, std::string &tag) const
Find tag by its name - for input tags, return in the reference argument.
Definition: TagInfo.cxx:106
TagInfo::NameTagPairVec
std::vector< NameTagPair > NameTagPairVec
Definition: TagInfo.h:46
TagInfo::addInputTag
StatusCode addInputTag(const NameTagPair &pair, bool override=false)
addInputTag for input tags - returns failure if tag name exists and override == false
Definition: TagInfo.cxx:181
skel.it
it
Definition: skel.GENtoEVGEN.py:423
TagInfo::printTags
void printTags(MsgStream &log) const
Printout method:
Definition: TagInfo.cxx:192
TagInfo::str
std::string str() const
String representation.
Definition: TagInfo.cxx:207
TagInfo::operator<
bool operator<(const TagInfo &rhs) const
Less than comparision needed to create e.g. set<TagInfo>
Definition: TagInfo.cxx:142
python.CreateTierZeroArgdict.pairs
pairs
Definition: CreateTierZeroArgdict.py:201
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
TagInfo::NameTagPair
std::pair< std::string, std::string > NameTagPair
Definition: TagInfo.h:45
TagInfo
This class contains the list of currently valid tags for detector description - GeoModel and IOV/Cond...
Definition: TagInfo.h:41
TagInfo::~TagInfo
virtual ~TagInfo()
Definition: TagInfo.cxx:89
lumiFormat.i
int i
Definition: lumiFormat.py:92
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TagInfo::setTagInfoTag
void setTagInfoTag(const std::string &tag)
set the tag for the TagInfo object itself
Definition: TagInfo.cxx:187
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
TagInfo::m_inputTags
NameTagPairVec m_inputTags
Definition: TagInfo.h:115
TagInfo.h
This class contains the list of currently valid tags for detector description - GeoModel and IOV/Cond...
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TagInfo::tagInfoTag
std::string tagInfoTag() const
The tag of the TagInfo object.
Definition: TagInfo.cxx:137
TagInfo::findTag
void findTag(const std::string &name, std::string &tag) const
Find tag by its name - for current tags, returning in the reference argument.
Definition: TagInfo.cxx:95
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
TagInfo::m_myTag
std::string m_myTag
Definition: TagInfo.h:116
TagInfo::m_tags
NameTagPairVec m_tags
Definition: TagInfo.h:114
TagInfo::getTags
NameTagPairVec getTags() const
Return a vector with all current tags.
Definition: TagInfo.cxx:122