CFEL - ASG Software Suite  2.5.0
CASS
machine_device.hpp
Go to the documentation of this file.
1 //Copyright (C) 2009, 2010, 2014, 2015 Lutz Foucar
2 
3 /**
4  * @file machine_device.hpp definitions of a machine device
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _MACHINEDATADEVICE_HPP_
10 #define _MACHINEDATADEVICE_HPP_
11 
12 #include <map>
13 #include <vector>
14 #include <string>
15 #include <iostream>
16 
17 #include "device_backend.hpp"
18 #include "serializable.hpp"
19 
20 namespace cass
21 {
22 namespace MachineData
23 {
24 /** Container for all Machine related Data
25  *
26  * This device contains all data that is machine related
27  * - Beamline Data
28  * - Epics Data
29  * - Evr Data
30  *
31  * @author Lutz Foucar
32  */
33 class Device : public DeviceBackend
34 {
35 public:
36  /** constructor initializing values to meaningful data*/
38  : DeviceBackend(1),
39  _epicsFilled(false)
40  {}
41 
42 public:
43  /** define the epics container
44  * @note instead of double as second one could make it a QVariant to be able to
45  * also store strings.
46  */
47  typedef std::map<std::string,double> epicsDataMap_t;
48 
49  /** define the beamline data container */
50  typedef std::map<std::string,double> bldMap_t;
51 
52  /** define the evr status container */
53  typedef std::vector<bool> evrStatus_t;
54 
55  /** define the spectrometer data */
56  typedef std::map<std::string,std::vector<uint32_t> > spectrometer_t;
57 
58 public:
59  /** serialize the device to the serializer
60  *
61  * @param out the stream to serialze this class to
62  */
63  void serialize(SerializerBackend &out)const
64  {
65  /** write the version */
66  writeVersion(out);
67  /** write the size of the beamlinedata */
68  out.add(static_cast<size_t>(_blddata.size()));
69  /** for each beamline entry in the map write the name and then the value */
70  for (bldMap_t::const_iterator it = _blddata.begin (); it != _blddata.end (); ++it)
71  {
72  out.add(it->first);
73  out.add(it->second);
74  }
75  /** write the epics data size */
76  out.add(static_cast<size_t>(_epicsdata.size()));
77  /** for each epics entry in the map write the name and then the value */
78  for (epicsDataMap_t::const_iterator it = _epicsdata.begin (); it != _epicsdata.end (); ++it)
79  {
80  out.add(it->first);
81  out.add(it->second);
82  }
83  }
84 
85  /** deserialize the device from the stream
86  *
87  * @return true when this class was deserialized from the stream sucessfully
88  * @param in the stream to serialize this class from
89  */
91  {
92  /** check whether the version is correct */
93  checkVersion(in);
94  /** read the beamlinedata, first clear the existing map */
95  _blddata.clear();
96  /** then read the size of the map */
97  size_t len(in.retrieve<size_t>());
98  /** now retrieve every entry of the map and add it to the map */
99  for (size_t i=0; i<len; ++i)
100  {
101  const bldMap_t::key_type key(in.retrieve<bldMap_t::key_type>());
102  _blddata[key] = in.retrieve<bldMap_t::mapped_type>();
103  }
104  /** read the epics data, first clear the existing map */
105  _epicsdata.clear();
106  /** read the size of the map */
107  len = in.retrieve<size_t>();
108  /** now retrieve every entry of the map and add it to the map */
109  for (size_t i=0; i<len; ++i)
110  {
111  const epicsDataMap_t::key_type key(in.retrieve<epicsDataMap_t::key_type>());
112  _epicsdata[key] = in.retrieve<epicsDataMap_t::mapped_type>();
113  }
114  return true;
115  }
116 
117 public:
118  //@{
119  /** getter */
120  const epicsDataMap_t &EpicsData()const {return _epicsdata;}
121  const bldMap_t &BeamlineData()const {return _blddata;}
122  const evrStatus_t &EvrData()const {return _evrdata;}
123  const spectrometer_t &spectrometers()const {return _spectrometers;}
124  bool epicsFilled()const {return _epicsFilled;}
125 
126  //@}
127  //@{
128  /** setter */
129  bldMap_t &BeamlineData() {return _blddata;}
130  epicsDataMap_t &EpicsData() {return _epicsdata;}
131  evrStatus_t &EvrData() {return _evrdata;}
132  spectrometer_t &spectrometers() {return _spectrometers;}
133  bool &epicsFilled() {return _epicsFilled;}
134  //@}
135 
136 private:
137  //beamline data//
138  bldMap_t _blddata; //!< map containing the beamlinedata
139  epicsDataMap_t _epicsdata;//!< a map containing all epics data in the xtc stream
140  evrStatus_t _evrdata; //!< a vector of bools describing the evr status
141 
142  /** container for beamline spectrometer data */
143  spectrometer_t _spectrometers;
144 
145  /** status flag to tell whether the epics variables have been filled during conversion */
147 };
148 
149 }//end namespace machinedata
150 }//end namespace cass
151 #endif
spectrometer_t _spectrometers
container for beamline spectrometer data
bldMap_t & BeamlineData()
setter
virtual void writeVersion(SerializerBackend &out) const
write the version to the stream
bool _epicsFilled
status flag to tell whether the epics variables have been filled during conversion ...
const epicsDataMap_t & EpicsData() const
getter
void serialize(SerializerBackend &out) const
serialize the device to the serializer
contains base class for all devices that are part of the cassevent.
Container for all Machine related Data.
bool epicsFilled() const
getter
file contains base class all serializable classes
std::map< std::string, double > epicsDataMap_t
define the epics container
spectrometer_t & spectrometers()
setter
const spectrometer_t & spectrometers() const
getter
evrStatus_t _evrdata
a vector of bools describing the evr status
virtual void checkVersion(SerializerBackend &in) const
check the version
bool deserialize(SerializerBackend &in)
deserialize the device from the stream
std::map< std::string, double > bldMap_t
define the beamline data container
bldMap_t _blddata
map containing the beamlinedata
const evrStatus_t & EvrData() const
getter
epicsDataMap_t & EpicsData()
setter
std::vector< bool > evrStatus_t
define the evr status container
Type retrieve()
read arbitrary value from stream
Definition: serializer.hpp:169
Device()
constructor initializing values to meaningful data
A Baseclass for all Devices in the CASSEvent.
std::map< std::string, std::vector< uint32_t > > spectrometer_t
define the spectrometer data
void add(const Type &value)
add arbitrary value to the stream
Definition: serializer.hpp:158
epicsDataMap_t _epicsdata
a map containing all epics data in the xtc stream
const bldMap_t & BeamlineData() const
getter
evrStatus_t & EvrData()
setter