CARMA C++
arraymap.h
1 #ifndef arraymap_h
2 #define arraymap_h
3 
4 #include "carma/szaarrayutils/regmap.h"
5 #include "carma/szaarrayutils/hash.h"
6 #include "carma/szaarrayutils/netbuf.h"
7 #include "carma/szaarrayutils/input.h"
8 #include "carma/szaarrayutils/output.h"
9 
10 #include <map>
11 
12 #define KLUDGE
13 
14 /*
15  * Define type aliases for the structures that are being declared
16  * below.
17  */
18 typedef struct ArrayMap ArrayMap;
19 typedef struct ArrRegMap ArrRegMap;
20 typedef struct ArrRegMapReg ArrRegMapReg;
21 /*
22  * A structure of the following type is used to encapsulate a single
23  * register block from an array map
24  */
25 struct ArrRegMapReg {
26  unsigned regmap; // The index of the specified regmap in the array map
27  RegMapReg reg;
28 };
29 
30 int find_ArrRegMapReg(ArrayMap* arraymap,
31  std::string regmap_name, std::string board_name, std::string block_name,
32  RegAspect facet, unsigned index, unsigned n,
33  ArrRegMapReg *reg);
34 
35 int init_ArrRegMapReg(ArrayMap* arraymap,
36  unsigned regmap, unsigned board, unsigned block,
37  unsigned index, unsigned nreg, RegAspect aspect,
38  ArrRegMapReg *reg);
39 
40 RegValidity input_ArrRegMapReg(InputStream *stream, int tell,
41  ArrayMap* arraymap, RegInputMode mode,
42  int extend, ArrRegMapReg *reg);
43 
44 int output_ArrRegMapReg(OutputStream *stream, ArrayMap* arraymap,
45  RegOutputMode mode, ArrRegMapReg *reg);
46 
47 void clr_ArrRegMapReg(ArrRegMapReg *reg);
48 
49 /*
50  * Collect information about a register map.
51  */
52 struct ArrRegMap {
53  char name[REG_NAME_LEN+1]; // An unambiguous name for the register map
54  std::string* comment_;
55 
56  unsigned number; // The index of this register map in the
57  // parent array map
58  int slot; // The start index of this register map
59  // in the archive array
60  unsigned iSlot_; // The start index of this register map
61  // in the slot array
62  int iArcSlot_; // The start index of this register map
63  // in the archive slot array
64  unsigned iByte_; // The sequential byte index of this
65  // register map in the array map
66  int iArcByte_; // The sequential byte index of this
67  // register map in the archived array
68  // map, or -1 if this register map
69  // contains no archived registers in the
70  // archive byte array
71  RegMap *regmap; // Pointer to the register map
72 
73  // Constructor
74 
75  ArrRegMap(ArrayMap* parent, void* vregtemp, unsigned iRegMap, bool old=false, bool addPerBrdRegs=true);
76 
77  ArrRegMap();
78 
79  // Destructor
80 
81  ~ArrRegMap();
82 
83  // Return the byte offset in the ArrayMap of this ArrRegMap
84 
85  int byteOffsetInArcArrayMap() {
86  return iArcByte_;
87  };
88 
89  int byteOffsetInWholeArrayMap() {
90  return iByte_;
91  };
92 
93  // Convenience method for the above
94 
95  int byteOffsetInArrayMap(bool archivedOnly) {
96  return archivedOnly ? byteOffsetInArcArrayMap() :
97  byteOffsetInWholeArrayMap();
98  }
99 
100  // Return the byte offset in the ArrayMap of the named block
101 
102  int byteOffsetInArcArrayMapOf(RegMapBlock* block, sza::util::Coord* coord=0);
103  int byteOffsetInWholeArrayMapOf(RegMapBlock* block, sza::util::Coord* coord=0);
104 
105  // Convenience method
106 
107  int byteOffsetInArrayMapOf(bool archivedOnly,
108  RegMapBlock* block, sza::util::Coord* coord=0)
109  {
110  return archivedOnly ? byteOffsetInArcArrayMapOf(block, coord) :
111  byteOffsetInWholeArrayMapOf(block, coord);
112  }
113 
114  // Return the slot offset in the ArrayMap of this ArrRegMap
115 
116  int slotOffsetInArcArrayMap() {
117  return iArcSlot_;
118  };
119 
120  int slotOffsetInWholeArrayMap() {
121  return iSlot_;
122  };
123 
124  // Convenience method for the above
125 
126  int slotOffsetInArrayMap(bool archivedOnly) {
127  return archivedOnly ? slotOffsetInArcArrayMap() :
128  slotOffsetInWholeArrayMap();
129  }
130 
131  // Return the slot offset in the ArrayMap of the named block
132 
133  int slotOffsetInArcArrayMapOf(RegMapBlock* block, sza::util::Coord* coord=0);
134  int slotOffsetInWholeArrayMapOf(RegMapBlock* block, sza::util::Coord* coord=0);
135 
136  // Convenience method
137 
138  int slotOffsetInArrayMapOf(bool archivedOnly,
139  RegMapBlock* block, sza::util::Coord* coord=0)
140  {
141  return archivedOnly ? slotOffsetInArcArrayMapOf(block, coord) :
142  slotOffsetInWholeArrayMapOf(block, coord);
143  }
144 
145  // Return byte statistics for this register map
146 
147  unsigned nByte() {return regmap->nByte();};
148  unsigned nArcByte() {return regmap->nArcByte();};
149 
150  // Convenience method for the above
151 
152  int nByte(bool archivedOnly) {
153  return archivedOnly ? nArcByte() : nByte();
154  }
155 
156  // Return a vector of boards matching the input string
157 
158  std::vector<RegMapBoard*> matchRegMapBoard(std::string regExpString);
159  std::vector<RegMapBoard*> matchRegMapBoard(std::string regExpString, sza::util::CoordRange& range);
160  std::vector<RegMapBoard*> matchRegMapBoard(std::vector<std::string>& boards);
161 };
162 
163 /*
164  * Collect information about all register maps.
165  */
166 struct ArrayMap {
167  unsigned ref_count; /* Reference counter */
168  std::vector<ArrRegMap*> regmaps; /* All register maps in this array */
169  int nregmap; /* The number of register maps */
170  unsigned nreg; /* The total number of registers */
171  unsigned narchive; /* The total number of archived registers */
172  unsigned nByte_; /* The total number of bytes */
173  unsigned nArcByte_; /* The total number of archived bytes */
174  std::map<std::string, ArrRegMap*> regmapMap_;
175 
176  // Constructor
177 
178  ArrayMap(void* vtmp, bool old=false, bool addPerBrdRegs=true);
179  ArrayMap();
180 
181  // Destructor
182 
183  ~ArrayMap();
184 
185  // Return the offset, in bytes_ of the named board and block from
186  // the start of the archived array
187 
188  int byteOffsetInArcArrayMapOf(std::string regmap, std::string board,
189  std::string block,
190  sza::util::Coord* coord=0);
191 
192  int byteOffsetInWholeArrayMapOf(std::string regmap, std::string board,
193  std::string block,
194  sza::util::Coord* coord=0);
195 
196  // Convenience method
197 
198  int byteOffsetOf(bool archivedOnly, std::string regmap, std::string board,
199  std::string block,
200  sza::util::Coord* coord=0)
201  {
202  return archivedOnly ?
203  byteOffsetInArcArrayMapOf(regmap, board, block, coord) :
204  byteOffsetInWholeArrayMapOf(regmap, board, block, coord);
205  }
206 
207  // Byte offsets
208 
209  int byteOffsetInArcArrayMapOf(ArrRegMap* aregmap, RegMapBlock* block,
210  sza::util::Coord* coord=0);
211 
212  int byteOffsetInWholeArrayMapOf(ArrRegMap* aregmap, RegMapBlock* block,
213  sza::util::Coord* coord=0);
214 
215  // Convenience method
216 
217  int byteOffsetOf(bool archivedOnly, ArrRegMap* aregmap, RegMapBlock* block,
218  sza::util::Coord* coord=0)
219  {
220  return archivedOnly ? byteOffsetInArcArrayMapOf(aregmap, block, coord) :
221  byteOffsetInWholeArrayMapOf(aregmap, block, coord);
222  }
223 
224  // Slot offsets
225 
226  int slotOffsetInArcArrayMapOf(ArrRegMap* aregmap, RegMapBlock* block,
227  sza::util::Coord* coord=0);
228 
229  int slotOffsetInWholeArrayMapOf(ArrRegMap* aregmap, RegMapBlock* block,
230  sza::util::Coord* coord=0);
231 
232  // Convenience method
233 
234  int slotOffsetOf(bool archivedOnly, ArrRegMap* aregmap, RegMapBlock* block,
235  sza::util::Coord* coord=0) {
236  return archivedOnly ? slotOffsetInArcArrayMapOf(aregmap, block, coord) :
237  slotOffsetInWholeArrayMapOf(aregmap, block, coord);
238  }
239 
240  // Return the slot offset in the ArrayMap of the named block
241 
242  int slotOffsetInArcArrayMapOf(std::string regmap, std::string board,
243  std::string block,
244  sza::util::Coord* coord=0);
245  int slotOffsetInWholeArrayMapOf(std::string regmap, std::string board,
246  std::string block,
247  sza::util::Coord* coord=0);
248 
249  // Convenience method
250 
251  int slotOffsetOf(bool archivedOnly,
252  std::string regmap, std::string board, std::string block,
253  sza::util::Coord* coord=0)
254  {
255  return archivedOnly ?
256  slotOffsetInArcArrayMapOf(regmap, board, block, coord) :
257  slotOffsetInWholeArrayMapOf(regmap, board, block, coord);
258  }
259 
260  // Return the number of bytes in this array map
261 
262  int nByte(bool archivedOnly) {
263  return archivedOnly ? nArcByte_ : nByte_;
264  }
265 
266  // Return the number of registers in this array map
267 
268  int nReg(bool archivedOnly) {
269  return archivedOnly ? narchive : nreg;
270  }
271 
272  // Find the named block
273 
274  RegMapBlock* findArrayMapBlock(std::string regmap_name, std::string board_name,
275  std::string block_name,
276  bool doThrow=false);
277  // Find the named register map
278 
279  RegMap* findRegMap(std::string regmap_name);
280 
281  // Return the arregmap associated wtih a register map
282 
283  ArrRegMap* findArrRegMap(RegMap* regmapPtr);
284  ArrRegMap* findArrRegMap(std::string regmapName);
285 
286  // Return a vector of regmaps which match the input string
287 
288  std::vector<ArrRegMap*> matchArrRegMap(std::string regExpString);
289  std::vector<ArrRegMap*> matchArrRegMap(std::vector<std::string>& regmaps);
290 };
291 
292 /* Allocate a readonly alias to a given register map. */
293 /* When no longer required this should be discarded by calling */
294 /* del_RegMap(). */
295 
296 ArrayMap *alias_ArrayMap(ArrayMap *arrayMap);
297 
298 /* Delete a register map or one of its aliases. */
299 
300 ArrayMap *del_ArrayMap(ArrayMap *arrayMap);
301 
302 /* Return non-zero if two register maps are equivalent. */
303 
304 int equiv_ArrayMap(ArrayMap *arrayMap1, ArrayMap *arrayMap2);
305 
306 ArrRegMap* find_ArrRegMap(ArrayMap *arrayMap, std::string regMapName);
307 
308 RegMapBlock* find_ArrayMapBlock(ArrayMap *arraymap, std::string regmap_name,
309  std::string board_name, std::string block_name);
310 
311 #endif
A class for specifying a coordinate in a multi-dimensional space.
Definition: Coord.h:21