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 (std::ostream &s) const
void show (MsgStream &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 31 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 39 of file DetectorDescription/Identifier/src/Range.cxx.

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

◆ 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 54 of file DetectorDescription/Identifier/src/Range.cxx.

54 {
55 // Construct from a root (i.e. add wild card for below)
56 build (root);
57}
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 47 of file DetectorDescription/Identifier/src/Range.cxx.

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

Member Function Documentation

◆ add() [1/6]

void Range::add ( const field & f)

Add a range specified using a field.

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

90 {
91 m_fields.emplace_back(f);
92}

◆ add() [2/6]

void Range::add ( const Range & subrange)

Append a subrange.

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

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

◆ add() [3/6]

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

Add a bounded value.

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

83 {
84 m_fields.emplace_back (minimum, maximum);
85}
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 78 of file DetectorDescription/Identifier/src/Range.cxx.

78 {
79 m_fields.emplace_back (value);
80}

◆ 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 95 of file DetectorDescription/Identifier/src/Range.cxx.

95 {
96 m_fields.emplace_back(std::move(f));
97}

◆ add() [6/6]

void Range::add ( Range && subrange)

Append a subrange, with move semantics.

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

107 {
108 if (m_fields.empty())
109 m_fields.swap (subrange.m_fields);
110 else {
111 size_t sz = subrange.m_fields.size();
112 m_fields.reserve (m_fields.size() + sz);
113 for (size_t i = 0; i < sz; ++i) {
114 m_fields.emplace_back (std::move(subrange.m_fields[i]));
115 }
116 }
117}
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 67 of file DetectorDescription/Identifier/src/Range.cxx.

67 {
68 // Construct from a root
69 m_fields.clear ();
70 for (size_type i = 0; i < root.fields (); ++i){
71 m_fields.emplace_back(root[i]);
72 }
73}
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 60 of file DetectorDescription/Identifier/src/Range.cxx.

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

◆ 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 176 of file DetectorDescription/Identifier/src/Range.cxx.

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

◆ cardinalityUpTo()

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

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

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

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

◆ clear()

void Range::clear ( )

Modifications.

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

123 {
124 m_fields.clear ();
125}

◆ fields()

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

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

150 {
151 return (m_fields.size ());
152}

◆ is_empty()

bool Range::is_empty ( ) const
inline

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

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

◆ match()

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

Match an identifier.

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

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

◆ maximum()

ExpandedIdentifier Range::maximum ( ) const

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

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

◆ 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 151 of file DetectorDescription/Identifier/src/Range.cxx.

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

◆ operator std::string()

Range::operator std::string ( ) const

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

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

305 {
306 std::string result;
307 size_type my_fields = m_fields.size ();
308 if (my_fields == 0) return (result);
309 // print fields one by one.
310 for (size_type field_number = 0; field_number < my_fields; field_number++) {
311 const field& f = m_fields[field_number];
312 if (field_number > 0) result += "/";
313 result += (std::string) f;
314 }
315 return (result);
316}

◆ operator==()

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

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

320 {
321 if (m_fields.size() != other.m_fields.size()) return false;
322 field_vector::const_iterator it1 = m_fields.begin();
323 field_vector::const_iterator it2 = other.m_fields.begin();
324 field_vector::const_iterator last = m_fields.end();
325 for (; it1 != last; ++it1, ++it2) {
326 if ((*it1) != (*it2)) return false;
327 }
328 return (true);
329}

◆ operator[]()

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

Access the field elements.

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

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

◆ 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 260 of file DetectorDescription/Identifier/src/Range.cxx.

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

◆ show() [1/2]

void Range::show ( MsgStream & s) const

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

298 {
299 std::ostringstream os;
300 show(os);
301 out << os.str();
302}
void show(std::ostream &s) const

◆ 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: