QwAnalysis
QwGeometry.h
Go to the documentation of this file.
1 /*
2  * QwGeometry.h
3  *
4  * Created on: Mar 29, 2011
5  * \author: wdconinc
6  */
7 
8 #ifndef QWGEOMETRY_H_
9 #define QWGEOMETRY_H_
10 
11 // System headers
12 #include <vector>
13 #include <algorithm>
14 
15 // Qweak headers
16 #include "QwDetectorInfo.h"
17 
18 // Forward declarations
19 class QwDetectorInfo;
20 
21 /**
22  * \class QwGeometry
23  * \ingroup QwTracking
24  *
25  * \brief Collection of QwDetectorInfo pointers that specifies an experimental geometry
26  */
27 class QwGeometry: public std::vector<QwDetectorInfo*> {
28 
29  private:
30 
31  /// Functor for sorting QwDetectorInfo pointers
32  struct compare {
33  bool operator()(const QwDetectorInfo *lhs, const QwDetectorInfo *rhs) { return *lhs < *rhs; }
34  };
35 
36  public:
37 
38  /// Default constructor
39  QwGeometry() { clear(); };
40  /// Copy constructor
41  QwGeometry(const QwGeometry& that): std::vector<QwDetectorInfo*>(that) { };
42  /// Virtual destructor
43  virtual ~QwGeometry() { };
44 
45  /// Assignment operator
47  if (this != &that) {
48  clear();
49  push_back(that);
50  }
51  return *this;
52  }
53 
54  /// Add single detector object
55  void push_back(QwDetectorInfo& detector) {
56  std::vector<QwDetectorInfo*>::push_back(&detector);
57  std::sort(begin(),end(),compare());
58  }
59 
60  /// Add single detector pointer
61  void push_back(QwDetectorInfo* detector) {
62  std::vector<QwDetectorInfo*>::push_back(detector);
63  std::sort(begin(),end(),compare());
64  }
65 
66  /// Add another geometry
67  void push_back(const QwGeometry& detectors) {
68  QwGeometry::const_iterator i;
69  for (i = detectors.begin(); i != detectors.end(); i++)
70  std::vector<QwDetectorInfo*>::push_back(*i);
71  std::sort(begin(),end(),compare());
72  }
73 
74  /// Add vector of detectors
75  void push_back(std::vector<QwDetectorInfo>& detectors) {
76  std::vector<QwDetectorInfo>::iterator i;
77  for (i = detectors.begin(); i != detectors.end(); i++)
78  std::vector<QwDetectorInfo*>::push_back(&(*i));
79  std::sort(begin(),end(),compare());
80  }
81 
82  /// Get detectors by name
83  const QwGeometry name(const std::string& name) {
84  QwGeometry results;
85  for (const_iterator i = begin(); i != end(); i++)
86  if ((*i)->GetDetectorName() == name)
87  results.push_back(*i);
88  return results;
89  }
90 
91  /// Get detectors in given region
92  const QwGeometry in(const EQwRegionID& r) const {
93  QwGeometry results;
94  for (const_iterator i = begin(); i != end(); i++)
95  if ((*i)->GetRegion() == r)
96  results.push_back(*i);
97  return results;
98  }
99 
100  /// Get detectors in given package
101  const QwGeometry in(const EQwDetectorPackage& p) const {
102  QwGeometry results;
103  for (const_iterator i = begin(); i != end(); i++)
104  if ((*i)->GetPackage() == p)
105  results.push_back(*i);
106  return results;
107  }
108 
109  /// Get detectors in given direction
110  const QwGeometry in(const EQwDirectionID& d) const {
111  QwGeometry results;
112  for (const_iterator i = begin(); i != end(); i++)
113  if ((*i)->GetDirection() == d)
114  results.push_back(*i);
115  return results;
116  }
117 
118  /// Get detectors of given type
119  const QwGeometry of(const EQwDetectorType& t) const {
120  QwGeometry results;
121  for (const_iterator i = begin(); i != end(); i++)
122  if ((*i)->GetType() == t)
123  results.push_back(*i);
124  return results;
125  }
126 
127  /// Get detectors like specified detector (same region, same package, same type)
128  const QwGeometry as(const QwDetectorInfo* d) const {
129  QwGeometry results;
130  for (const_iterator i = begin(); i != end(); i++)
131  if ((*i)->GetPackage() == d->GetPackage()
132  && (*i)->GetRegion() == d->GetRegion()
133  && (*i)->GetDirection() == d->GetDirection()
134  && (*i)->GetType() == d->GetType())
135  results.push_back(*i);
136  return results;
137  }
138 
139  // Print function
140  void Print() const;
141 
142  // Output stream operator
143  friend std::ostream& operator<< (std::ostream& stream, const QwGeometry& detectors);
144 
145 };
146 
147 /**
148  * Print function
149  */
150 inline void QwGeometry::Print() const
151 {
152  for (QwGeometry::const_iterator i = begin(); i != end(); i++) {
153  if (*i)
154  (*i)->Print();
155  else
156  QwOut << "(null)" << QwLog::endl;
157  QwOut << QwLog::endl;
158  }
159 }
160 
161 /**
162  * Output stream operator
163  * @param stream Output stream
164  * @param detectors Detector geometry object
165  * @return Output stream
166  */
167 inline std::ostream& operator<< (std::ostream& stream, const QwGeometry& detectors)
168 {
169  for (QwGeometry::const_iterator i = detectors.begin(); i != detectors.end(); i++) {
170  if (*i)
171  stream << *(*i) << std::endl;
172  else
173  stream << "(null)" << std::endl;
174  }
175  return stream;
176 }
177 
178 #endif /* QWGEOMETRY_H_ */
const QwGeometry in(const EQwDetectorPackage &p) const
Get detectors in given package.
Definition: QwGeometry.h:101
Functor for sorting QwDetectorInfo pointers.
Definition: QwGeometry.h:32
#define QwOut
Predefined log drain for explicit output.
Definition: QwLog.h:35
void push_back(QwDetectorInfo &detector)
Add single detector object.
Definition: QwGeometry.h:55
QwGeometry(const QwGeometry &that)
Copy constructor.
Definition: QwGeometry.h:41
std::ostream & operator<<(std::ostream &out, const QwColor &color)
Output stream operator which uses the enum-to-escape-code mapping.
Definition: QwColor.h:153
const QwGeometry in(const EQwRegionID &r) const
Get detectors in given region.
Definition: QwGeometry.h:92
EQwDetectorPackage GetPackage() const
void push_back(const QwGeometry &detectors)
Add another geometry.
Definition: QwGeometry.h:67
EQwRegionID GetRegion() const
EQwDirectionID GetDirection() const
EQwDetectorPackage
Definition: QwTypes.h:70
const QwGeometry as(const QwDetectorInfo *d) const
Get detectors like specified detector (same region, same package, same type)
Definition: QwGeometry.h:128
const QwGeometry name(const std::string &name)
Get detectors by name.
Definition: QwGeometry.h:83
EQwDetectorType
Definition: QwTypes.h:94
EQwRegionID
Definition: QwTypes.h:16
void Print() const
Definition: QwGeometry.h:150
friend std::ostream & operator<<(std::ostream &stream, const QwGeometry &detectors)
Definition: QwGeometry.h:167
void push_back(QwDetectorInfo *detector)
Add single detector pointer.
Definition: QwGeometry.h:61
bool operator()(const QwDetectorInfo *lhs, const QwDetectorInfo *rhs)
Definition: QwGeometry.h:33
EQwDetectorType GetType() const
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
EQwDirectionID
Definition: QwTypes.h:41
Collection of QwDetectorInfo pointers that specifies an experimental geometry.
Definition: QwGeometry.h:27
const QwGeometry of(const EQwDetectorType &t) const
Get detectors of given type.
Definition: QwGeometry.h:119
virtual ~QwGeometry()
Virtual destructor.
Definition: QwGeometry.h:43
QwGeometry & operator=(const QwGeometry &that)
Assignment operator.
Definition: QwGeometry.h:46
usr bin c fPIC std
QwGeometry()
Default constructor.
Definition: QwGeometry.h:39
void push_back(std::vector< QwDetectorInfo > &detectors)
Add vector of detectors.
Definition: QwGeometry.h:75
const QwGeometry in(const EQwDirectionID &d) const
Get detectors in given direction.
Definition: QwGeometry.h:110