ATLAS Offline Software
Loading...
Searching...
No Matches
Range Class Reference

A Range describes the possible ranges for the field values of an ExpandedIdentifier. More...

#include <Range.h>

Collaboration diagram for Range:

Public Types

using element_type = ExpandedIdentifier::element_type
using size_type = ExpandedIdentifier::size_type
using field = IdentifierField
using field_vector = std::vector<field>

Public Member Functions

 Range ()=default
 Range (const Range &other, size_type start)
 This is a sub-range copy constructor.
 Range (const ExpandedIdentifier &root)
 Construct from a simple ExpandedIdentifier.
 Range (const std::string &text)
void build (const std::string &text)
 Build Range from a textual description.
void build (const ExpandedIdentifier &root)
 Build a range from a single ExpandedIdentifier (see similar constructor for comment)
void clear ()
 Modifications.
void add (element_type value)
 Add a required value. (ie. low = high = value)
void add (element_type minimum, element_type maximum)
 Add a bounded value.
void add (const field &f)
 Add a range specified using a field.
void add (field &&f)
 Add a range specified using a field, with move semantics.
void add (const Range &subrange)
 Append a subrange.
void add (Range &&subrange)
 Append a subrange, with move semantics.
int match (const ExpandedIdentifier &id) const
 Match an identifier.
const fieldoperator[] (size_type index) const
 Access the field elements.
size_type fields () const
bool is_empty () const
ExpandedIdentifier minimum () const
 min and max ExpandedIdentifiers
(if they exist, ie.
ExpandedIdentifier maximum () const
size_type cardinality () const
 Computes a possible cardinality :
size_type cardinalityUpTo (const ExpandedIdentifier &id) const
 Get the cardinality from the beginning up to the given ExpandedIdentifier.
bool overlaps_with (const Range &other) const
 Check if two Ranges overlap.
void show () const
void show (std::ostream &s) const
 operator std::string () const
 Produce a textual representation of the range using the input format.
bool operator== (const Range &other) const

Private Attributes

field_vector m_fields

Detailed Description

A Range describes the possible ranges for the field values of an ExpandedIdentifier.

Specifications can be : No bound * Low bound n: High bound :m Both bounds n:m Enumeration v1, v2, v3, ... , vn

Trailing * are implicit for all trailing fields

Definition at line 29 of file DetectorDescription/Identifier/Identifier/Range.h.

Member Typedef Documentation

◆ element_type

◆ field

◆ field_vector

using Range::field_vector = std::vector<field>

◆ size_type

Constructor & Destructor Documentation

◆ Range() [1/4]

Range::Range ( )
default

◆ Range() [2/4]

Range::Range ( const Range & other,
size_type start )

This is a sub-range copy constructor.


It copies the portion of the other Range, starting from the
specified starting index up to its last field.

Definition at line 37 of file DetectorDescription/Identifier/src/Range.cxx.

37 {
38 if (start < other.fields ()) {
39 field_vector::const_iterator it = other.m_fields.begin ();
40 it += start;
41 m_fields.insert (m_fields.end (), it, other.m_fields.end ());
42 }
43}

◆ Range() [3/4]

Range::Range ( const ExpandedIdentifier & root)

Construct from a simple ExpandedIdentifier.

This implies that all fields will have their min=max=id[i]

Definition at line 52 of file DetectorDescription/Identifier/src/Range.cxx.

52 {
53 // Construct from a root (i.e. add wild card for below)
54 build (root);
55}
void build(const std::string &text)
Build Range from a textual description.

◆ Range() [4/4]

Range::Range ( const std::string & text)
explicit

Definition at line 45 of file DetectorDescription/Identifier/src/Range.cxx.

45 :Range(){
46 if (text.empty()) return;
47 std::istringstream in(text);
48 in>>*this;
49}
Range()=default

Member Function Documentation

◆ add() [1/6]

void Range::add ( const field & f)

Add a range specified using a field.

Definition at line 88 of file DetectorDescription/Identifier/src/Range.cxx.

88 {
89 m_fields.emplace_back(f);
90}

◆ add() [2/6]

void Range::add ( const Range & subrange)

Append a subrange.

Definition at line 98 of file DetectorDescription/Identifier/src/Range.cxx.

98 {
99 for (size_t i = 0; i < subrange.fields (); ++i) {
100 const field& f = subrange[i];
101 m_fields.push_back (f);
102 }
103}

◆ add() [3/6]

void Range::add ( element_type minimum,
element_type maximum )

Add a bounded value.

Definition at line 81 of file DetectorDescription/Identifier/src/Range.cxx.

81 {
82 m_fields.emplace_back (minimum, maximum);
83}
ExpandedIdentifier maximum() const
ExpandedIdentifier minimum() const
min and max ExpandedIdentifiers (if they exist, ie.

◆ add() [4/6]

void Range::add ( element_type value)

Add a required value. (ie. low = high = value)

Definition at line 76 of file DetectorDescription/Identifier/src/Range.cxx.

76 {
77 m_fields.emplace_back (value);
78}

◆ add() [5/6]

void Range::add ( field && f)

Add a range specified using a field, with move semantics.

Add a range specified using a field, using move semantics.

Definition at line 93 of file DetectorDescription/Identifier/src/Range.cxx.

93 {
94 m_fields.emplace_back(std::move(f));
95}

◆ add() [6/6]

void Range::add ( Range && subrange)

Append a subrange, with move semantics.

Definition at line 105 of file DetectorDescription/Identifier/src/Range.cxx.

105 {
106 if (m_fields.empty())
107 m_fields.swap (subrange.m_fields);
108 else {
109 size_t sz = subrange.m_fields.size();
110 m_fields.reserve (m_fields.size() + sz);
111 for (size_t i = 0; i < sz; ++i) {
112 m_fields.emplace_back (std::move(subrange.m_fields[i]));
113 }
114 }
115}
static Double_t sz

◆ build() [1/2]

void Range::build ( const ExpandedIdentifier & root)

Build a range from a single ExpandedIdentifier (see similar constructor for comment)

Definition at line 65 of file DetectorDescription/Identifier/src/Range.cxx.

65 {
66 // Construct from a root
67 m_fields.clear ();
68 for (size_type i = 0; i < root.fields (); ++i){
69 m_fields.emplace_back(root[i]);
70 }
71}
ExpandedIdentifier::size_type size_type

◆ build() [2/2]

void Range::build ( const std::string & text)

Build Range from a textual description.

The syntax is :

range : <value-range> [ "/" <value-range> ... ]

value-range : "*" | <value> | ":" <max> | <min> ":" | <min> ":" <max> | <value> "," <value> "," ... "," <value>

Definition at line 58 of file DetectorDescription/Identifier/src/Range.cxx.

58 {
59 if (text.empty()) return;
60 std::istringstream in(text);
61 in>>*this;
62}

◆ cardinality()

Range::size_type Range::cardinality ( ) const

Computes a possible cardinality :

  • all bounded fields are counted as they are
  • unbounded fields are counted for one value.

Definition at line 174 of file DetectorDescription/Identifier/src/Range.cxx.

174 {
175 size_type result = 1;
176 const Range& me = *this;
177 for (size_type i = 0; i < fields (); ++i) {
178 const field& f = me[i];
179 result *= f.get_indices ();
180 }
181 return (result);
182}

◆ cardinalityUpTo()

Range::size_type Range::cardinalityUpTo ( const ExpandedIdentifier & id) const

Get the cardinality from the beginning up to the given ExpandedIdentifier.

Definition at line 188 of file DetectorDescription/Identifier/src/Range.cxx.

188 {
189 size_type result = 0;
190 if (id.fields() != fields()) return (result);
191 const Range& me = *this;
192 // Check if we are above or below this range
193 if (id < minimum()) return 0;
194 if (maximum() < id) return cardinality();
195 // Collect the indices of a match
196 std::vector<size_type> indices(id.fields (), 0);
197 bool is_match = true;
198 size_type level = 0;
199 for (; level < id.fields (); ++level) {
200 const field& f = me[level];
201 // Require all fields to be bounded or enumerated
202 if (f.empty()) return 0;
203 if (f.isEnumerated()) {
204 // Continue testing for a match
205 size_type max = f.get_values().size() - 1;
206 if (f.get_values()[max] < id[level]) {
207 // above max
208 is_match = false;
209 indices[level] = max + 1;
210 } else {
211 for (size_type j = 0; j < f.get_values().size(); ++j) {
212 if (id[level] <= f.get_values()[j]) {
213 if (id[level] != f.get_values()[j]) {
214 // between two values or below first one
215 is_match = false;
216 }
217 indices[level] = j;
218 break;
219 }
220 }
221 }
222 } else {
223 if (f.get_maximum() < id[level]) {
224 // above max
225 is_match = false;
226 indices[level] = f.get_maximum() - f.get_minimum() + 1;
227 } else if (id[level] < f.get_minimum()) {
228 // below min
229 is_match = false;
230 indices[level] = 0;
231 } else {
232 indices[level] = id[level] - f.get_minimum();
233 }
234 }
235 if (!is_match) break;
236 }
237
238 // Calculate the cardinality
239 if (level < id.fields ()) ++level;
240 for (size_type j = 0; j < level; ++j) {
241 size_type card = indices[j];
242 for (size_type k = j + 1; k < id.fields(); ++k) {
243 const field& f = me[k];
244 card *= f.get_indices();
245 }
246 result += card;
247 }
248 return result;
249}
#define max(a, b)
Definition cfImp.cxx:41
size_type cardinality() const
Computes a possible cardinality :
std::pair< long int, long int > indices

◆ clear()

void Range::clear ( )

Modifications.

Definition at line 121 of file DetectorDescription/Identifier/src/Range.cxx.

121 {
122 m_fields.clear ();
123}

◆ fields()

Range::size_type Range::fields ( ) const
inline

Definition at line 148 of file DetectorDescription/Identifier/Identifier/Range.h.

148 {
149 return (m_fields.size ());
150}

◆ is_empty()

bool Range::is_empty ( ) const
inline

Definition at line 155 of file DetectorDescription/Identifier/Identifier/Range.h.

155 {
156 if (m_fields.size () == 0) return (true);
157 return (false);
158}

◆ match()

int Range::match ( const ExpandedIdentifier & id) const

Match an identifier.

Definition at line 126 of file DetectorDescription/Identifier/src/Range.cxx.

126 {
127
128 size_type my_fields = m_fields.size ();
129 const size_type id_fields = id.fields ();
130
131 // More fields in the range than in the identifier will never match.
132 //if (my_fields > id_fields) return (0);
133
134 // Allow match for id shorter than range - assume "wildcards" for
135 // missing id fields
136 size_type nfields = (my_fields > id_fields) ? id_fields : my_fields;
137 // Test fields one by one.
138 for (size_type field_number = 0; field_number < nfields; field_number++) {
139 const field& f = m_fields[field_number];
140 if (!f.match (id[field_number])) return (0);
141 }
142 // All conditions match.
143 return (1);
144}

◆ maximum()

ExpandedIdentifier Range::maximum ( ) const

Definition at line 162 of file DetectorDescription/Identifier/src/Range.cxx.

162 {
163 size_type my_fields = m_fields.size ();
164 ExpandedIdentifier result;
165 // Copy fields to result
166 for (size_type field_number = 0; field_number < my_fields; field_number++) {
167 const field& f = m_fields[field_number];
168 // Normal field
169 result << f.get_maximum ();
170 }
171 return (result);
172}

◆ minimum()

ExpandedIdentifier Range::minimum ( ) const

min and max ExpandedIdentifiers
(if they exist, ie.

for fully bounded Ranges) Question : what if the Range has wild cards ??

Definition at line 149 of file DetectorDescription/Identifier/src/Range.cxx.

149 {
150 size_type my_fields = m_fields.size ();
151 ExpandedIdentifier result;
152 // Copy fields to result
153 for (size_type field_number = 0; field_number < my_fields; field_number++) {
154 const field& f = m_fields[field_number];
155 // Valued field
156 result << f.get_minimum ();
157 }
158 return (result);
159}

◆ operator std::string()

Range::operator std::string ( ) const

Produce a textual representation of the range using the input format.

Definition at line 298 of file DetectorDescription/Identifier/src/Range.cxx.

298 {
299 std::string result;
300 size_type my_fields = m_fields.size ();
301 if (my_fields == 0) return (result);
302 // print fields one by one.
303 for (size_type field_number = 0; field_number < my_fields; field_number++) {
304 const field& f = m_fields[field_number];
305 if (field_number > 0) result += "/";
306 result += (std::string) f;
307 }
308 return (result);
309}

◆ operator==()

bool Range::operator== ( const Range & other) const

Definition at line 313 of file DetectorDescription/Identifier/src/Range.cxx.

313 {
314 if (m_fields.size() != other.m_fields.size()) return false;
315 field_vector::const_iterator it1 = m_fields.begin();
316 field_vector::const_iterator it2 = other.m_fields.begin();
317 field_vector::const_iterator last = m_fields.end();
318 for (; it1 != last; ++it1, ++it2) {
319 if ((*it1) != (*it2)) return false;
320 }
321 return (true);
322}

◆ operator[]()

const Range::field & Range::operator[] ( Range::size_type index) const

Access the field elements.

Definition at line 28 of file DetectorDescription/Identifier/src/Range.cxx.

28 {
29 if (index >= m_fields.size ()){
30 static const field f;
31 return (f);
32 }
33 return (m_fields[index]);
34}

◆ overlaps_with()

bool Range::overlaps_with ( const Range & other) const

Check if two Ranges overlap.

Check overlap between two Ranges :

As soon as one pair of corresponding fields do not match, the global overlap is empty.

Definition at line 258 of file DetectorDescription/Identifier/src/Range.cxx.

258 {
259 const Range& me = *this;
260 if ((fields () == 0) || (other.fields () == 0)) return (false);
261 for (size_type i = 0; i < std::min (fields (), other.fields ()); ++i){
262 const field& f1 = me[i];
263 const field& f2 = other[i];
264 if (!f1.overlaps_with (f2)) return (false);
265 }
266 return (true);
267}

◆ show() [1/2]

void Range::show ( ) const

Definition at line 270 of file DetectorDescription/Identifier/src/Range.cxx.

270 {
271 show (std::cout);
272}

◆ show() [2/2]

void Range::show ( std::ostream & s) const

Definition at line 274 of file DetectorDescription/Identifier/src/Range.cxx.

274 {
275 const Range& me = *this;
276 s << (std::string) me << " (";
277 int allbits = 0;
278 for (size_type i = 0; i < fields (); ++i) {
279 const field& f = me[i];
280 if (i > 0) s << "+";
281 size_type indices = f.get_indices ();
282 int bits = 1;
283 indices--;
284 if (indices > 0) {
285 bits = 0;
286 while (indices > 0){
287 indices /= 2;
288 bits++;
289 }
290 }
291 allbits += bits;
292 s << bits;
293 }
294 s << "=" << allbits << ") ";
295}

Member Data Documentation

◆ m_fields

field_vector Range::m_fields
private

The documentation for this class was generated from the following files: