NanoSliceVersionConvention.h
Go to the documentation of this file.
1 /*
2  * File: NanoSliceVersionConvention.h
3  * Author: denis
4  *
5  * This class holds conventions for the nanoslice version.
6  * For a version of a Nanoslice, it tells the FEB Firmware registers values
7  *
8  * Created on October 22, 2013, 8:52 AM
9  */
10 
11 #ifndef NANOSLICEVERSIONCONVENTION_H
12 #define NANOSLICEVERSIONCONVENTION_H
13 
14 #include "DAQDataFormats/RawDAQData.h" // Macros for function pointer bindings
15 #include "DAQDataFormats/DataFormatException.h" // Macros for function pointer bindings
16 
17 #include <iostream>
18 #include <vector>
19 #include <stdint.h> // uint32_t, etc
20 #ifndef DARWINBUILD
21  #include <boost/lexical_cast.hpp>
22 #endif
23 
24 namespace daqdataformats {
25 
26  /// All encoding types
27  enum Encode_Type {
30  ,ENCODE_UNKNOWN = 0xFFFFF
31  };// end of NanoSliceHeaderMASKS
32 
33 
34 
35  /// Class describing the values of the FEB registers for the NanoSlice version
37  public:
40  ,_nSamples (0)
42  {
43  }
45  ,const uint32_t nsamples
46  ,const uint32_t npretriggered_samples
47  ):
48  _encode (encode)
49  ,_nSamples (nsamples)
50  ,_nPretriggeredSamples(npretriggered_samples)
51  {
52  }
54  _encode (copy._encode)
55  ,_nSamples (copy._nSamples)
57 
58  {
59  }
60 
62 
64  {
65  _encode = encode;
66  return true;
67  }
68  bool setNSamples(const uint32_t nsamples)
69  {
70  _nSamples = nsamples;
71  return true;
72  }
73  bool setNPretriggeredSamples(const uint32_t nsamples)
74  {
75  _nPretriggeredSamples = nsamples;
76  return true;
77  }
78 
79  Encode_Type getEncode() const {return _encode;}
80  uint32_t getNSamples() const {return _nSamples;}
82 
83  std::ostream& print(std::ostream& os=std::cout) const
84  {
85  os<<"Encode="<<_encode
86  <<", NSamples="<<_nSamples
87  <<", NPretriggeredSamples="<<_nPretriggeredSamples<<"\n";
88 
89  return os;
90  }
91 
92 
93  private:
94  Encode_Type _encode; ///< Encoding for a sample. Compression type.
95  uint32_t _nSamples; ///< Total number of samples to record
96  uint32_t _nPretriggeredSamples; ///< Number of pretriggered samples to record. Must be less than NSamples
97  };// end of
98 
99 
100 
101 
103 
104  public:
107 
108  std::ostream& print(std::ostream& os=std::cout) const
109  {
110 
111  const int nversions = _versionRegisters.size();
112  os<<"Total Number of versions="<<nversions<<"\n";
113 
114 
115  for(int i=0; i<nversions; ++i){
116  os<<"Version "<<i<<":";
117  try{
118  if(checkVersion(i, false)){
119  _versionRegisters[i].print(os);
120  }
121  else{os<<"NOT ALLOWED\n";}
122  }
123  catch(...){
124  os<<"NOT ALLOWED\n";
125  }
126 
127  }
128 
129  return os;
130  }
131 
132  /// Get the encoding type
134  {
135  if(!checkVersion(ver)) return ENCODE_UNKNOWN;
136  return _versionRegisters[(int)ver].getEncode();
137  }
138  /// Get the number of samples
139  uint32_t getNSamples(const version_t ver) const
140  {
141  if(!checkVersion(ver)) return 0;
142  return _versionRegisters[(int)ver].getNSamples();
143  }
144  /// Get number of pretriggered samples
145  uint32_t getNPretriggeredSamples(const version_t ver) const
146  {
147  if(!checkVersion(ver)) return 0;
148  return _versionRegisters[(int)ver].getNPretriggeredSamples();
149  }
150 
151 
152  private:
153  bool setup()
154  {
155  _versionRegisters.push_back(FEBVersioningRegisters(DCSENCODE_12_in_16, 1, 0));
156  _versionRegisters.push_back(FEBVersioningRegisters(DCSENCODE_12_in_16, 0, 0));
157  _versionRegisters.push_back(FEBVersioningRegisters(RAWENCODE_12_in_16, 8, 3));
158  _versionRegisters.push_back(FEBVersioningRegisters(RAWENCODE_12_in_16, 4, 3));
159  _versionRegisters.push_back(FEBVersioningRegisters(RAWENCODE_12_in_16, 14, 0));
160  _versionRegisters.push_back(FEBVersioningRegisters(RAWENCODE_12_in_16, 20, 0));
161  return true;
162  }
163 
164  /// Check the version of nanoslice
165  /// If it's wrong, throw an exception
166  bool checkVersion(const version_t ver, const bool throw_exception=true) const
167  {
168 
169  /// See if it's an allowed version
171  || ver == 1
172  || ver >= (int)_versionRegisters.size()
173  || ver < 0
174  ){
175 
176  if(throw_exception){
177 #ifndef DARWINBUILD
178  // GENERATE_DATAFORMAT_EXCEPTION("NanoSlice Version " + boost::lexical_cast<std::string>(ver) + " is not allowed");
179 #else
180  GENERATE_DATAFORMAT_EXCEPTION("NanoSlice Version is not allowed");
181 #endif
182  }
183  return false;
184  }// end of checking the version
185 
186  return true;
187  }
188  private:
189 
190  std::vector <FEBVersioningRegisters> _versionRegisters;
191 
192  };// end of class NOvACheckSum
193 
194 }// end of daqdataformats namespace
195 
196 #endif /* NANOSLICEVERSIONCONVENTION_H */
uint32_t _nSamples
Total number of samples to record.
Encode_Type
All encoding types.
std::vector< FEBVersioningRegisters > _versionRegisters
#define GENERATE_DATAFORMAT_EXCEPTION(msg)
ps_atom_t encode(std::string const &)
FEBVersioningRegisters(const FEBVersioningRegisters &copy)
static void setup()
Definition: main.cxx:808
std::ostream & print(std::ostream &os=std::cout) const
Class describing the values of the FEB registers for the NanoSlice version.
uint32_t _nPretriggeredSamples
Number of pretriggered samples to record. Must be less than NSamples.
bool checkVersion(const version_t ver, const bool throw_exception=true) const
uint32_t getNSamples(const version_t ver) const
Get the number of samples.
uint32_t getNPretriggeredSamples(const version_t ver) const
Get number of pretriggered samples.
FEBVersioningRegisters(const Encode_Type encode, const uint32_t nsamples, const uint32_t npretriggered_samples)
OStream cout
Definition: OStream.cxx:6
Encode_Type getEncodeType(const version_t ver) const
Get the encoding type.
int32_t version_t
Definition: RawDAQData.h:72
bool setNPretriggeredSamples(const uint32_t nsamples)
std::ostream & print(std::ostream &os=std::cout) const
static const version_t DAQDATAFORMAT_UNKNOWN_VERSION
Definition: RawDAQData.h:81
Class to hold the data from the FEBs in correct formats.
Encode_Type _encode
Encoding for a sample. Compression type.