CARMA C++
CarmaConfig.h
Go to the documentation of this file.
1 // $Id: CarmaConfig.h,v 1.4 2012/06/27 18:05:09 eml Exp $
2 
3 #ifndef SZA_UTIL_CARMACONFIG_H
4 #define SZA_UTIL_CARMACONFIG_H
5 
15 #include "carma/szautil/Angle.h"
18 #include "carma/szautil/Length.h"
19 #include "carma/szautil/Mutex.h"
20 #include "carma/szautil/Percent.h"
21 
22 #include <iostream>
23 #include <string>
24 #include <vector>
25 
26 #ifdef CARMA
27 #undef CARMA
28 #endif
29 
30 namespace sza {
31  namespace util {
32 
33  class CarmaConfig {
34  public:
35 
36  //------------------------------------------------------------
37  // Struct to encapsulate an antenna
38  //------------------------------------------------------------
39 
40  struct Antenna {
41 
42  int antNumber_; // The number of the antenna
43  // associated with this pad
44  sza::util::Length diameter_;
45  sza::util::Length sweptVolumeDiameter_;
46  sza::util::Length elAxisHeight_;
47  sza::util::Length cylinderDiameter_;
48 
49  unsigned antFlag_;
50  bool tracking_;
51  unsigned subarrayNumber_;
52 
53  Antenna() {
54  antNumber_ = -1;
55  tracking_ = false;
56  subarrayNumber_ = 0;
57  }
58 
59  Antenna(const Antenna& location) {
60  *this = location;
61  }
62 
63  Antenna(Antenna& location) {
64  *this = location;
65  }
66 
67  void operator=(const Antenna& location) {
68  *this = (Antenna&) location;
69  }
70 
71 
72  void operator=(Antenna& ant) {
73  antNumber_ = ant.antNumber_;
74  diameter_ = ant.diameter_;
75  sweptVolumeDiameter_ = ant.sweptVolumeDiameter_;
76  elAxisHeight_ = ant.elAxisHeight_;
77  cylinderDiameter_ = ant.cylinderDiameter_;
78  antFlag_ = ant.antFlag_;
79  tracking_ = ant.tracking_;
80  subarrayNumber_ = ant.subarrayNumber_;
81  }
82 
83  sza::util::AntennaType::Type getAntType();
84 
85  // Write the contents of this object to an ostream
86 
87  std::string antType();
88 
89  // Allows cout << Antenna
90 
91  friend std::ostream& operator<<(std::ostream& os, Antenna& pad);
92  };
93 
94  //------------------------------------------------------------
95  // Flags to indicate which antennas occupy a pad in which
96  // configuration
97  //------------------------------------------------------------
98 
99  enum Config {
100  NONE = 0x0,
101  UNKNOWN= 0x0,
102 
103  A_OVRO = 0x1,
104  A_BIMA = 0x2,
105 
106  A = A_OVRO | A_BIMA,
107 
108  B_OVRO = 0x4,
109  B_BIMA = 0x8,
110 
111  B = B_OVRO | B_BIMA,
112 
113  C_OVRO = 0x10,
114  C_BIMA = 0x20,
115 
116  C = C_OVRO | C_BIMA,
117 
118  D_OVRO = 0x40,
119  D_BIMA = 0x80,
120 
121  D = D_OVRO | D_BIMA,
122 
123  E_OVRO = 0x100,
124  E_BIMA = 0x200,
125 
126  E = E_OVRO | E_BIMA,
127 
128  H_SZA = 0x400,
129  L_SZA = 0x800,
130  I_SZA = 0x1000,
131  BP_SZA = 0x2000,
132  AP_SZA = 0x4000,
133 
134  H = H_SZA,
135  L = L_SZA,
136  I = I_SZA,
137  BP = BP_SZA,
138  AP = AP_SZA,
139 
140  BO_OVRO = 0x8000,
141  BO_BIMA = 0x10000,
142 
143  BO = BO_OVRO | BO_BIMA,
144 
145  CO_OVRO = 0x20000,
146  CO_BIMA = 0x40000,
147 
148  CO = CO_OVRO | CO_BIMA,
149 
150  DO_OVRO = 0x80000,
151  DO_BIMA = 0x100000,
152 
153  DO = DO_OVRO | DO_BIMA,
154 
155  ANY = A|B|C|D|E|H|L|I|BO|CO|DO,
156 
157  BIMA = A_BIMA|B_BIMA|C_BIMA|D_BIMA|E_BIMA|BO_BIMA|CO_BIMA|DO_BIMA,
158  OVRO = A_OVRO|B_OVRO|C_OVRO|D_OVRO|E_OVRO|BO_OVRO|CO_OVRO|DO_OVRO,
159  CARMA = BIMA|OVRO,
160  SZA = H_SZA|L_SZA|I_SZA|BP_SZA|AP_SZA
161  };
162 
163  //-----------------------------------------------------------------------
164  // Struct to encapsulate a pad location
165  //-----------------------------------------------------------------------
166 
167  struct PadLocation {
168 
169  unsigned flags_; // A bitmask of antennas that occupy this
170  // pad in each configuration
171  unsigned padNumber_;// The CARMA pad number (NB: these are NOT
172  // consecutive!)
173  sza::util::Length east_; // The east location of this pad
174  // (relative to pad 32)
175  sza::util::Length north_; // The north location of this pad
176  // (relative to pad 32)
177  sza::util::Length up_; // The vertical location of this pad
178  // (relative to pad 32)
179 
180  CarmaConfig::Antenna ant_;// The antenna currently located on this pad
181 
182  bool validity_; // Utility to store validity
183  // information about this pad -- not
184  // used for anything at the moment,
185  // outside of plotting on
186  // ConfigPlotter
187 
188  PadLocation() {};
189  virtual ~PadLocation() {};
190 
191  PadLocation(unsigned padNumber,
192  double eastInMeters, double northInMeters,
193  double upInMeters,
194  unsigned occupationFlags) {
195 
196  padNumber_ = padNumber;
197  east_.setMeters(eastInMeters);
198  north_.setMeters(northInMeters);
199  up_.setMeters(upInMeters);
200  flags_ = occupationFlags;
201  validity_ = true;
202  }
203 
204  PadLocation(const PadLocation& location) {
205  *this = location;
206  }
207 
208  PadLocation(PadLocation& location) {
209  *this = location;
210  }
211 
212  void operator=(const PadLocation& location) {
213  *this = (PadLocation&) location;
214  }
215 
216  void operator=(PadLocation& location) {
217  east_ = location.east_;
218  north_ = location.north_;
219  up_ = location.up_;
220  flags_ = location.flags_;
221  padNumber_ = location.padNumber_;
222  ant_ = location.ant_;
223  validity_ = location.validity_;
224  }
225 
226  // Allows cout << PadLocation
227 
228  friend std::ostream& operator<<(std::ostream& os, PadLocation& pad);
229 
230  // Return true if this antenna is shadowed by the passed ant,
231  // in the current pointing position
232 
233  bool isShadowed(Angle& az, Angle& el, PadLocation& pad);
234 
235  // More general method that allows for shadowing percentages
236  // to be specified
237 
238  bool isShadowed(Angle& az0, Angle& el0, PadLocation& pad,
239  bool useSweptVolumeDiameter,
240  Percent& percent, bool isPercentOfDiameter, bool verbose=false);
241 
242  double shadowedArea(double radiusShadowedAnt, double radiusShadowingAnt, double sep);
243 
244  std::string listConfigs();
245 
246  void addConf(std::ostringstream& os, bool& prev,
247  unsigned flags, unsigned conf);
248  };
249 
250  // Constructor.
251 
252  CarmaConfig();
253 
254  // Destructor.
255 
256  virtual ~CarmaConfig();
257 
258  CarmaConfig(const CarmaConfig& conf);
259  CarmaConfig(CarmaConfig& conf);
260  void operator=(const CarmaConfig& conf);
261  void operator=(CarmaConfig& conf);
262 
263  //-----------------------------------------------------------------------
264  // Utility functions
265  //-----------------------------------------------------------------------
266 
267  // Return true if padNumber is occupied for the configuration
268  // specified
269 
270  bool isOccupied(unsigned padNumber, unsigned configFlag);
271 
272  // Return an Antenna struct populated with the correct
273  // information for this antenna type
274 
275  static Antenna getAntennaInfo(unsigned configFlag);
276 
277  // Associate a pad number with an antenna number in the passed
278  // configuration of pads
279 
280  void associatePadAndAntenna(std::vector<PadLocation>& pads,
281  unsigned padNumber, unsigned antNumber);
282 
283  // Same as above, but for current configuration
284 
285  void associatePadAndAntenna(unsigned padNumber, unsigned antNumber);
286 
287  //-----------------------------------------------------------------------
288  // Return known configurations
289  //-----------------------------------------------------------------------
290 
291  std::vector<PadLocation> getConfiguration(unsigned flag);
292 
293  std::vector<PadLocation> getConfiguration(std::string name);
294 
295  // Return known SZA configurations
296 
297  std::vector<PadLocation> getSzaImagingConfiguration();
298  std::vector<PadLocation> getSzaLowDecConfiguration();
299  std::vector<PadLocation> getSzaHighDecConfiguration();
300  std::vector<PadLocation> getSzaBPConfiguration();
301  std::vector<PadLocation> getSzaAPConfiguration();
302 
303  // Associate pads with antenna numbers for known SZA
304  // configurations
305 
306  void associateSzaImagingConfiguration(std::vector<PadLocation>& pads);
307  void associateSzaLowDecConfiguration(std::vector<PadLocation>& pads);
308  void associateSzaHighDecConfiguration(std::vector<PadLocation>& pads);
309  void associateSzaAPConfiguration(std::vector<PadLocation>& pads);
310  void associateSzaBPConfiguration(std::vector<PadLocation>& pads);
311 
312  // Sort a configuration by antenna number
313 
314  std::vector<PadLocation> sortByAntNumber(std::vector<PadLocation>& pads);
315 
316  //-----------------------------------------------------------------------
317  // Create an arbitrary array out of existing pad locations
318  //-----------------------------------------------------------------------
319 
320  void initializeCurrentConfiguration();
321  void setCurrentConfiguration(unsigned flag);
322  void setCurrentConfiguration(std::string name);
323  void setCurrentConfiguration(ArrayConfig::Type type);
324  void addPad(unsigned padNumber, unsigned antType, int antNumber=-1);
325  void removePad(unsigned padNumber);
326  void addPad(std::vector<PadLocation>& pads);
327  void removePad(std::vector<PadLocation>& pads);
328  std::vector<PadLocation> getCurrentConfiguration();
329  std::vector<PadLocation> getAllPads();
330 
331  static unsigned confNameToFlag(std::string name);
332  static unsigned confTypeToFlag(ArrayConfig::Type type);
333  static std::string confFlagToName(unsigned flag);
334  static ArrayConfig::Type confFlagToType(unsigned flag);
335 
336  std::string confName() {
337  return confFlagToName(currentConfFlag_);
338  }
339 
340  ArrayConfig::Type confType() {
341  return confFlagToType(currentConfFlag_);
342  }
343 
344  Mutex guard_;
345  unsigned currentConfFlag_;
346 
347  PadLocation findNearest(Length east, Length north);
348 
349  private:
350 
351  bool padLabels_;
352 
353  PadLocation getPadByNumber(unsigned padNumber);
354 
355  void initializeCarmaPadLocations();
356 
357  // The full array of known pad locations
358 
359  std::vector<PadLocation> padLocations_;
360 
361  // A user-defined configuration, built out of known pad
362  // locations
363 
364  public:
365  std::vector<PadLocation> currentConfiguration_;
366 
367  }; // End class CarmaConfig
368 
369  } // End namespace util
370 } // End namespace sza
371 
372 
373 
374 #endif // End #ifndef SZA_UTIL_CARMACONFIG_H
Tagged: Mon Aug 17 11:01:48 PDT 2009.
Tagged: Thu Oct 9 22:48:42 PDT 2008.
Tagged: Sat Mar 27 16:28:13 PST 2004.
Tagged: Wed Oct 15 14:14:12 PDT 2008.