ATLAS Offline Software
DetectorDescription/Identifier/src/ExpandedIdentifier.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 #include <algorithm>
8 #include <cstdarg>
9 #include <cstdio>
10 #include <cstring>
11 #include <iomanip>
12 #include <iostream>
13 
14 //-----------------------------------------------
15 static void show_vector (const ExpandedIdentifier::element_vector& v)
16 {
17  ExpandedIdentifier::element_vector::const_iterator it;
18  bool first = true;
19 
20  std::cout << "[";
21  for (it = v.begin (); it != v.end (); ++it)
22  {
23  if (first) first = false;
24  else std::cout << ".";
25 
27  std::cout << value;
28 
29  // if (value >= 0) std::cout << value;
30  // else std::cout << "*";
31  }
32  std::cout << "]";
33 }
34 
35 
36 //-----------------------------------------------
38 {
39  set (text);
40 }
41 
42 
43 //-----------------------------------------------
44 void ExpandedIdentifier::set (const std::string& text)
45 {
46  clear ();
47  if (text.empty()) return;
48  const char* ctext = text.c_str ();
49 
50  for (;;)
51  {
52 
53  const char* sep;
54 
55  sep = strchr (ctext, '/');
56 
57  int value = 0;
58  sscanf (ctext, "%80d", &value);
59 
61 
62  if (sep == nullptr) break;
63 
64  ctext = sep + 1;
65  }
66 }
67 
68 
69 //-----------------------------------------------
71 {
72  const ExpandedIdentifier& me = *this;
73  const size_type my_fields = fields ();
74  const size_type other_fields = other.fields ();
75 
76  //
77  // Scan fields up to the less common field number
78  //
79  size_type field = 0;
80  while ((field < my_fields) &&
81  (field < other_fields))
82  {
83  element_type my_field = me[field];
84  element_type other_field = other[field];
85 
86  if (my_field < other_field) return (1);
87  if (my_field > other_field) return (0);
88 
89  field++;
90  }
91 
92  return (0);
93 }
94 
95 //-----------------------------------------------
96 ExpandedIdentifier::operator std::string () const
97 {
98  std::string result;
99  char temp[20];
100 
101  size_type my_fields = m_fields.size ();
102 
103  if (my_fields == 0) return (result);
104 
105  // print fields one by one.
106  for (size_type field_number = 0; field_number < my_fields; field_number++)
107  {
108  element_type value = m_fields[field_number];
109 
110  if (field_number > 0) result += "/";
111 
112  sprintf (temp, "%d", value);
113  result += temp;
114  }
115 
116  return (result);
117 }
118 
119 //-----------------------------------------------
121 {
122  show_vector (m_fields);
123 }
124 
125 
get_generator_info.result
result
Definition: get_generator_info.py:21
ExpandedIdentifier::prefix_less
int prefix_less(const ExpandedIdentifier &other) const
Definition: DetectorDescription/Identifier/src/ExpandedIdentifier.cxx:70
ExpandedIdentifier::add
void add(element_type value)
skel.it
it
Definition: skel.GENtoEVGEN.py:423
ExpandedIdentifier
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:108
ExpandedIdentifier::show
void show() const
Definition: DetectorDescription/Identifier/src/ExpandedIdentifier.cxx:120
athena.value
value
Definition: athena.py:122
ExpandedIdentifier::fields
size_type fields() const
ExpandedIdentifier.h
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
ExpandedIdentifier::element_vector
boost::container::small_vector< element_type, 12 > element_vector
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:117
ExpandedIdentifier::set
void set(const std::string &text)
Definition: DetectorDescription/Identifier/src/ExpandedIdentifier.cxx:44
ExpandedIdentifier::m_fields
element_vector m_fields
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:218
grepfile.sep
sep
Definition: grepfile.py:38
python.PyAthena.v
v
Definition: PyAthena.py:157
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
DeMoScan.first
bool first
Definition: DeMoScan.py:534
ExpandedIdentifier::ExpandedIdentifier
ExpandedIdentifier()=default
ExpandedIdentifier::clear
void clear()
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
ExpandedIdentifier::size_type
boost::container::small_vector< element_type, 12 >::size_type size_type
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:122
ExpandedIdentifier::element_type
int element_type
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:116