ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | List of all members
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. More...
 
 Range (const ExpandedIdentifier &root)
 Construct from a simple ExpandedIdentifier. More...
 
 Range (const std::string &text)
 
void build (const std::string &text)
 Build Range from a textual description. More...
 
void build (const ExpandedIdentifier &root)
 Build a range from a single ExpandedIdentifier (see similar constructor for comment) More...
 
void clear ()
 Modifications. More...
 
void add ()
 Add a wild card field. More...
 
void add (element_type value)
 Add a required value. (ie. low = high = value) More...
 
void add (element_type minimum, element_type maximum)
 Add a bounded value. More...
 
void add (const field &f)
 Add a range specified using a field
More...
 
void add (field &&f)
 Add a range specified using a field, with move semantics. More...
 
void add (const Range &subrange)
 Append a subrange. More...
 
void add (Range &&subrange)
 Append a subrange, with move semantics. More...
 
int match (const ExpandedIdentifier &id) const
 Match an identifier. More...
 
const fieldoperator[] (size_type index) const
 Access the field elements. More...
 
size_type fields () const
 
bool is_empty () const
 
ExpandedIdentifier minimum () const
 min and max ExpandedIdentifiers
(if they exist, ie. More...
 
ExpandedIdentifier maximum () const
 
size_type cardinality () const
 Computes a possible cardinality : More...
 
size_type cardinalityUpTo (const ExpandedIdentifier &id) const
 Get the cardinality from the beginning up to the given ExpandedIdentifier. More...
 
bool overlaps_with (const Range &other) const
 Check if two Ranges overlap. More...
 
void show () const
 
void show (std::ostream &s) const
 
 operator std::string () const
 Produce a textual representation of the range using the input format. More...
 
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 }

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

Member Function Documentation

◆ add() [1/7]

void Range::add ( )

Add a wild card field.

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

75  {
76  m_fields.emplace_back();
77 }

◆ add() [2/7]

void Range::add ( const field f)

Add a range specified using a field

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

92  {
93  m_fields.emplace_back(f);
94 }

◆ add() [3/7]

void Range::add ( const Range subrange)

Append a subrange.

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

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

◆ add() [4/7]

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

Add a bounded value.

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

85  {
86  m_fields.emplace_back (minimum, maximum);
87 }

◆ add() [5/7]

void Range::add ( element_type  value)

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

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

80  {
81  m_fields.emplace_back (value);
82 }

◆ add() [6/7]

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

97  {
98  m_fields.emplace_back(std::move(f));
99 }

◆ add() [7/7]

void Range::add ( Range &&  subrange)

Append a subrange, with move semantics.

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

109  {
110  if (m_fields.empty())
111  m_fields.swap (subrange.m_fields);
112  else {
113  size_t sz = subrange.m_fields.size();
114  m_fields.reserve (m_fields.size() + sz);
115  for (size_t i = 0; i < sz; ++i) {
116  m_fields.emplace_back (std::move(subrange.m_fields[i]));
117  }
118  }
119 }

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

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

239  {
240  size_type result = 1;
241  const Range& me = *this;
242  for (size_type i = 0; i < fields (); ++i) {
243  const field& f = me[i];
244  result *= f.get_indices ();
245  }
246  return (result);
247 }

◆ cardinalityUpTo()

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

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

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

253  {
254  size_type result = 0;
255  if (id.fields() != fields()) return (result);
256  const Range& me = *this;
257  // Check if we are above or below this range
258  if (id < minimum()) return 0;
259  if (maximum() < id) return cardinality();
260  // Collect the indices of a match
261  std::vector<size_type> indices(id.fields (), 0);
262  bool is_match = true;
263  size_type level = 0;
264  for (; level < id.fields (); ++level) {
265  const field& f = me[level];
266  // Require all fields to be bounded or enumerated
267  if (f.empty()) return 0;
268  if (f.isEnumerated()) {
269  // Continue testing for a match
270  size_type max = f.get_values().size() - 1;
271  if (f.get_values()[max] < id[level]) {
272  // above max
273  is_match = false;
274  indices[level] = max + 1;
275  } else {
276  for (size_type j = 0; j < f.get_values().size(); ++j) {
277  if (id[level] <= f.get_values()[j]) {
278  if (id[level] != f.get_values()[j]) {
279  // between two values or below first one
280  is_match = false;
281  }
282  indices[level] = j;
283  break;
284  }
285  }
286  }
287  } else {
288  if (f.get_maximum() < id[level]) {
289  // above max
290  is_match = false;
291  indices[level] = f.get_maximum() - f.get_minimum() + 1;
292  } else if (id[level] < f.get_minimum()) {
293  // below min
294  is_match = false;
295  indices[level] = 0;
296  } else {
297  indices[level] = id[level] - f.get_minimum();
298  }
299  }
300  if (!is_match) break;
301  }
302 
303  // Calculate the cardinality
304  if (level < id.fields ()) ++level;
305  for (size_type j = 0; j < level; ++j) {
306  size_type card = indices[j];
307  for (size_type k = j + 1; k < id.fields(); ++k) {
308  const field& f = me[k];
309  card *= f.get_indices();
310  }
311  result += card;
312  }
313  return result;
314 }

◆ clear()

void Range::clear ( )

Modifications.

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

125  {
126  m_fields.clear ();
127 }

◆ fields()

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

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

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

◆ is_empty()

bool Range::is_empty ( ) const
inline

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

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

◆ match()

int Range::match ( const ExpandedIdentifier id) const

Match an identifier.

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

130  {
131  size_type my_fields = m_fields.size ();
132  const size_type id_fields = id.fields ();
133  // Remove trailing wild cards since they are meaningless.
134  while ((my_fields > 1) &&
135  (m_fields[my_fields-1].empty())){
136  my_fields--;
137  }
138  // Ranges with only wild cards always match.
139  if (my_fields == 0) return (1);
140  // More fields in the range than in the identifier will never match.
141  //if (my_fields > id_fields) return (0);
142 
143  // Allow match for id shorter than range - assume "wildcards" for
144  // missing id fields
145  size_type nfields = (my_fields > id_fields) ? id_fields : my_fields;
146  // Test fields one by one.
147  for (size_type field_number = 0; field_number < nfields; field_number++) {
148  const field& f = m_fields[field_number];
149  if (!f.match (id[field_number])) return (0);
150  }
151  // All conditions match.
152  return (1);
153 }

◆ maximum()

ExpandedIdentifier Range::maximum ( ) const

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

187  {
188  size_type my_fields = m_fields.size ();
190  // Remove all by the last trailing wild card, extra ones are
191  // meaningless.
192  while ((my_fields > 1) &&
193  (m_fields[my_fields-1].empty())) {
194  my_fields--;
195  }
196 
197  // Ranges with only wild cards: set first field of min to ExpandedIdentifier::max_value
198  if (my_fields == 0) {
200  return result; // Don't combine these two lines --- it inhibits RVO.
201  }
202 
203  // Copy fields to result - look for wild cards
204  for (size_type field_number = 0; field_number < my_fields; field_number++) {
205  const field& f = m_fields[field_number];
206  if (f.empty()) {
207  // Wilds card
208  if (field_number == 0) {
209  // For 1st field set it to ExpandedIdentifier::max_value
211  } else {
212  //
213  // For subsequent fields, set do ++ for field-1
214  // This requires rebuilding the result
215  //
216  ExpandedIdentifier new_result;
217 
218  for (size_type new_field_number = 0;
219  new_field_number < (field_number - 1);
220  ++new_field_number) {
221  new_result << result[new_field_number];
222  }
223 
224  element_type last = result[field_number - 1];
225  new_result << ((ExpandedIdentifier::max_value == last) ? last : last + 1);
226  new_result << 0;
227  assert ( result.fields () == new_result.fields () );
228  result = new_result;
229  }
230  } else {
231  // Normal field
232  result << f.get_maximum ();
233  }
234  }
235 
236  return (result);
237 }

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

158  {
159  size_type my_fields = m_fields.size ();
161  // Remove trailing wild cards since they are meaningless.
162  while ((my_fields > 1) &&
163  (m_fields[my_fields-1].empty())){
164  my_fields--;
165  }
166  // Ranges with only wild cards: set first field of min to 0
167  if (my_fields == 0) {
168  result << 0;
169  return result; // Don't combine these two lines --- it inhibits RVO.
170  }
171  // Copy fields to result - look for wild cards
172  for (size_type field_number = 0; field_number < my_fields; field_number++) {
173  const field& f = m_fields[field_number];
174  if (f.empty()){
175  // Wilds card -> set field to 0
176  result << 0;
177  } else {
178  // Valued field
179  result << f.get_minimum ();
180  }
181  }
182 
183  return (result);
184 }

◆ operator std::string()

Range::operator std::string ( ) const

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

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

363  {
364  std::string result;
365  size_type my_fields = m_fields.size ();
366  // Remove trailing wild cards since they are meaningless.
367  while ((my_fields > 1) &&
368  (m_fields[my_fields-1].empty())) {
369  my_fields--;
370  }
371  if (my_fields == 0) return (result);
372  // print fields one by one.
373  for (size_type field_number = 0; field_number < my_fields; field_number++) {
374  const field& f = m_fields[field_number];
375  if (field_number > 0) result += "/";
376  result += (std::string) f;
377  }
378  return (result);
379 }

◆ operator==()

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

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

383  {
384  if (m_fields.size() != other.m_fields.size()) return false;
385  field_vector::const_iterator it1 = m_fields.begin();
386  field_vector::const_iterator it2 = other.m_fields.begin();
387  field_vector::const_iterator last = m_fields.end();
388  for (; it1 != last; ++it1, ++it2) {
389  if ((*it1) != (*it2)) return false;
390  }
391  return (true);
392 }

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

323  {
324  const Range& me = *this;
325  if ((fields () == 0) || (other.fields () == 0)) return (false);
326  for (size_type i = 0; i < std::min (fields (), other.fields ()); ++i){
327  const field& f1 = me[i];
328  const field& f2 = other[i];
329  if (!f1.overlaps_with (f2)) return (false);
330  }
331  return (true);
332 }

◆ show() [1/2]

void Range::show ( ) const

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

335  {
336  show (std::cout);
337 }

◆ show() [2/2]

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

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

339  {
340  const Range& me = *this;
341  s << (std::string) me << " (";
342  int allbits = 0;
343  for (size_type i = 0; i < fields (); ++i) {
344  const field& f = me[i];
345  if (i > 0) s << "+";
346  size_type indices = f.get_indices ();
347  int bits = 1;
348  indices--;
349  if (indices > 0) {
350  bits = 0;
351  while (indices > 0){
352  indices /= 2;
353  bits++;
354  }
355  }
356  allbits += bits;
357  s << bits;
358  }
359  s << "=" << allbits << ") ";
360 }

Member Data Documentation

◆ m_fields

field_vector Range::m_fields
private

The documentation for this class was generated from the following files:
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
fitman.sz
sz
Definition: fitman.py:527
get_generator_info.result
result
Definition: get_generator_info.py:21
max
#define max(a, b)
Definition: cfImp.cxx:41
Range::size_type
ExpandedIdentifier::size_type size_type
Definition: DetectorDescription/Identifier/Identifier/Range.h:33
Range::show
void show() const
Definition: DetectorDescription/Identifier/src/Range.cxx:335
index
Definition: index.py:1
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
Range::maximum
ExpandedIdentifier maximum() const
Definition: DetectorDescription/Identifier/src/Range.cxx:187
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
Range::field
IdentifierField field
Definition: DetectorDescription/Identifier/Identifier/Range.h:34
skel.it
it
Definition: skel.GENtoEVGEN.py:396
ExpandedIdentifier
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:102
athena.value
value
Definition: athena.py:124
ExpandedIdentifier::fields
size_type fields() const
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
ExpandedIdentifier::max_value
static constexpr element_type max_value
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:115
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
read_hist_ntuple.f2
f2
Definition: read_hist_ntuple.py:20
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Range::m_fields
field_vector m_fields
Definition: DetectorDescription/Identifier/Identifier/Range.h:145
Range::minimum
ExpandedIdentifier minimum() const
min and max ExpandedIdentifiers (if they exist, ie.
Definition: DetectorDescription/Identifier/src/Range.cxx:158
lumiFormat.i
int i
Definition: lumiFormat.py:85
DetDescrDictionaryDict::it1
std::vector< HWIdentifier >::iterator it1
Definition: DetDescrDictionaryDict.h:17
Range::Range
Range()=default
jobOptions.card
card
Definition: jobOptions.GenevaPy8_Zmumu.py:11
ReadOfcFromCool.nfields
nfields
Definition: ReadOfcFromCool.py:114
hist_file_dump.f
f
Definition: hist_file_dump.py:135
Range::fields
size_type fields() const
Definition: DetectorDescription/Identifier/Identifier/Range.h:151
min
#define min(a, b)
Definition: cfImp.cxx:40
Range
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition: DetectorDescription/Identifier/Identifier/Range.h:29
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
Range::cardinality
size_type cardinality() const
Computes a possible cardinality :
Definition: DetectorDescription/Identifier/src/Range.cxx:239
Range::build
void build(const std::string &text)
Build Range from a textual description.
Definition: DetectorDescription/Identifier/src/Range.cxx:58
Range::element_type
ExpandedIdentifier::element_type element_type
Definition: DetectorDescription/Identifier/Identifier/Range.h:32
fitman.k
k
Definition: fitman.py:528
read_hist_ntuple.f1
f1
Definition: read_hist_ntuple.py:4