CFEL - ASG Software Suite  2.5.0
CASS
lma_reader.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file lma_reader.cpp contains the class to read lma files
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <stdint.h>
10 #include <algorithm>
11 #include <vector>
12 
13 #include "lma_reader.h"
14 
15 #include "cass_event.h"
16 #include "cass_settings.h"
17 #include "agattypes.hpp"
18 #include "log.h"
19 
20 using namespace cass;
21 using namespace cass::ACQIRIS;
22 using namespace std;
23 using Streaming::operator >>;
24 
26  : FileReader("lma")
27 {}
28 
30 {
31 }
32 
33 void LmaReader::readHeaderInfo(std::ifstream &file)
34 {
35  lmaHeader::General header;
36  file >> header;
37 
38  if (header.nbrBits != 16)
39  throw runtime_error("LMAParser():run: The lma file seems to contain 8-bit wavefroms '"
40  + toString(header.nbrBits) + "'. Currently this is not supported.");
41 
42  _instrument.channels().resize(header.nbrChannels);
43  _usedChannelBitmask = header.usedChannelBitmask;
44 
45  Log::add(Log::VERBOSEINFO,"LMAReader(): File contains instrument with '" +
46  toString(header.nbrChannels) +"' channels:");
47  for (int16_t i(0) ; i < header.nbrChannels ;++i)
48  {
49  Channel &chan(_instrument.channels()[i]);
50  chan.sampleInterval() = header.samplingInterval;
51  chan.waveform().resize(header.nbrSamples);
52  chan.channelNbr() = i;
53 
54  Log::add(Log::VERBOSEINFO,"LMAReader(): Channel '" + toString(i) + "' is " +
55  ((_usedChannelBitmask & (0x1<<i))?"":"not") + " recorded!");
56 
57  if (_usedChannelBitmask & (0x1<<i))
58  {
59  lmaHeader::Channel chanheader;
60  file >> chanheader;
61  chan.offset() = chanheader.offset_mV*1e-3;
62  chan.gain() = chanheader.gain_mVperLSB*1e-3;
63  Channel::waveform_t & waveform (chan.waveform());
64  fill(waveform.begin(),waveform.end(),chanheader.offset_mV/chanheader.gain_mVperLSB);
65  }
66  }
67 }
68 
69 bool LmaReader::operator ()(ifstream &file, CASSEvent& evt)
70 {
71  /** extract the right instrument from the cassevent */
72  Device &dev(dynamic_cast<Device&>(*(evt.devices()[CASSEvent::Acqiris])));
73  Instrument &instr(dev.instruments()[0]);
74  /** copy the header information to the instrument */
75  instr = _instrument;
76  Instrument::channels_t &channels(instr.channels());
77 
78  /** read the event information data from the file */
79  lmaHeader::Event evtHead;
80  file >> evtHead;
81  evt.id() = evtHead.id;
82  instr.id() = evt.id();
83 
84  for (size_t i=0; i<channels.size();++i)
85  {
86  Channel &chan(instr.channels()[i]);
87  chan.horpos() = evtHead.horpos;
88  Channel::waveform_t &waveform(chan.waveform());
89  if (_usedChannelBitmask & (0x1<<i))
90  {
91  /** since we zero substracted the wavefrom in the lma file, we need to
92  * create the right wavefrom again. This is done by going through the
93  * wavefrom sinpplets called pulses and put them at the right position in
94  * the wavefrom of the channel.
95  */
96  int16_t nbrPulses(Streaming::retrieve<int16_t>(file));
97  for (int16_t i(0); i < nbrPulses; ++i)
98  {
99  /** read the puls properties from file */
100  lmaHeader::Puls pulsHead;
101  file >> pulsHead;
102  size_t dataSize(pulsHead.length * 2);
103  file.read(reinterpret_cast<char*>(&waveform[pulsHead.idxPos]),
104  dataSize);
105  }
106  }
107  }
108 
109  return evt.id();
110 }
std::vector< int16_t > waveform_t
define the waveform
Definition: channel.hpp:35
uint32_t _usedChannelBitmask
bitmask describing which channels are active in the instrument
Definition: lma_reader.h:61
Event to store all LCLS Data.
Definition: cass_event.h:32
void readHeaderInfo(std::ifstream &file)
read the file header
Definition: lma_reader.cpp:33
bool operator()(std::ifstream &file, CASSEvent &event)
read the lma file contents put them into cassevent
Definition: lma_reader.cpp:69
contains the layout of the lma file headers.
An Acqiris Instrument.
file contains declaration of the CASSEvent
contains class to read lma files
STL namespace.
double & sampleInterval()
setter
Definition: channel.hpp:103
the header for each event
Definition: agattypes.hpp:67
base class for all file readers
Definition: file_reader.h:24
the general header of an lma file
Definition: agattypes.hpp:24
The Acqiris device.
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
LmaReader()
constructor
Definition: lma_reader.cpp:25
const channels_t & channels() const
ACQIRIS::Instrument _instrument
acqiris device where we store the file header information
Definition: lma_reader.h:58
devices_t & devices()
setters
Definition: cass_event.h:66
int16_t offset_mV
the offset of the channel in mV
Definition: agattypes.hpp:86
double & horpos()
setter
Definition: channel.hpp:101
void loadSettings()
load the settings of the reader
Definition: lma_reader.cpp:29
id_t & id()
setters
Definition: cass_event.h:64
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
the header of a puls
Definition: agattypes.hpp:126
A Channel of an Acqiris Instrument.
Definition: channel.hpp:31
std::vector< Channel > channels_t
a vector of Channels
file contains specialized class that do the settings for cass
the header of each channel as part of the file header
Definition: agattypes.hpp:80
contains a logger for cass