CFEL - ASG Software Suite  2.5.0
CASS
acqiristdc_converter.cpp
Go to the documentation of this file.
1 //Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file acqiristdc_converter.cpp file contains the definition of the converter
5  * for the xtc containing acqiris tdc data.
6  *
7  * @author Lutz Foucar
8  */
9 
10 #include <cassert>
11 #include <sstream>
12 #include <stdexcept>
13 
14 #include "pdsdata/xtc/Xtc.hh"
15 #include "pdsdata/xtc/TypeId.hh"
16 #include "pdsdata/xtc/DetInfo.hh"
17 #include "pdsdata/xtc/Src.hh"
18 #include "pdsdata/acqiris/TdcConfigV1.hh"
19 #include "pdsdata/acqiris/TdcDataV1.hh"
20 
21 #include "acqiristdc_converter.h"
22 
23 #include "acqiristdc_device.hpp"
24 #include "cass_event.h"
25 
26 using namespace cass::ACQIRISTDC;
27 using namespace std;
28 
29 // =================define static members =================
32 
34 {
35  QMutexLocker locker(&_mutex);
36  if(!_instance)
37  {
39  }
40  return _instance;
41 }
42 // ========================================================
43 
44 
46 {
47  _pdsTypeList.push_back(Pds::TypeId::Id_AcqTdcData);
48  _pdsTypeList.push_back(Pds::TypeId::Id_AcqTdcConfig);
49 }
50 
51 void Converter::operator()(const Pds::Xtc* xtc, cass::CASSEvent* evt)
52 {
53  //check whether xtc is a configuration or a event//
54  switch (xtc->contains.id())
55  {
56  case (Pds::TypeId::Id_AcqTdcConfig) :
57  {
58  const Pds::DetInfo& info = *(Pds::DetInfo*)(&xtc->src);
59 // assert(static_cast<int>(info.detector()) == static_cast<int>(SXRTdc));
60  cass::CASSEvent::devices_t::iterator devIt
61  (evt->devices().find(cass::CASSEvent::AcqirisTDC));
62  assert(evt->devices().end() != devIt);
63  Device &dev (dynamic_cast<Device&>(*(devIt->second)));
64  Instrument &instr(dev.instruments()[info.devId()]);
65  Instrument::channels_t &channels(instr.channels());
66  channels.resize(Instrument::NbrChannels);
67  cout << "ACQIRISTDC::Converter: found '"<<Pds::DetInfo::name(info)
68  <<"' configuration in datastream."
69  <<endl;
70  }
71  break;
72 
73  //if it is a event then extract all information from the event//
74  case (Pds::TypeId::Id_AcqTdcData):
75  {
76  const Pds::DetInfo& info = *(Pds::DetInfo*)(&xtc->src);
77  cass::CASSEvent::devices_t::iterator devIt
78  (evt->devices().find(cass::CASSEvent::AcqirisTDC));
79  assert(evt->devices().end() != devIt);
80  Device &dev (dynamic_cast<Device&>(*(devIt->second)));
81  Instrument &instr(dev.instruments()[info.devId()]);
82 // if (xtc->sizeofPayload()/4 > 2)
83 // {
84 // uint32_t* word ((uint32_t*) xtc->payload());
85 // cout << "start"<<endl;
86 // for (int i(0); i < xtc->sizeofPayload()/4 ; ++i)
87 // cout << hex<< word[i] <<dec<<endl;
88 // cout << "stop"<<endl;
89 // }
90 // Device::instruments_t::iterator instrIt
91 // (dev->instruments().find(info.devId()));
92 // if (dev->instruments().end() == instrIt)
93 // {
94 // stringstream ss;
95 // ss<<"ACQIRISTDC::Converter(): The AcqirisTDC in the CASSEvent does"
96 // <<" not contain the instrument '"<<Pds::DetInfo::name(info)<<"'";
97 // throw runtime_error(ss.str());
98 // }
99 // Instrument &instr(instrIt->second);
100  Instrument::channels_t &channels(instr.channels());
101  channels.resize(Instrument::NbrChannels);
102  assert(6 == channels.size());
103  for (Instrument::channels_t::iterator it(channels.begin()); it != channels.end(); ++it)
104  it->hits().clear();
105  //extract the data from the xtc//
106  const Pds::Acqiris::TdcDataV1 *data
107  (reinterpret_cast<const Pds::Acqiris::TdcDataV1*>(xtc->payload()));
108  // Data is terminated with an AuxIOMarker (Memory bank switch)
109  while(!(data->source() == Pds::Acqiris::TdcDataV1::AuxIO &&
110  static_cast<const Pds::Acqiris::TdcDataV1::Marker*>(data)->type() <
111  Pds::Acqiris::TdcDataV1::Marker::AuxIOMarker))
112  {
113  switch(data->source())
114  {
115  case Pds::Acqiris::TdcDataV1::Comm:
116  break;
117  case Pds::Acqiris::TdcDataV1::AuxIO:
118  break;
119  default:
120  {
121  const Pds::Acqiris::TdcDataV1::Channel& c
122  (*static_cast<const Pds::Acqiris::TdcDataV1::Channel*>(data));
123  if (!c.overflow())
124  {
125  //get data of the right channel and convert s to ns */
126  channels[data->source()-1].hits().push_back(c.time()*1e9);
127  }
128  break;
129  }
130  }
131  data++;
132  }
133  }
134  break;
135 
136 
137  default:
138  {
139  stringstream ss;
140  ss<<"ACQIRISTDC::Converter(): Xtc type'"<<Pds::TypeId::name(xtc->contains.id())
141  <<"' is not handled by TDCConverter";
142  throw logic_error(ss.str());
143  }
144  break;
145  }
146 }
static ConversionBackend::shared_pointer instance()
create singleton if doesnt exist already
Event to store all LCLS Data.
Definition: cass_event.h:32
file contains declaration of the CASSEvent
static QMutex _mutex
singleton locker for mutithreaded requests
STL namespace.
additional info
file contains the declaration of the acqiristdc part of the CASSEvent
The Acqiris TDC device.
std::vector< Channel > channels_t
a vector of Channels
devices_t & devices()
setters
Definition: cass_event.h:66
static ConversionBackend::shared_pointer _instance
the singleton container
void operator()(const Pds::Xtc *, CASSEvent *)
takes the xtc and copies the data to cassevent
auxiliary data[Processor]
std::tr1::shared_ptr< ConversionBackend > shared_pointer
typedef
file contains the declaration of the converter for the xtc containing acqiris tdc data...
An Acqiris TDC Instrument.