CFEL - ASG Software Suite  2.5.0
CASS
agat_deserializer.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file agat_deserializer.cpp contains functions to deserialize the data stream
5  * sent by agat.
6  *
7  * @author Lutz Foucar
8  */
9 
10 #include <algorithm>
11 
12 #include <QtCore/QDataStream>
13 
14 #include "agat_deserializer.h"
15 
16 #include "cass.h"
17 #include "cass_event.h"
18 #include "acqiris_device.hpp"
19 #include "agattypes.hpp"
20 
21 using namespace cass;
22 using namespace ACQIRIS;
23 using namespace std;
24 using Streaming::operator >>;
25 
26 
28 {
29  size_t nBytesRead(0);
30  /** extract the right instrument from the cassevent */
31  if (evt.devices().find(CASSEvent::Acqiris) == evt.devices().end())
32  throw runtime_error("deserializeNormalAgat(): The Acqiris Device does not exist.");
33  Device &dev(dynamic_cast<Device&>(*(evt.devices()[CASSEvent::Acqiris])));
34  Instrument &instr(dev.instruments()[0]);
35 
36  /** read the event header and copy the id */
38  stream >> evtHead;
39  nBytesRead += sizeof(AGATRemoteHeader::Event);
40  evt.id() = evtHead.id;
41  instr.id() = evt.id();
42  /** resize the channel container to fit the right number of channels */
43  instr.channels().resize(evtHead.nbrChannels);
44  /** for each channel */
45  for (size_t iChan(0); iChan < evtHead.nbrChannels; ++iChan)
46  {
47  /** check whether it is contained in the stream */
48  if (evtHead.usedChannelBitmask & (0x1 << iChan))
49  {
50  /** if the channel is contained in the stream */
51  /** read the channel header */
53  stream >> chanHead;
54  nBytesRead += sizeof(AGATRemoteHeader::Channel);
55  /** copy channel parameters from the header to the cassevent */
56  Channel &chan(instr.channels()[iChan]);
57  chan.channelNbr() = iChan;
58  chan.offset() = chanHead.offset_mV*1e-3;
59  chan.gain() = chanHead.gain_mVperLSB*1e-3;
60  chan.sampleInterval() = evtHead.samplingInterval;
61  /** resize the wavefrom so that all the pulses will fit into it */
62  Channel::waveform_t& waveform(chan.waveform());
63  waveform.resize(evtHead.nbrSamples);
64  /** set all value to the basevalue */
65  fill(waveform.begin(),waveform.end(),chanHead.offset_mV/chanHead.gain_mVperLSB);
66  /** for all pulses within that channel */
67  for (size_t iPuls(0); iPuls < chanHead.nbrPulses; ++iPuls)
68  {
69  /** read the puls header and determine the length of the puls form it*/
70  lmaHeader::Puls pulsHead;
71  stream >> pulsHead;
72  nBytesRead += sizeof(lmaHeader::Puls);
73  size_t datasize = pulsHead.length * evtHead.nbrBits/8;
74  /** read the puls data into the wavefrom at the right position */
75  stream.readRawData(reinterpret_cast<char*>(&waveform[pulsHead.idxPos]),
76  datasize);
77  nBytesRead += datasize;
78  }
79  }
80  }
81  return true;
82 }
83 
std::vector< int16_t > waveform_t
define the waveform
Definition: channel.hpp:35
Event to store all LCLS Data.
Definition: cass_event.h:32
contains the layout of the lma file headers.
An Acqiris Instrument.
file contains declaration of the CASSEvent
STL namespace.
readRawData(char *s, int len)
The Acqiris device.
size_t operator()(QDataStream &stream, CASSEvent &evt)
deserialize stream
devices_t & devices()
setters
Definition: cass_event.h:66
the header of an recorded channel
Definition: agattypes.hpp:188
file contains the declaration of the acqiris part of the CASSEvent
file contains global definitions for project cass
contains functions to deserialize the data stream sent by agat.
id_t & id()
setters
Definition: cass_event.h:64
the general stream header
Definition: agattypes.hpp:142
uint32_t length
how many points of the wavefrom are in the puls
Definition: agattypes.hpp:132
the header of a puls
Definition: agattypes.hpp:126
A Channel of an Acqiris Instrument.
Definition: channel.hpp:31
size_t & channelNbr()
setter
Definition: channel.hpp:106