CFEL - ASG Software Suite  2.5.0
CASS
acqiris_device.hpp
Go to the documentation of this file.
1 //Copyright (C) 2009, 2010, 2015 Lutz Foucar
2 
3 /**
4  * @file acqiris_device.hpp file contains the declaration of the acqiris part
5  * of the CASSEvent
6  *
7  * @author Lutz Foucar
8  */
9 
10 #ifndef _ACQIRIS_DEVICE_HPP_
11 #define _ACQIRIS_DEVICE_HPP_
12 
13 #include <vector>
14 #include <map>
15 
16 #include "device_backend.hpp"
17 #include "channel.hpp"
18 #include "serializable.hpp"
19 
20 namespace cass
21 {
22 namespace ACQIRIS
23 {
24 /** An Acqiris Instrument.
25  *
26  * An Acqiris Instrument represents the actual Acqiris (Multi)-Instrument,
27  * which contains a lot of channels
28  *
29  * @author Lutz Foucar
30  */
31 class Instrument : public Serializable
32 {
33 public:
34  /** constructor */
36  : Serializable(1)
37  {}
38 
39  /** constuct class from stream
40  *
41  * @param in the stream to construct this class from
42  */
44  : Serializable(1)
45  {
46  deserialize(in);
47  }
48 
49 public:
50  /** a vector of Channels */
51  typedef std::vector<Channel> channels_t;
52 
53 public:
54  /** will serialize all channels to Serializer
55  *
56  * @param out the stream to serialze this class to
57  */
58  virtual void serialize(SerializerBackend &out)const
59  {
60  writeVersion(out);
61  /** copy the size of the channels and then all channels */
62  out.add(static_cast<size_t>(_channels.size()));
63  for(channels_t::const_iterator it=_channels.begin(); it != _channels.end(); ++it)
64  it->serialize(out);
65  }
66 
67  /** will deserialize all channels from the Serializer
68  *
69  * @return true when this class was deserialized from the stream sucessfully
70  * @param in the stream to serialize this class from
71  */
72  virtual bool deserialize(SerializerBackend &in)
73  {
74  checkVersion(in);
75  /** read how many channels */
76  size_t nChannels(in.retrieve<size_t>());
77  /** clear the channels container and deserialize the channels from the stream */
78  _channels.clear();
79  for(size_t i(0); i < nChannels; ++i)
80  _channels.push_back(Channel(in));
81  return true;
82  }
83 
84 public:
85  /** @returns the channels of this instrument*/
86  const channels_t &channels()const {return _channels;}
87 
88  /** @returns a reference, so that one can edit the channels*/
89  channels_t &channels() {return _channels;}
90 
91  /** @returns the event id */
92  uint64_t id()const {return _eventID;}
93 
94  /** @returns reference to the eventid */
95  uint64_t &id() {return _eventID;}
96 
97 private:
98  /** Container for all Channels */
99  channels_t _channels;
100 
101  /** the eventid that this detector belongs to (can be used for crosschecks */
102  uint64_t _eventID;
103 };
104 
105 
106 
107 
108 /** The Acqiris device
109  *
110  * The Acqiris device contains all availabe Acqiris instruments
111  * All availabe instruments will be added when they are detected
112  *
113  * @author Lutz Foucar
114  */
115 class Device : public DeviceBackend
116 {
117 public:
118  /** constructor */
120  : DeviceBackend(1)
121  {}
122 
123 public:
124  /** a map of all instruments available*/
125  typedef std::map<uint32_t, Instrument> instruments_t;
126 
127 public:
128  /** instrument setter*/
129  instruments_t &instruments() {return _instruments;}
130 
131  /** instrument getter*/
132  const instruments_t &instruments()const {return _instruments;}
133 
134 public:
135  /** will serialize all channels to Serializer
136  *
137  * @param out the stream to serialze this class to
138  */
139  virtual void serialize(SerializerBackend &out)const
140  {
141  writeVersion(out);
142  /** write the size of the container */
143  out.add(static_cast<size_t>(_instruments.size()));
144  /** for each instrument in the map write the key and then the Instrument */
145  for (instruments_t::const_iterator it = _instruments.begin (); it != _instruments.end (); ++it)
146  {
147  out.add(it->first);
148  it->second.serialize(out);
149  }
150  }
151 
152  /** will deserialize all channels from the Serializer
153  *
154  * @return true when this class was deserialized from the stream sucessfully
155  * @param in the stream to serialize this class from
156  */
157  virtual bool deserialize(SerializerBackend &in)
158  {
159  checkVersion(in);
160  /** read the number of instruments */
161  size_t nInstr(in.retrieve<size_t>());
162  /** read the key of the instrument and add the deserialized instrument */
163  for(size_t i(0); i < nInstr; ++i)
164  {
165  const instruments_t::key_type key(in.retrieve<instruments_t::key_type>());
166  _instruments[key] = Instrument(in);
167  }
168  return true;
169  }
170 
171 private:
172  /** Container for all Instruments*/
173  instruments_t _instruments;
174 };
175 }//end namespace acqiris
176 }//end namespace cass
177 
178 
179 #endif
instruments_t _instruments
Container for all Instruments.
virtual bool deserialize(SerializerBackend &in)
will deserialize all channels from the Serializer
An Acqiris Instrument.
virtual bool deserialize(SerializerBackend &in)
will deserialize all channels from the Serializer
virtual void serialize(SerializerBackend &out) const
will serialize all channels to Serializer
virtual void writeVersion(SerializerBackend &out) const
write the version to the stream
uint64_t _eventID
the eventid that this detector belongs to (can be used for crosschecks
std::map< uint32_t, Instrument > instruments_t
a map of all instruments available
file contains the classes that describe an acqiris channel
channels_t _channels
Container for all Channels.
Instrument(SerializerBackend &in)
constuct class from stream
The Acqiris device.
contains base class for all devices that are part of the cassevent.
const channels_t & channels() const
file contains base class all serializable classes
virtual void checkVersion(SerializerBackend &in) const
check the version
virtual void serialize(SerializerBackend &out) const
will serialize all channels to Serializer
A Channel of an Acqiris Instrument.
Definition: channel.hpp:31
const instruments_t & instruments() const
instrument getter
std::vector< Channel > channels_t
a vector of Channels
Type retrieve()
read arbitrary value from stream
Definition: serializer.hpp:169
A Baseclass for all Devices in the CASSEvent.
Serializable.
void add(const Type &value)
add arbitrary value to the stream
Definition: serializer.hpp:158
instruments_t & instruments()
instrument setter