ATLAS Offline Software
LArG4Identifier.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // LArG4Identifier.hh
6 // 01-Jul-2002 Bill Seligman
7 
8 // This is code copied (dare I use the word stolen?) from the Athena
9 // Identifier class, as implemented by RD Schaffer and Christian
10 // Arnault. It was slightly modified by Bill Seligman for ROOT/G4
11 // compatibility.
12 
13 // If you're an Athena user, you're probably wondering: why steal the
14 // code? Why not just include the files from the Athena libraries?
15 // The answer is that I still want the LArG4Sim application to run in
16 // stand-alone mode, without any access to the Athena libraries. If
17 // this ever becomes an Athena-only application, we can make the
18 // switch.
19 
20 #ifndef LARG4CODE_LARG4IDENTIFIER_H
21 #define LARG4CODE_LARG4IDENTIFIER_H
22 
23 // LArG4Identifier :
24 //
25 // Stores a set of numbers.
26 //
27 // ---------------------------------------------------
28 //
29 // ------------------------
30 // Possible operations :
31 // ------------------------
32 //
33 // ------------------------
34 // Constructors:
35 // ------------------------
36 //
37 // LArG4Identifier () : default constructor
38 //
39 // LArG4Identifier (const std::string& text) : build an identifier from a textual
40 // description following the syntax
41 // <value> [ "/" <value> ... ]
42 //
43 // LArG4Identifier (const LArG4Identifier& other) : copy constructor
44 //
45 // LArG4Identifier (const LArG4Identifier& other,
46 // size_type start) : subset constructor
47 //
48 // ------------------------
49 // Initialisations:
50 // ------------------------
51 //
52 // void clear () : clears up the identifier
53 //
54 // void set (const std::string& text) : set from a textual description
55 //
56 // ------------------------
57 // Modifications:
58 // ------------------------
59 //
60 // void add (element_type value) : appends a numeric value to
61 // an identifier (adds a field).
62 //
63 // LArG4Identifier& operator << (element_type value) : appends a numeric value to
64 // an identifier (adds a field).
65 //
66 // ------------------------
67 // Accessors:
68 // ------------------------
69 //
70 // size_type fields () : returns the number of fields
71 // currently stored into the
72 // identifier.
73 //
74 // element_type operator [] (size_type field) : gets the value stored at the
75 // specified field number.
76 //
77 // ------------------------
78 // Comparison operators:
79 // ------------------------
80 //
81 // operator < (id_type& other) : absolute comparison,
82 //
83 // e.g. :
84 //
85 // /1/2 < /1/3
86 // /1 < /1/3
87 // /1 is implicitly /1/0...
88 //
89 // prefix_less (id_type& other) : comparison on the equal length
90 // prefix parts of two ids,
91 //
92 // e.g. :
93 //
94 // /1/2 < /1/3,
95 // but now
96 // /1 == /1/3
97 //
98 //
99 // ----------------------------------------------------
100 //
101 // Example of how to use an identifier :
102 //
103 // #include <LArG4Identifier.h>
104 //
105 // LArG4Identifier id;
106 //
107 // id << 125 << 236 << 306 << 2222;
108 //
109 // for (size_type i = 0; i < id.fields (); ++i)
110 // {
111 // cout << "id[" << i << "] = " << id[i] << endl;
112 // }
113 //
114 //-----------------------------------------------
115 
116 #include <vector>
117 #include <string>
118 #include <limits.h>
119 
121 {
122 public:
123 
124 
125  //----------------------------------------------------------------
126  // Define public typedefs
127  //----------------------------------------------------------------
128  typedef short element_type; // WGS
129  typedef std::vector<element_type> element_vector;
130  typedef std::vector<element_type>::size_type size_type;
131 
132  typedef enum
133  {
134  max_value = SHRT_MAX
136 
137  //----------------------------------------------------------------
138  // Constructors
139  //----------------------------------------------------------------
140 
141  //----------------------------------------------------------------
142  // Default constructor
143  //----------------------------------------------------------------
145 
146  //----------------------------------------------------------------
147  // Copy constructor
148  //----------------------------------------------------------------
150 
151  //----------------------------------------------------------------
152  // Constructor from a subset of another LArG4Identifier
153  //----------------------------------------------------------------
155 
156  //----------------------------------------------------------------
157  // Constructor from a textual description
158  //----------------------------------------------------------------
159  LArG4Identifier (const std::string& text);
160 
161  virtual ~LArG4Identifier() {};
162 
163  //----------------------------------------------------------------
164  // Modifications
165  //----------------------------------------------------------------
166 LArG4Identifier& operator=(const LArG4Identifier&);//coverity issue fix.
167 
168  //----------------------------------------------------------------
169  // Append a value into a new field.
170  //----------------------------------------------------------------
174 
175  //----------------------------------------------------------------
176  // build from a textual description
177  //----------------------------------------------------------------
178  void set (const std::string& text);
179 
180  //----------------------------------------------------------------
181  // Erase all fields.
182  // All previously stored data is lost.
183  //----------------------------------------------------------------
184  void clear ();
185 
186  //----------------------------------------------------------------
187  // Accessors
188  //----------------------------------------------------------------
189 
190  //----------------------------------------------------------------
191  // Get the value stored into the specified field.
192  //----------------------------------------------------------------
194 
195  //----------------------------------------------------------------
196  // Count the number of fields.
197  //----------------------------------------------------------------
198  size_type fields () const;
199 
200  //----------------------------------------------------------------
201  // Comparison operators
202  //----------------------------------------------------------------
203 
204  int operator == (const LArG4Identifier& other) const;
205  int operator != (const LArG4Identifier& other) const;
206  int operator < (const LArG4Identifier& other) const;
207  int operator > (const LArG4Identifier& other) const;
208  int prefix_less (const LArG4Identifier& other) const;
209 
214  int match (const LArG4Identifier& other) const;
215 
216  //----------------------------------------------------------------
217  // Utilities
218  //----------------------------------------------------------------
219 
220  //----------------------------------------------------------------
221  // Send a textual representation of the identifier using the input format
222  //----------------------------------------------------------------
223  operator std::string () const;
224 
225  void show () const;
226 
227 private:
228 
229 
230  //----------------------------------------------------------------
231  // The actual identifier data.
232  //----------------------------------------------------------------
234 
235 };
236 
237 #endif // LARG4CODE_LARG4IDENTIFIER_H
LArG4Identifier::operator<<
LArG4Identifier & operator<<(element_type value)
LArG4Identifier::element_vector
std::vector< element_type > element_vector
Definition: LArG4Identifier.h:129
LArG4Identifier
Definition: LArG4Identifier.h:121
LArG4Identifier::match
int match(const LArG4Identifier &other) const
Test if the shorter of two ids is identical to the equivalent sub-id extracted from the longer.
LArG4Identifier::show
void show() const
index
Definition: index.py:1
LArG4Identifier::operator==
int operator==(const LArG4Identifier &other) const
LArG4Identifier::~LArG4Identifier
virtual ~LArG4Identifier()
Definition: LArG4Identifier.h:161
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
LArG4Identifier::clear
void clear()
athena.value
value
Definition: athena.py:124
LArG4Identifier::set
void set(const std::string &text)
LArG4Identifier::operator=
LArG4Identifier & operator=(const LArG4Identifier &)
LArG4Identifier::operator<
int operator<(const LArG4Identifier &other) const
LArG4Identifier::m_fields
element_vector m_fields
Definition: LArG4Identifier.h:233
LArG4Identifier::prefix_less
int prefix_less(const LArG4Identifier &other) const
LArG4Identifier::element_type
short element_type
Definition: LArG4Identifier.h:128
LArG4Identifier::add
void add(element_type value)
LArG4Identifier::LArG4Identifier
LArG4Identifier(const LArG4Identifier &other)
LArG4Identifier::LArG4Identifier
LArG4Identifier()
LArG4Identifier::operator>
int operator>(const LArG4Identifier &other) const
LArG4Identifier::max_value
@ max_value
Definition: LArG4Identifier.h:134
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
LArG4Identifier::LArG4Identifier
LArG4Identifier(const LArG4Identifier &other, size_type start)
LArG4Identifier::fields
size_type fields() const
LArG4Identifier::operator[]
element_type & operator[](size_type index)
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
LArG4Identifier::operator!=
int operator!=(const LArG4Identifier &other) const
LArG4Identifier::size_type
std::vector< element_type >::size_type size_type
Definition: LArG4Identifier.h:130
LArG4Identifier::max_value_type
max_value_type
Definition: LArG4Identifier.h:133
LArG4Identifier::LArG4Identifier
LArG4Identifier(const std::string &text)