20 #include "kb_client.hpp"
33 throw logic_error(
"XFELOnlineInput::instance(): The instance of the base class is already initialized");
42 :
InputBase(ringbuffer,ratemeter,loadmeter,parent),
43 _quitWhenDone(quitwhendone),
57 string serverAddress(s.
value(
"ServerAddress",
"tcp://localhost:1234").toString().toStdString());
60 const size_t nPulses(s.
value(
"NbrPulsesInTrain",64).toUInt());
63 string source(s.
value(
"Source",
"SPB_DET_AGIPD1M-1/DET/detector-1").toString().toStdString());
65 string imageDataPath(s.
value(
"PathToImage",
"image.data").toString().toStdString());
67 int det_CASSID(s.
value(
"CASSID",30).toInt());
71 karabo_bridge::Client client;
78 client.connect(serverAddress);
82 serverAddress +
"'. Now waiting for data.");
97 auto data(client.next());
105 const auto det_shape(
data[source].array[imageDataPath].shape());
106 const bool dataNeedsPermutation(det_shape[3] != 128);
107 size_t nPulsesFromImage;
109 size_t nRowsInModule;
111 if (dataNeedsPermutation)
114 nPulsesFromImage = (det_shape[3]);
115 nModules = (det_shape[0]);
116 nRowsInModule = (det_shape[2]);
117 nCols = (det_shape[1]);
122 nPulsesFromImage = (det_shape[0]);
123 nModules = (det_shape[1]);
124 nRowsInModule = (det_shape[2]);
125 nCols = (det_shape[3]);
127 const size_t sizeofOneDet(nModules*nRowsInModule*nCols);
128 const size_t nCASSRows(nModules*nRowsInModule);
132 const auto nElements(
data[source].array[imageDataPath].
size());
133 if (
data[source].array[imageDataPath].dtype() ==
"uint16_t")
135 const auto ptr(
data[source].array[imageDataPath].data<uint16_t>());
136 det_data.assign(ptr,ptr+nElements);
138 else if (
data[source].array[imageDataPath].dtype() ==
"float32")
142 const auto ptr(
data[source].array[imageDataPath].data<float>());
143 if (dataNeedsPermutation)
146 det_data.resize(nElements);
147 for (
size_t iModule(0); iModule < nModules ; ++iModule)
149 for (
size_t iColumn(0); iColumn < nCols ; ++iColumn)
151 for (
size_t iRow(0); iRow < nRowsInModule ; ++iRow)
153 for (
size_t iPulse(0); iPulse < nPulsesFromImage; ++iPulse)
155 auto origIDX(iPulse +
157 iColumn*nPulsesFromImage*nRowsInModule +
158 iModule*nPulsesFromImage*nRowsInModule*nCols);
160 iColumn*nRowsInModule +
161 iModule*nRowsInModule*nCols +
162 iPulse*nRowsInModule*nCols*nModules);
163 det_data[goodIDX] = ptr[origIDX];
171 det_data.assign(ptr,ptr+nElements);
176 if (nPulses != nPulsesFromImage)
179 toString(nPulses) +
"' and the detector data '" +
180 toString(nPulsesFromImage) +
"' mismatch. "+
185 for(
size_t pulseID(0); pulseID < nPulses; ++pulseID)
188 if ((pulseID == 0) ||
217 CASSEvent::devices_t::iterator devIt;
221 if(devIt == devices.end())
222 throw runtime_error(
string(
"XFELOnlineInput: CASSEvent does not ") +
223 "contain a pixeldetector device");
228 det.columns() = nCols;
229 det.rows() = nCASSRows;
233 auto offsetToBegin(pulseID * sizeofOneDet);
234 auto offsetToEnd((pulseID+1) * sizeofOneDet);
235 det.frame().assign(det_data.begin()+offsetToBegin,det_data.begin()+offsetToEnd);
241 if(devIt == devices.end())
242 throw runtime_error(
string(
"XFELOnlineInput: CASSEvent does not") +
243 " contain a machinedata device");
252 for (
auto& d :
data) datasize += d.second.bytesReceived();
Event to store all LCLS Data.
class calculating a rate in Hz.
status_t _status
the internal status of the thread
detectors_t & dets()
instrument setter
things written only at end of run H5Dump ProcessorSummary size
file contains custom exceptions used in cass
static void add(Level level, const std::string &line)
add a string to the log
Container for all Machine related Data.
A Ringbuffer, handles communication between Input and Worker Threads.
devices_t & devices()
setters
std::vector< pixel_t > frame_t
a frame is a vector of pixels
bool shouldQuit() const
query whether this thread is told to quit
file contains the declaration of the acqiris part of the CASSEvent
std::string toString(const Type &t)
convert any type to a string
auxiliary data[Processor]
value(const QString &key, const QVariant &defaultValue=QVariant()
std::map< Device, DeviceBackend::shared_pointer > devices_t
mapping from device type to handler instance
contains container for simple pixel detector data
definitions of a machine device
file contains specialized class that do the settings for cass
the device containing pixel detector data
Detector containing a ccd camera image.
void pausePoint()
point where the thread will be paused
contains a logger for cass
int16_t pixel
define a pixel
const bldMap_t & BeamlineData() const
getter
beginGroup(const QString &prefix)