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=std::cout) 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 38 of file DetectorDescription/Identifier/src/Range.cxx.

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

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

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

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

Member Function Documentation

◆ add() [1/6]

void Range::add ( const field & f)

Add a range specified using a field.

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

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

◆ add() [2/6]

void Range::add ( const Range & subrange)

Append a subrange.

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

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

◆ add() [3/6]

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

Add a bounded value.

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

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

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

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

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

◆ add() [6/6]

void Range::add ( Range && subrange)

Append a subrange, with move semantics.

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

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

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

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

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

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

◆ cardinalityUpTo()

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

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

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

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

122 {
123 m_fields.clear ();
124}

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

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

◆ maximum()

ExpandedIdentifier Range::maximum ( ) const

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

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

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

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

◆ operator std::string()

Range::operator std::string ( ) const

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

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

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

◆ operator==()

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

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

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

◆ operator[]()

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

Access the field elements.

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

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

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

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

◆ show() [1/2]

void Range::show ( MsgStream & s) const

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

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

◆ show() [2/2]

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

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

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

Member Data Documentation

◆ m_fields

field_vector Range::m_fields
private

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