CFEL - ASG Software Suite  2.5.0
CASS
signal_producer.cpp
Go to the documentation of this file.
1 //Copyright (C) 2010 Lutz Foucar
2 
3 /**
4  * @file signal_producer.cpp file contains the classes that describe how to
5  * analyze the waveform and stores the result.
6  *
7  * @author Lutz Foucar
8  */
9 #include <stdexcept>
10 #include <iostream>
11 
12 #include "signal_producer.h"
13 #include "cass_settings.h"
14 
15 #include "signal_extractor.h"
16 
17 using namespace cass::ACQIRIS;
18 using namespace std;
19 
20 namespace cass
21 {
22 namespace ACQIRIS
23 {
24 /** functor returning true if signal is in requested range
25  *
26  * @author Lutz Foucar
27  */
28 class isInTimeRange : std::unary_function<SignalProducer::signal_t,bool>
29 {
30 public:
31  /** constructor intializing the range*/
32  isInTimeRange(const std::pair<double,double>& range)
33  :_range(range)
34  {}
35 
36  bool operator()(const SignalProducer::signal_t &sig)const
37  {
38  return (sig[time] >_range.first && sig[time] <= _range.second);
39  }
40 
41 private:
42  /** the range */
43  std::pair<double,double> _range;
44 };
45 }//end namespace cass
46 }//end namespace acqiris
47 
49 {
50  SignalExtractorType analyzerType
51  (static_cast<SignalExtractorType>(s.value("SignalExtractionMethod",com16).toInt()));
52  _signalextractor = SignalExtractor::instance(analyzerType);
53  _signalextractor->loadSettings(s);
54  _range = make_pair(s.value("GoodRangeLow",0).toDouble(),
55  s.value("GoodRangeHigh",0).toDouble());
56 }
57 
59 {
60  bool newEventAssociated (_newEventAssociated);
61  _newEventAssociated = false;
62  return (newEventAssociated)? (*_signalextractor)(_signals):_signals;
63 }
64 
66 {
67  _newEventAssociated = true;
68  _goodHitExtracted = false;
69  _signals.clear();
70  _goodHit = 0;
71  _signalextractor->associate(evt);
72 }
73 
74 double SignalProducer::firstGood(const std::pair<double,double>& range)
75 {
76  if(!_goodHitExtracted)
77  {
78  _goodHitExtracted = true;
79  signals_t &sigs (output());
80  signals_t::iterator sigIt(find_if(sigs.begin(),sigs.end(),isInTimeRange(range)));
81  _goodHit = (sigIt != sigs.end())? (*sigIt)[time] : 0;
82  }
83  return _goodHit;
84 }
85 
87 {
88  if(!_goodHitExtracted)
89  {
90  _goodHitExtracted = true;
91  signals_t &sigs (output());
92  signals_t::iterator sigIt(find_if(sigs.begin(),sigs.end(), isInTimeRange(_range)));
93  _goodHit = (sigIt != sigs.end())? (*sigIt)[time] : 0;
94  }
95  return _goodHit;
96 }
Event to store all LCLS Data.
Definition: cass_event.h:32
file contains the classes that describe how to analyze the waveform and stores the result...
std::vector< signal_t > signals_t
Settings for CASS.
Definition: cass_settings.h:30
double firstGood()
returns the time of the first peak in the time range
STL namespace.
std::vector< double > signal_t
void loadSettings(CASSSettings &s)
loads the settings.
static std::tr1::shared_ptr< SignalExtractor > instance(SignalExtractorType type)
creates an instance of the requested extractor type
void associate(const CASSEvent &evt)
assciate the event with this signalproducer
file file contains base class for all classes that extract signals from the recorded data ...
value(const QString &key, const QVariant &defaultValue=QVariant()
isInTimeRange(const std::pair< double, double > &range)
constructor intializing the range
bool operator()(const SignalProducer::signal_t &sig) const
file contains specialized class that do the settings for cass
signals_t & output()
return the signals
SignalExtractorType
the waveformanalyzers that are available
functor returning true if signal is in requested range
std::pair< double, double > _range
the range