00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "psana_examples/DumpAcqiris.h"
00017
00018
00019
00020
00021 #include <algorithm>
00022
00023
00024
00025
00026 #include "MsgLogger/MsgLogger.h"
00027 #include "pdsdata/xtc/DetInfo.hh"
00028 #include "psddl_psana/acqiris.ddl.h"
00029
00030
00031
00032
00033
00034 using namespace psana_examples;
00035 PSANA_MODULE_FACTORY(DumpAcqiris)
00036
00037
00038
00039
00040
00041 namespace psana_examples {
00042
00043
00044
00045
00046 DumpAcqiris::DumpAcqiris (const std::string& name)
00047 : Module(name)
00048 {
00049 m_source = configSrc("source", "DetInfo(:Acqiris.*)");
00050 }
00051
00052
00053
00054
00055 DumpAcqiris::~DumpAcqiris ()
00056 {
00057 }
00058
00059
00060 void
00061 DumpAcqiris::beginCalibCycle(Event& evt, Env& env)
00062 {
00063 MsgLog(name(), trace, "in beginCalibCycle()");
00064
00065 shared_ptr<Psana::Acqiris::ConfigV1> acqConfig = env.configStore().get(m_source, &m_src);
00066 if (acqConfig) {
00067 WithMsgLog(name(), info, str) {
00068 str << "Acqiris::ConfigV1: nbrBanks=" << acqConfig->nbrBanks()
00069 << " channelMask=" << acqConfig->channelMask()
00070 << " nbrChannels=" << acqConfig->nbrChannels()
00071 << " nbrConvertersPerChannel=" << acqConfig->nbrConvertersPerChannel();
00072
00073 const Psana::Acqiris::HorizV1& h = acqConfig->horiz();
00074 str << "\n horiz: sampInterval=" << h.sampInterval()
00075 << " delayTime=" << h.delayTime()
00076 << " nbrSegments=" << h.nbrSegments()
00077 << " nbrSamples=" << h.nbrSamples();
00078
00079 const ndarray<const Psana::Acqiris::VertV1, 1>& vert = acqConfig->vert();
00080 for (unsigned ch = 0; ch < acqConfig->nbrChannels(); ++ ch) {
00081 const Psana::Acqiris::VertV1& v = vert[ch];
00082 str << "\n vert(" << ch << "):"
00083 << " fullScale=" << v.fullScale()
00084 << " slope=" << v.slope()
00085 << " offset=" << v.offset()
00086 << " coupling=" << v.coupling()
00087 << " bandwidth=" << v.bandwidth();
00088 }
00089 }
00090 }
00091 }
00092
00093
00094 void
00095 DumpAcqiris::event(Event& evt, Env& env)
00096 {
00097
00098 Pds::Src src;
00099 shared_ptr<Psana::Acqiris::DataDescV1> acqData = evt.get(m_src);
00100 if (acqData) {
00101
00102
00103 shared_ptr<Psana::Acqiris::ConfigV1> acqConfig = env.configStore().get(m_src);
00104
00105
00106 int nchan = acqData->data_shape()[0];
00107 for (int chan = 0; chan < nchan; ++ chan) {
00108
00109 const Psana::Acqiris::DataDescV1Elem& elem = acqData->data(chan);
00110
00111 const Psana::Acqiris::VertV1& v = acqConfig->vert()[chan];
00112 double slope = v.slope();
00113 double offset = v.offset();
00114
00115 WithMsgLog(name(), info, str ) {
00116
00117 str << "Acqiris::DataDescV1: channel=" << chan
00118 << "\n nbrSegments=" << elem.nbrSegments()
00119 << "\n nbrSamplesInSeg=" << elem.nbrSamplesInSeg()
00120 << "\n indexFirstPoint=" << elem.indexFirstPoint();
00121
00122 const ndarray<const Psana::Acqiris::TimestampV1, 1>& timestamps = elem.timestamp();
00123 const ndarray<const int16_t, 2>& waveforms = elem.waveforms();
00124
00125
00126 for (unsigned seg = 0; seg < elem.nbrSegments(); ++ seg) {
00127
00128 unsigned size = elem.nbrSamplesInSeg();
00129 ndarray<const int16_t, 1> raw(waveforms[seg]);
00130 ndarray<float, 1> wf = make_ndarray<float>(size);
00131 for (unsigned i = 0; i < size; ++ i) {
00132 wf[i] = raw[i]*slope + offset;
00133 }
00134
00135 str << "\n Segment #" << seg
00136 << "\n timestamp value = " << timestamps[seg].value() << " pos = " << timestamps[seg].pos()
00137 << "\n raw = " << raw
00138 << "\n data = " << wf;
00139
00140 }
00141 }
00142 }
00143 }
00144 }
00145
00146 }