ATLAS Offline Software
TagList.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 // Please feel free to contact me (krumnack@iastate.edu) for bug
11 // reports, feature suggestions, praise and complaints.
12 
13 
14 //
15 // includes
16 //
17 
18 //protect
19 #include <SampleHandler/TagList.h>
20 
21 #include <RootCoreUtils/Assert.h>
22 #include <RootCoreUtils/ThrowMsg.h>
23 
24 //
25 // method implementations
26 //
27 
28 namespace SH
29 {
30  std::string dbg (const TagList& obj, unsigned /*verbosity*/)
31  {
32  std::string result;
33 
34  for (TagList::iterator tag = obj.begin(), end = obj.end();
35  tag != end; ++ tag)
36  {
37  if (!result.empty())
38  result += ",";
39  result += *tag;
40  };
41  return "(" + result + ")";
42  }
43 
44 
45 
47  testInvariant () const
48  {
49  for (TagsIter tag = m_tags.begin(),
50  end = m_tags.end(); tag != end; ++ tag)
51  {
52  RCU_INVARIANT (!tag->empty());
53  //RCU_INVARIANT (tag->find (':') == std::string::npos);
54  };
55  }
56 
57 
58 
60  TagList ()
61  {
62  RCU_NEW_INVARIANT (this);
63  }
64 
65 
66 
68  TagList (const std::string& tags, char separator)
69  {
70  std::string::const_iterator pos1, pos2 = tags.begin(), end = tags.end();
71 
72  while (pos2 != end)
73  {
74  for (pos1 = pos2; pos2 != end && *pos2 != separator; ++ pos2) {};
75 
76  if (pos2 != pos1)
77  m_tags.insert (std::string (pos1, pos2));
78  if (pos2 != end)
79  ++ pos2;
80  };
81 
82  RCU_NEW_INVARIANT (this);
83  }
84 
85 
86 
88  has (const std::string& tag) const
89  {
90  RCU_READ_INVARIANT (this);
91  RCU_REQUIRE_SOFT (!tag.empty());
92  return m_tags.find (tag) != m_tags.end();
93  }
94 
95 
96 
98  begin () const
99  {
100  RCU_READ_INVARIANT (this);
101  return m_tags.begin();
102  }
103 
104 
105 
107  end () const
108  {
109  RCU_READ_INVARIANT (this);
110  return m_tags.end();
111  }
112 
113 
114 
115  std::string TagList ::
116  join (const char separator) const
117  {
118  RCU_READ_INVARIANT (this);
119 
120  std::string result;
121  for (TagsIter tag = m_tags.begin(), end = m_tags.end();
122  tag != end; ++ tag)
123  {
124  if (tag->find (separator) != std::string::npos)
125  RCU_THROW_MSG (std::string ("can't use separator ") + separator + " it is part of tag " + *tag);
126  if (!result.empty())
127  result += separator;
128  result += *tag;
129  };
130  return result;
131  }
132 
133 
134 
136  add (const std::string& tag)
137  {
138  RCU_CHANGE_INVARIANT (this);
139 
140  m_tags.insert (tag);
141  }
142 }
get_generator_info.result
result
Definition: get_generator_info.py:21
SH::TagList
A class that manages a list of tags for identifying samples.
Definition: TagList.h:48
TagList.h
SH::dbg
std::string dbg(const Meta &, unsigned)
Definition: Meta.cxx:28
SH::TagList::has
bool has(const std::string &tag) const
whether we have the given tag
Definition: TagList.cxx:88
SH::TagList::join
std::string join(char separator=':') const
join all the tags together into a string
Definition: TagList.cxx:116
SH::TagList::begin
iterator begin() const
the begin iterator to use
Definition: TagList.cxx:98
Assert.h
SH::TagList::TagsIter
std::set< std::string >::const_iterator TagsIter
the iterator for m_tags
Definition: TagList.h:150
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SH::TagList::add
void add(const std::string &tag)
add a tag to the list
Definition: TagList.cxx:136
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
RCU_REQUIRE_SOFT
#define RCU_REQUIRE_SOFT(x)
Definition: Assert.h:153
SH::TagList::testInvariant
void testInvariant() const
test the invariant of this object
Definition: TagList.cxx:47
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
ThrowMsg.h
SH::TagList::iterator
std::set< std::string >::const_iterator iterator
the iterator to use
Definition: TagList.h:96
SH::TagList::m_tags
std::set< std::string > m_tags
the list of tags
Definition: TagList.h:146
SH::TagList::TagList
TagList()
standard default constructor
Definition: TagList.cxx:60
SH::TagList::end
iterator end() const
the end iterator to use
Definition: TagList.cxx:107
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: PrunDriver.h:15
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
python.PyAthena.obj
obj
Definition: PyAthena.py:135
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233