CFEL - ASG Software Suite  2.5.0
CASS
acqiristdc_device.hpp
Go to the documentation of this file.
1 //Copyright (C) 2011, 2015 Lutz Foucar
2 
3 /**
4  * @file acqiristdc_device.hpp file contains the declaration of the acqiristdc
5  * part of the CASSEvent
6  *
7  * @author Lutz Foucar
8  */
9 
10 #ifndef _ACQIRISTDC_DEVICE_HPP_
11 #define _ACQIRISTDC_DEVICE_HPP_
12 
13 #include <vector>
14 #include <map>
15 
16 #include "device_backend.hpp"
17 #include "serializable.hpp"
18 
19 namespace cass
20 {
21 namespace ACQIRISTDC
22 {
23 /** A Channel of an Acqiris TDC Instrument.
24  *
25  * contains all information that an Acqiris TDC instrument will provide about
26  * a channel and the recorded hits of that channel
27  *
28  * @author Lutz Foucar
29  */
30 class Channel : public Serializable
31 {
32 public:
33  /** define the hits */
34  typedef std::vector<double> hits_t;
35 
36  /** constructor that will set the serialize version*/
38  : Serializable(1)
39  {}
40 
41  /** construct this from the stream
42  *
43  * @param in the input stream to read this class from
44  */
46  : Serializable(1)
47  {
48  deserialize(in);
49  }
50 
51 public:
52  /** will serialize this channel to the serializer
53  *
54  * @param out the stream to serialze this class to
55  */
56  void serialize(SerializerBackend &out)const
57  {
58  writeVersion(out);
59  /** write the number of hits */
60  const size_t nHits = _hits.size();
61  out.add(nHits);
62  /** write the hits */
63  for (hits_t::const_iterator it(_hits.begin()); it!=_hits.end(); ++it)
64  out.add(*it);
65  }
66 
67  /** deserialize this channel from the stream
68  *
69  * @return true when this class was deserialized from the stream sucessfully
70  * @param in the stream to serialize this class from
71  */
73  {
74  checkVersion(in);
75  /** read the number of hits */
76  size_t nHits(in.retrieve<size_t>());
77  /** clear the hit container and read the hits */
78  _hits.clear();
79  for (size_t i(0); i < nHits; ++i)
80  _hits.push_back(in.retrieve<double>());
81  return true;
82  }
83 
84  /** retireve hits */
85  const hits_t &hits()const {return _hits;}
86 
87  /** retrieve hits*/
88  hits_t &hits() {return _hits;}
89 
90 private:
91  /** the hits of the channel */
92  hits_t _hits;
93 };
94 
95 
96 
97 /** An Acqiris TDC Instrument.
98  *
99  * An Acqiris Instrument represents the actual Acqiris (Multi)-Instrument,
100  * which contains a lot of channels
101  *
102  * @author Lutz Foucar
103  */
104 class Instrument : public Serializable
105 {
106 public:
107  /** constructor */
109  : Serializable(1)
110  {}
111 
112  /** constuct class from stream
113  *
114  * @param in the stream to construct this class from
115  */
117  : Serializable(1)
118  {
119  deserialize(in);
120  }
121 
122 public:
123  /** a vector of Channels */
124  typedef std::vector<Channel> channels_t;
125 
126  /** there is a fixed size of channels in this instrument */
127  enum {NbrChannels=6};
128 
129 public:
130  /** will serialize all channels to Serializer
131  *
132  * @param out the stream to serialze this class to
133  */
134  void serialize(SerializerBackend &out)const
135  {
136  writeVersion(out);
137  /** serialize the size of the channels and then all channels */
138  size_t nChannels = _channels.size();
139  out.add(nChannels);
140  channels_t::const_iterator it(_channels.begin());
141  for(; it != _channels.end(); ++it)
142  it->serialize(out);
143  }
144 
145  /** will deserialize all channels from the Serializer
146  *
147  * @return true when this class was deserialized from the stream sucessfully
148  * @param in the stream to serialize this class from
149  */
151  {
152  checkVersion(in);
153  /** read how many channels */
154  size_t nChannels(in.retrieve<size_t>());
155  /** clear the channel container and read the channels from the stream */
156  _channels.clear();
157  for(size_t i(0); i < nChannels ; ++i)
158  _channels.push_back(Channel(in));
159  return true;
160  }
161 
162 public:
163  /** @returns the channels of this instrument*/
164  const channels_t &channels()const {return _channels;}
165 
166  /** @returns a reference, so that one can edit the channels*/
167  channels_t &channels() {return _channels;}
168 
169 private:
170  /** Container for all Channels */
171  channels_t _channels;
172 };
173 
174 
175 
176 
177 /** The Acqiris TDC device
178  *
179  * The Acqiris TDC device contains all availabe Acqiris TDC instruments
180  *
181  * @author Lutz Foucar
182  */
183 class Device : public DeviceBackend
184 {
185 public:
186  /** constructor */
188  : DeviceBackend(1)
189  {}
190 
191 public:
192  /** define the instruments container */
193  typedef std::map<uint32_t, Instrument> instruments_t;
194 
195 public:
196  /** instrument setter */
197  instruments_t &instruments() {return _instruments;}
198 
199  /** instrument getter */
200  const instruments_t &instruments()const {return _instruments;}
201 
202 public:
203  /** will serialize all channels to Serializer
204  *
205  * @param out the stream to serialze this class to
206  */
207  void serialize(SerializerBackend &out)const
208  {
209  writeVersion(out);
210  /** write the size of the instruments container */
211  out.add(static_cast<size_t>(_instruments.size()));
212  /** now write each instrument but first the key of the instrument */
213  instruments_t::const_iterator it(_instruments.begin());
214  for(; it != _instruments.end(); ++it)
215  {
216  out.add(it->first);
217  it->second.serialize(out);
218  }
219  }
220 
221  /** will deserialize all channels from the Serializer
222  *
223  * @return true when this class was deserialized from the stream sucessfully
224  * @param in the stream to serialize this class from
225  */
227  {
228  checkVersion(in);
229  /** read the number of instruments */
230  size_t nInstr(in.retrieve<size_t>());
231  /** read the key of the instrument and add the deserialized instrument */
232  for(size_t i(0); i < nInstr; ++i)
233  {
234  const instruments_t::key_type key(in.retrieve<instruments_t::key_type>());
235  _instruments[key] = Instrument(in);
236  }
237  return true;
238  }
239 
240 private:
241  /** Container for all Instruments */
242  instruments_t _instruments;
243 };
244 }//end namespace acqiris
245 }//end namespace cass
246 
247 
248 #endif
bool deserialize(SerializerBackend &in)
will deserialize all channels from the Serializer
const instruments_t & instruments() const
instrument getter
instruments_t & instruments()
instrument setter
const hits_t & hits() const
retireve hits
void serialize(SerializerBackend &out) const
will serialize all channels to Serializer
virtual void writeVersion(SerializerBackend &out) const
write the version to the stream
bool deserialize(SerializerBackend &in)
deserialize this channel from the stream
const channels_t & channels() const
std::map< uint32_t, Instrument > instruments_t
define the instruments container
void serialize(SerializerBackend &out) const
will serialize this channel to the serializer
contains base class for all devices that are part of the cassevent.
The Acqiris TDC device.
std::vector< Channel > channels_t
a vector of Channels
file contains base class all serializable classes
instruments_t _instruments
Container for all Instruments.
Instrument(SerializerBackend &in)
constuct class from stream
bool deserialize(SerializerBackend &in)
will deserialize all channels from the Serializer
A Channel of an Acqiris TDC Instrument.
virtual void checkVersion(SerializerBackend &in) const
check the version
hits_t & hits()
retrieve hits
Channel()
constructor that will set the serialize version
hits_t _hits
the hits of the channel
channels_t _channels
Container for all Channels.
Type retrieve()
read arbitrary value from stream
Definition: serializer.hpp:169
A Baseclass for all Devices in the CASSEvent.
std::vector< double > hits_t
define the hits
void serialize(SerializerBackend &out) const
will serialize all channels to Serializer
An Acqiris TDC Instrument.
Serializable.
void add(const Type &value)
add arbitrary value to the stream
Definition: serializer.hpp:158
Channel(SerializerBackend &in)
construct this from the stream