CFEL - ASG Software Suite  2.5.0
CASS
machine_data.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 Lutz Foucar
2 
3 /**
4  * @file machine_data.cpp file contains definition of processors that
5  * extract information from the beamline and epics data.
6  *
7  * @author Lutz Foucar
8  */
9 
10 #include <QtCore/QString>
11 
12 #include "machine_data.h"
13 #include "machine_device.hpp"
14 #include "cass_settings.h"
15 #include "log.h"
16 #include "cass_exceptions.hpp"
17 
18 
19 using namespace cass;
20 using namespace MachineData;
21 using namespace std;
22 using namespace std::tr1;
23 
24 // *** processors 120 retrives beamline data ***
25 
26 pp120::pp120(const name_t &name)
27  : Processor(name)
28 {
29  loadSettings(0);
30 }
31 
32 void pp120::loadSettings(size_t)
33 {
34  CASSSettings s;
35  s.beginGroup("Processor");
36  s.beginGroup(name().c_str());
37  _varname = s.value("VariableName","").toString().toStdString();
38  setupGeneral();
39  if (!setupCondition())
40  return;
41 
43 
44  Log::add(Log::INFO,"Processor '" + name() + "': will retrieve datafield ' " +
45  _varname + "' from beamline data. Condition is '" + _condition->name() +"'");
46 }
47 
48 void pp120::process(const CASSEvent& evt, result_t &result)
49 {
50  const Device &md
51  (dynamic_cast<const Device&>
52  (*(evt.devices().find(CASSEvent::MachineData)->second)));
53  const Device::bldMap_t &bld(md.BeamlineData());
54  result.setValue(bld.find(_varname) == bld.end() ? 0: bld.find(_varname)->second);
55 }
56 
57 
58 
59 
60 
61 
62 
63 
64 // *** processors 121 checks event code ***
65 
66 pp121::pp121(const name_t &name)
67  : Processor(name)
68 {
69  loadSettings(0);
70 }
71 
72 void pp121::loadSettings(size_t)
73 {
74  CASSSettings s;
75  s.beginGroup("Processor");
76  s.beginGroup(name().c_str());
77  _eventcode = s.value("EventCode",0).toUInt();
78  setupGeneral();
79  if (!setupCondition())
80  return;
82 
83  Log::add(Log::INFO,"Processor '"+ name() + "' will check whether event code '" +
84  toString(_eventcode) + "' is present in the event. Condition is '" +
85  _condition->name() +"'");
86 }
87 
88 void pp121::process(const CASSEvent& evt, result_t &result)
89 {
90  using namespace MachineData;
91  const Device &md
92  (dynamic_cast<const Device&>
93  (*(evt.devices().find(CASSEvent::MachineData)->second)));
94  const Device::evrStatus_t &evr(md.EvrData());
95  result.setValue((_eventcode < evr.size()) ? evr[_eventcode] : 0);
96 }
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 // *** processors 122 retrieve eventID ***
110 
112  : Processor(name)
113 {
114  loadSettings(0);
115 }
116 
118 {
119  CASSSettings s;
120  s.beginGroup("Processor");
121  s.beginGroup(name().c_str());
122 
123  setupGeneral();
124  if (!setupCondition())
125  return;
126  _part = s.value("EventIDPart",0).toInt();
127 
129 
130  Log::add(Log::INFO,"Processor '" + name() + "' will retrieve the event ID from events. Condition is '" +
131  _condition->name() + "'");
132 }
133 
134 void pp122::process(const CASSEvent& evt, result_t &result)
135 {
136  if (_part == lower)
137  result.setValue(evt.id() & 0x00000000FFFFFFFF);
138  if (_part == upper)
139  result.setValue((evt.id() & 0xFFFFFFFF00000000) >> 32);
140  else
141  result.setValue(evt.id());
142 }
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 // *** processors 123 retrieve beamline spectrometer data ***
159 
160 pp123::pp123(const name_t &name)
161  : Processor(name)
162 {
163  loadSettings(0);
164 }
165 
167 {
168  setupGeneral();
169  if (!setupCondition())
170  return;
171  CASSSettings s;
172  s.beginGroup("Processor");
173  s.beginGroup(name().c_str());
174  _specname = s.value("SpectrometerName","").toString().toStdString();
175  int size(0);
176  if (_specname.find("horiz") != string::npos)
177  size = 1024;
178  if (_specname.find("vert") != string::npos)
179  size = 256;
180  size = s.value("Size",size).toInt();
183  (new result_t(result_t::axe_t(size,0,size,"arb. units"))));
184 
185  Log::add(Log::INFO,"Processor '" + name() + "' will retrieve the beamline spectrometer data '"+
186  _specname +"'.Condition is '" + _condition->name() + "'");
187 }
188 
189 void pp123::process(const CASSEvent& evt, result_t &result)
190 {
191  using namespace MachineData;
192  const Device &mdev
193  (dynamic_cast<const Device&>
194  (*(evt.devices().find(CASSEvent::MachineData)->second)));
195  const Device::spectrometer_t &spectros(mdev.spectrometers());
196  Device::spectrometer_t::const_iterator specIt(spectros.find(_specname));
197  if (specIt == spectros.end())
198  throw InvalidData("pp123::process (" + name() + "): Spectrometer with name '" +
199  _specname +"' is unknown.");
200  const Device::spectrometer_t::mapped_type &spec(specIt->second);
201 
202  if (result.size() < spec.size())
203  throw logic_error("pp123:process (" + name() +
204  "): Result with size '" + toString(result.size()) +
205  "'is not large enough to handle spectrometer data with size" +
206  toString(spec.size()) + "'");
207  copy(spec.begin(),spec.end(),result.begin());
208 }
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 // *** processors 130 retrives epics data ***
222 
224  : Processor(name)
225 {
226  loadSettings(0);
227 }
228 
230 {
231  CASSSettings settings;
232  settings.beginGroup("Processor");
233  settings.beginGroup(name().c_str());
234  _varname = settings.value("VariableName","").toString().toStdString();
235  setupGeneral();
236  if (!setupCondition())
237  return;
239  Log::add(Log::INFO,"Processor '" + name() + "' will retrieve datafield' " +
240  _varname +"' from epics data. Condition is" + _condition->name() + "'");
241 }
242 
243 void pp130::process(const CASSEvent& evt, result_t &result)
244 {
245  using namespace MachineData;
246  const Device &md
247  (dynamic_cast<const Device&>
248  (*(evt.devices().find(CASSEvent::MachineData)->second)));
249  const Device::epicsDataMap_t &epics(md.EpicsData());
250  Device::epicsDataMap_t::const_iterator eit(epics.find(_varname));
251  result.setValue(eit == epics.end() ? 0 : eit->second);
252 }
253 
254 
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 // *** processors 230 calcs photonenergy from bld ***
267 
269  : Processor(name)
270 {
271  loadSettings(0);
272 }
273 
275 {
276  if (!setupCondition())
277  return;
278  setupGeneral();
280  Log::add(Log::INFO,"Processor '" + name() + "' calculates photonenergy from " +
281  "'EbeamL3Energy' and 'EbeamPkCurrBC2'." + " Condition is '" +
282  _condition->name() + "'");
283 }
284 
285 void pp230::process(const CASSEvent& evt, result_t &result)
286 {
287  using namespace MachineData;
288  const Device &md
289  (dynamic_cast<const Device&>
290  (*(evt.devices().find(CASSEvent::MachineData)->second)));
291  const Device::bldMap_t bld(md.BeamlineData());
292 
293  const double ebEnergy
294  (bld.find("EbeamL3Energy") == bld.end() ? 0 : bld.find("EbeamL3Energy")->second);
295  const double peakCurrent
296  (bld.find("EbeamPkCurrBC2") == bld.end() ? 0 : bld.find("EbeamPkCurrBC2")->second);
297 
298  // const double K (3.5); // K of the undulator (provided by Marc Messerschmidt)
299  // const double lambda (3.0e7); // LCLS undulator period in nm
300  // const double hc (1239.84172); // in eV*nm
301  // // electron energy in rest mass units (E/mc^2)
302  // double gamma (ebEnergy/(0.510998903));
303  // // resonant photon wavelength in same units as undulator period)
304  // double photonenergy (hc*2*gamma*gamma/(lambda*(1+K*K/2)));
305 
306  //=======================================================================================
307 
308  // Get present beam energy [GeV]
309  const double DL2energyGeV (0.001*ebEnergy);
310  // wakeloss prior to undulators
311  const double LTUwakeLoss (0.0016293*peakCurrent);
312  // Spontaneous radiation loss per segment
313  const double SRlossPerSegment (0.63*DL2energyGeV);
314  // wakeloss in an undulator segment
315  const double wakeLossPerSegment (0.0003*peakCurrent);
316  // energy loss per segment
317  const double energyLossPerSegment (SRlossPerSegment + wakeLossPerSegment);
318  // energy in first active undulator segment [GeV]
319  const double energyProfile (DL2energyGeV - 0.001*LTUwakeLoss - 0.0005*energyLossPerSegment);
320  // Calculate the resonant photon energy of the first active segment
321  const double photonenergy (44.42*energyProfile*energyProfile);
322 
323  result.setValue(photonenergy);
324 }
CachedList::item_type result_t
define the results
Definition: processor.h:52
Event to store all LCLS Data.
Definition: cass_event.h:32
virtual void createHistList(result_t::shared_pointer result)
create result list.
Definition: processor.cpp:79
virtual void loadSettings(size_t)
load the settings from cass.ini
virtual void process(const CASSEvent &, result_t &)
copy data from CASS event to histogram storage
virtual void process(const CASSEvent &, result_t &)
calc the photonenergy from the bld
std::string _specname
the name of the spectrometer to retrieve from the machine device
Definition: machine_data.h:221
pp230(const name_t &)
constructor
const name_t name() const
retrieve the name of this processor
Definition: processor.h:167
virtual void process(const CASSEvent &, result_t &)
copy data from CASS event to histogram storage
Settings for CASS.
Definition: cass_settings.h:30
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
Definition: result.hpp:323
int _part
which part of the eventid should be retrieved
Definition: machine_data.h:173
size_type size() const
return the raw size of the storage
Definition: result.hpp:881
STL namespace.
an axis of a more than 0 dimensional container
Definition: result.hpp:29
things written only at end of run H5Dump ProcessorSummary size
file contains custom exceptions used in cass
virtual void loadSettings(size_t)
load the settings from cass.ini
Exception thrown when there is a problem with the data.
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
virtual void loadSettings(size_t)
load the settings from cass.ini
void setValue(const_reference value)
assign the result container to a value
Definition: result.hpp:543
const_iterator begin() const
retrieve a iterator for read access to beginning
Definition: result.hpp:608
virtual void process(const CASSEvent &, result_t &)
copy data from CASS event to histogram storage
pp130(const name_t &)
constructor
base class for processors.
Definition: processor.h:39
Container for all Machine related Data.
virtual void process(const CASSEvent &, result_t &)
copy data from CASS event to histogram storage
devices_t & devices()
setters
Definition: cass_event.h:66
std::map< std::string, double > epicsDataMap_t
define the epics container
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
virtual void loadSettings(size_t)
load the settings from cass.ini
pp120(const name_t &)
constructor
value(const QString &key, const QVariant &defaultValue=QVariant()
std::string _varname
name of the variable in the beamline data
Definition: machine_data.h:267
std::map< std::string, double > bldMap_t
define the beamline data container
virtual void loadSettings(size_t)
load the settings from cass.ini
virtual void loadSettings(size_t)
load the settings from cass.ini
std::string _varname
name of the variable in the beamline data
Definition: machine_data.h:88
void setupGeneral()
general setup of the processor
Definition: processor.cpp:85
definitions of a machine device
file contains specialized class that do the settings for cass
pp121(const name_t &)
constructor
std::vector< bool > evrStatus_t
define the evr status container
virtual void process(const CASSEvent &, result_t &)
copy data from CASS event to histogram storage
shared_pointer _condition
pointer to the processor that will contain the condition
Definition: processor.h:277
pp122(const name_t &)
constructor
std::map< std::string, std::vector< uint32_t > > spectrometer_t
define the spectrometer data
bool setupCondition(bool defaultConditionType=true)
setup the condition.
Definition: processor.cpp:94
std::string name_t
define the name type
Definition: processor.h:46
contains a logger for cass
size_t _eventcode
name of the variable in the beamline data
Definition: machine_data.h:125
pp123(const name_t &)
constructor
beginGroup(const QString &prefix)
file contains declaration of processors that extract information from the beamline and epics data...