NSCL DDAS  1.0
Support for XIA DDAS at the NSCL
 All Classes Namespaces Files Functions Variables Macros Pages
SetFile.h
Go to the documentation of this file.
1 /*
2  This software is Copyright by the Board of Trustees of Michigan
3  State University (c) Copyright 2017.
4 
5  You may use this software under the terms of the GNU public license
6  (GPL). The terms of this license are described at:
7 
8  http://www.gnu.org/licenses/gpl.txt
9 
10  Authors:
11  Ron Fox
12  Giordano Cerriza
13  NSCL
14  Michigan State University
15  East Lansing, MI 48824-1321
16 */
17 
21 #ifndef SETFILE_H
22 #define SETFILE_H
23 #include <string>
24 #include <map>
25 #include <vector>
26 
27 #include <stdint.h>
28 
29 
30 namespace DDAS {
31  // The VAR file actually is a DSP memory layout file for the chunk of
32  // DSP memory that holds the DSP parameters. This memory
33  // starts at DSP_BASE below. File offsets are computed from VAR file numbers
34  // as (varfileNumber - DSP_BASE ) * sizeof(uint32_t)
35  //
36  static const unsigned DSP_BASE=0x4a000;
46  struct VarDescriptor {
47  std::string s_name;
48  unsigned s_longoff;
49  unsigned s_nLongs;
50 
51  VarDescriptor() {}
52  ~VarDescriptor() {}
53  VarDescriptor(const VarDescriptor& rhs) {
54  copyin(rhs);
55  }
56  VarDescriptor& operator=(const VarDescriptor& rhs) {
57  if (this != &rhs) {
58  copyin(rhs);
59  }
60  return *this;
61  }
62  void copyin(const VarDescriptor& rhs) {
63  s_name = rhs.s_name;
64  s_longoff = rhs.s_longoff;
65  s_nLongs = rhs.s_nLongs;
66  }
67  };
68 
75  typedef std::vector<VarDescriptor> VarOffsetArray;
76 
81  typedef std::map<uint32_t, VarDescriptor> VarMapByOffset;
82 
87  typedef std::map<std::string, VarDescriptor> VarMapByName;
88 
94  typedef struct _Variable {
95  VarDescriptor s_desc;
96  uint32_t s_value; // Module level e.g.
97  std::vector<uint32_t> s_values; // Channel level e.g.
98  _Variable() {}
99  ~_Variable() {}
100  _Variable(const _Variable& rhs) {
101  copyin(rhs);
102  }
103  _Variable& operator=(const _Variable& rhs) {
104  if (this != &rhs) {
105  copyin(rhs);
106  }
107  return *this;
108  }
109  void copyin(const _Variable& rhs) {
110  s_desc = rhs.s_desc;
111  s_value = rhs.s_value;
112  s_values = rhs.s_values;
113  }
114  } Variable;
115 
120  typedef std::vector<Variable> UnpackedSetFile;
121 
126  typedef std::map<std::string, Variable> SetFileByName;
127 
132  class SetFile {
133  public:
134  // Var definition files:
135 
136  static VarOffsetArray readVarFile(const char* filename);
137  static VarMapByOffset createVarOffsetMap(const VarOffsetArray& offsets);
138  static VarMapByName createVarNameMap(const VarOffsetArray& offsets);
139 
140  // set files I/O and resource management:
141 
142  static std::pair<unsigned, uint32_t*> readSetFile(const char* filename);
143  static void writeSetFile(
144  const char* filename, unsigned nLongs, uint32_t* pVars
145  );
146  static void freeSetFile(uint32_t* pVars);
147 
148 
149  static UnpackedSetFile populateSetFileArray(
150  unsigned nLongs, const uint32_t* pVars,
151  const VarOffsetArray& map
152  );
153  static SetFileByName populateSetFileMap(
154  unsigned nLong, const uint32_t* pVars,
155  const VarOffsetArray& map
156  );
157  static SetFileByName populateSetFileMap(
158  const UnpackedSetFile& vars
159  );
160  private:
161  static Variable getVariable(
162  unsigned nLong, const uint32_t* pVars, const VarDescriptor& d
163  );
164  };
165 
166 } // DDAS Namespace.
167 
168 #endif
Definition: SetFile.h:94
Definition: SetFile.h:46
static UnpackedSetFile populateSetFileArray(unsigned nLongs, const uint32_t *pVars, const VarOffsetArray &map)
Definition: SetFile.cpp:246
static std::pair< unsigned, uint32_t * > readSetFile(const char *filename)
Definition: SetFile.cpp:143
Definition: SetFile.h:132
static void freeSetFile(uint32_t *pVars)
Definition: SetFile.cpp:191
static SetFileByName populateSetFileMap(unsigned nLong, const uint32_t *pVars, const VarOffsetArray &map)
Definition: SetFile.cpp:276
static VarMapByOffset createVarOffsetMap(const VarOffsetArray &offsets)
Definition: SetFile.cpp:104
static void writeSetFile(const char *filename, unsigned nLongs, uint32_t *pVars)
Definition: SetFile.cpp:204
static VarMapByName createVarNameMap(const VarOffsetArray &offsets)
Definition: SetFile.cpp:122
static VarOffsetArray readVarFile(const char *filename)
Definition: SetFile.cpp:47
Definition: functions.h:26