CFEL - ASG Software Suite  2.5.0
CASS
test_input.cpp
Go to the documentation of this file.
1 // Copyright (C) 2012,2013 Lutz Foucar
2 
3 /**
4  * @file test_input.cpp contains declaration of a input for testing purposes
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <iostream>
10 #include <iomanip>
11 #include <fstream>
12 #include <string>
13 #include <sstream>
14 #include <stdexcept>
15 
16 #include <QtCore/QStringList>
17 
18 
19 #include "test_input.h"
20 
21 #include "cass_event.h"
22 #include "cass_settings.h"
23 #include "data_generator.h"
24 #include "generic_factory.hpp"
25 #include "log.h"
26 #include "cass_exceptions.h"
27 
28 using namespace std;
29 using namespace cass;
30 
31 void TestInput::instance(RingBuffer<CASSEvent> &ringbuffer,
32  Ratemeter &ratemeter, Ratemeter &loadmeter,
33  QObject *parent)
34 {
35  if(_instance)
36  throw logic_error("TestInput::instance(): The instance of the base class is already initialized");
37  _instance = shared_pointer(new TestInput(ringbuffer,ratemeter,loadmeter,parent));
38 }
39 
40 TestInput::TestInput(RingBuffer<CASSEvent> &ringbuffer,
41  Ratemeter &ratemeter, Ratemeter &loadmeter,
42  QObject *parent)
43  :InputBase(ringbuffer,ratemeter,loadmeter,parent)
44 {
45  Log::add(Log::VERBOSEINFO, "TestInput::TestInput(): constructed");
46  load();
47 }
48 
50 {
51  CASSSettings s;
52  s.beginGroup("TestInput");
53  QStringList usedFillers(s.value("Generators").toStringList());
54 
55  _generators.clear();
56 
57  for (QStringList::const_iterator it(usedFillers.begin()); it != usedFillers.end(); ++it)
58  {
61  DataGenerator::shared_pointer generator(generatorFactory.create(type));
62  generator->load();
63  _generators.push_back(generator);
64  }
65 }
66 
68 {
70 
71  while (true)
72  {
73  if (_control == _quit)
74  break;
75 
76  /** retrieve a new element from the ringbuffer */
77  CASSEvent *cassevent(0);
78  _ringbuffer.nextToFill(cassevent);
79 
80  /** fill the cassevent object with help of the fillers */
81  try
82  {
83  for (generators_t::iterator gen(_generators.begin()); gen != _generators.end(); ++gen)
84  (*gen)->fill(*cassevent);
85  cassevent->id() = ++_counter;
86  _ringbuffer.doneFilling(cassevent, true);
87  }
88  catch(const DataGenerationError &error)
89  {
90  Log::add(Log::ERROR,"TestInput::run(): Error generating a data packet");
91  _ringbuffer.doneFilling(cassevent, false);
92  }
93  newEventAdded(cassevent->datagrambuffer().size());
94  }
95  Log::add(Log::INFO,"TestInput::run():Quitting.");
96 }
Event to store all LCLS Data.
Definition: cass_event.h:32
class calculating a rate in Hz.
Definition: ratemeter.h:28
status_t _status
the internal status of the thread
file contains declaration of the CASSEvent
Settings for CASS.
Definition: cass_settings.h:30
Input base class.
Definition: input_base.h:31
STL namespace.
shared_pointer create(const typename instanciatorMap_t::key_type &type)
create an instance of the requested derived type
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
A Ringbuffer, handles communication between Input and Worker Threads.
Definition: ringbuffer.hpp:52
size_t _counter
a counter to create a fake event id
Definition: test_input.h:78
file contains base class for all data generators.
Testing Input for cass.
Definition: test_input.h:37
generators_t _generators
container for all used fillers
Definition: test_input.h:75
void load()
load the parameters used for the input
Definition: test_input.cpp:49
file contains declaration of a input for testing purposes
control_t _control
the internal control status of the thread
id_t & id()
setters
Definition: cass_event.h:64
void run()
function with the main loop
Definition: test_input.cpp:67
Exception thrown when there is a problem during data generation.
std::tr1::shared_ptr< DataGenerator > shared_pointer
typedef the shared pointer of this
value(const QString &key, const QVariant &defaultValue=QVariant()
RingBuffer< CASSEvent > & _ringbuffer
reference to the ringbuffer
Definition: input_base.h:140
buffer_t & datagrambuffer()
setters
Definition: cass_event.h:65
std::tr1::shared_ptr< InputBase > shared_pointer
shared pointer of this type
Definition: input_base.h:35
file contains specialized class that do the settings for cass
contains a factory that can be used for any class
contains a logger for cass
void newEventAdded(const size_t eventsize)
increment the numer of events received in the ratemeter
Definition: input_base.cpp:37
Factory for creating shared_pointers of classes derived from a base class.
beginGroup(const QString &prefix)