CFEL - ASG Software Suite  2.5.0
CASS
waveform_generator.cpp
Go to the documentation of this file.
1 //Copyright (C) 2012 Lutz Foucar
2 
3 /**
4  * @file waveform_generator.cpp file contains a class for waveform generation
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <algorithm>
10 
11 #include "waveform_generator.h"
12 
13 #include "cass_event.h"
14 #include "acqiris_device.h"
15 #include "cass_settings.h"
16 #include "channel.h"
17 
18 using namespace std;
19 using namespace cass;
20 using namespace ACQIRIS;
21 
22 
23 Registrar<DataGenerator,WaveformGenerator> WaveformGenerator::reg("Waveform");
24 
25 WaveformGenerator::WaveformGenerator()
26 {
27 }
28 
29 void WaveformGenerator::load()
30 {
31  CASSSettings s;
32  s.beginGroup("WaveformGenerator");
33  _instrID = s.value("InstrumentId",8).toInt();
34  Instrument::channels_t &channels = _instrument.channels();
35  const size_t nSamples = s.value("NbrOfSamples",20000).toUInt();
36  const double sampleInterval = s.value("SampleInterval",1.e-9).toDouble();
37  const int size = s.beginReadArray("Channel");
38  channels.resize(size);
39  for (int i = 0; i < size; ++i)
40  {
41  s.setArrayIndex(i);
42  Channel &chan = channels[i];
43  chan.channelNbr() = 99;
44  chan.horpos() = 0;
45  chan.offset() = s.value("Offset",0).toDouble();
46  chan.sampleInterval() = sampleInterval;
47  chan.gain() = 0xFFFF / s.value("FullScale",0.5).toDouble();
48  chan.waveform().resize(nSamples);
49  }
50 
51 }
52 
53 void WaveformGenerator::fill(CASSEvent& evt)
54 {
55  /** generate random waveform */
56  Instrument::channels_t &channels = _instrument.channels();
57  for (Instrument::channels_t::iterator it(channels.begin()); it != channels.end(); ++it)
58  {
59  Channel &chan = *it;
60  waveform_t &waveform (chan.waveform());
61  generate(waveform.begin(),waveform.end(),qrand);
62  }
63 
64  /** retrieve acqiris device */
65  Device &dev(*dynamic_cast<Device*>(evt.devices()[CASSEvent::Acqiris]));
66  /** retrieve a reference to the requested instrument */
67  Instrument & instrument(dev.instruments()[static_cast<Instruments>(_instrID)]);
68  /** copy contents of the instrument to the instrument stored in the cassevent */
69  instrument = _instrument;
70 }
setArrayIndex(int i)
Event to store all LCLS Data.
Definition: cass_event.h:32
helper struct that will add Derived to the factory map
file contains declaration of the CASSEvent
Settings for CASS.
Definition: cass_settings.h:30
STL namespace.
things written only at end of run H5Dump ProcessorSummary size
beginReadArray(const QString &prefix)
file contains a class for waveform generation
devices_t & devices()
setters
Definition: cass_event.h:66
value(const QString &key, const QVariant &defaultValue=QVariant()
file contains specialized class that do the settings for cass
beginGroup(const QString &prefix)