10 #include <tr1/functional>
18 #include <OnlineUserAPI.h>
30 using tr1::placeholders::_1;
58 funcstatus = ol_connect(&_sockID, name.c_str());
60 throw runtime_error(
"DetectorTile: could not retrieve socket id of '" +
61 name +
"' ErrorCode is '" +
toString(funcstatus) +
65 int datasize = 0, worksize = 0;
66 funcstatus = ol_get_data_size(&datasize, &worksize, _sockID);
68 throw runtime_error(
"DetectorTile: could not retrieve datasize'" +
69 name +
"' ErrorCode is '" +
toString(funcstatus) +
71 _databuffer.resize(datasize,0);
72 _workbuffer.resize(worksize,0);
78 funcstatus = ol_read_det_xsize(&xsize, &(_databuffer.front()), 0);
80 throw runtime_error(
"DetectorTile: could not extract xsize of tile '" +
81 name +
"' ErrorCode is '" +
toString(funcstatus) +
"'");
83 funcstatus = ol_read_det_ysize(&ysize, &_databuffer.front(), 0);
85 throw runtime_error(
"DetectorTile: could not extract ysize of tile '" +
86 name +
"' ErrorCode is '" +
toString(funcstatus) +
"'");
89 funcstatus = ol_read_abs_gain(&gain, &_databuffer.front(), 0);
91 throw runtime_error(
"DetectorTile: could not extract gain of tile '" +
92 name +
"' ErrorCode is '" +
toString(funcstatus) +
111 int funcstatus = ol_collect_det_data(&_databuffer.front(),
112 &_workbuffer.front(),
118 if (funcstatus == OL_ERR_TAGDATAGONE)
120 "' on socket '" +
toString(_sockID) +
121 "' isn't available anymore");
123 throw runtime_error(
"DetectorTile: could not retrieve data of tile '" +
124 name +
"' for tag '" +
toString(tag) +
125 "' using socket '" +
toString(_sockID) +
126 "'. ErrorCode is '" +
toString(funcstatus) +
"'");
142 if (this->tag() != tag)
147 int funcstatus = ol_read_det_data(&data_org, &_databuffer.front(), 0);
148 if (funcstatus < 0 || !data_org)
151 name +
"' ErrorCode is '" +
toString(funcstatus) +
"'");
158 if (normalizeID != -1)
159 transform(data_org, data_org+xsize*ysize, start,
160 bind1st(multiplies<float>(),relativeGain));
162 copy(data_org, data_org+xsize*ysize, start);
165 datasize = xsize * ysize *
sizeof(uint16_t);
175 int funcstatus = ol_read_tag_num(&tag, &_databuffer.front(), 0);
178 name +
"' ErrorCode is '" +
toString(funcstatus) +
"'");
189 int funcstatus = ol_read_run_num(&run, &_databuffer.front(), 0);
192 name +
"' ErrorCode is '" +
toString(funcstatus) +
"'");
212 pixeldetector::Detector::frame_t::iterator
start;
256 return lastTag + tagAdvance;
259 tiles.front().retrieveData();
260 return tiles.front().tag();
272 return tiles.front().runNumber();
291 for (
size_t i(0); i < tiles.size(); ++i)
293 det.frame().resize(det.frame().size() +
294 tiles[i].xsize*tiles[i].ysize);
295 det.columns() = tiles[i].xsize;
296 det.rows() += tiles[i].ysize;
300 size_t currentsize(0);
301 for (
size_t i(0); i < tiles.size(); ++i)
303 tiles[i].start = det.frame().begin() + currentsize;
304 const size_t npixels(tiles[i].xsize*tiles[i].ysize);
305 currentsize += npixels;
330 #pragma omp parallel for shared(error) num_threads(tiles.size())
332 for (
size_t i = 0; i < tiles.size(); ++i)
341 tiles[i].copyData(tag);
357 uint64_t datasize(0);
358 for (
size_t i(0); i < tiles.size(); ++i)
359 datasize += tiles[i].datasize;
480 throw logic_error(
"SACLAOnlineInput::instance(): The instance of the base class is already initialized");
488 :
InputBase(ringbuffer,ratemeter,loadmeter,parent),
490 _skippedEvtCounter(0)
502 vector<OctalDetector> octalDetectors;
504 for (
int i = 0; i <
size; ++i)
507 int cassid(s.
value(
"CASSID",-1).toInt());
515 det.tagAdvance = s.
value(
"NextTagNumberAdvancedBy",2).toInt();
516 Log::add(
Log::INFO,
"SACLAOnlineInput: Setting up octal detector with cassid '" +
517 toString(cassid) +
"'. The next tag number is guessed by " +
518 "advancing the current one by '" +
toString(det.tagAdvance) +
"'");
521 for (
int j(0); j<nTiles; ++j)
524 const string tilename(s.
value(
"TileName",
"Invalid").toString().toStdString());
525 octalDetectors.back().tiles.push_back(
DetectorTile(tilename));
533 tile.
ysize -= s.
value(
"NbrCalibrationRows",6).toUInt();
534 tile.normalizeID = s.
value(
"NormalizeTo",0).toInt()-1;
536 for (
size_t j(0); j<det.tiles.size(); ++j)
543 (tile.
normalizeID == -1 ?
"":
" The tile will be normalized to tile '" +
546 " with relative gain '" +
556 if (octalDetectors.empty())
557 throw invalid_argument(
"SACLAOnlineInput: Need to have at least one octal detector defined");
563 size_t maxGuessedEvents(s.
value(
"MaxGuessedEvents",60).toUInt());
568 int BeamlineNbr = s.
value(
"BeamlineNumber",3).toInt();
606 toString(omp_get_max_threads()) +
"' input threads");
626 uint64_t datasize(0);
636 if(devIt == devices.end())
637 throw runtime_error(
"SACLAOnlineInput: CASSEvent does not contains a pixeldetector device");
641 int latestTag(octalDetectors.front().latestTag(lastTag));
649 if (latestTag > lastTag)
652 evt.
id() = latestTag;
657 vector<OctalDetector>::iterator octIter(octalDetectors.begin());
658 vector<OctalDetector>::iterator octEnd(octalDetectors.end());
659 for(; octIter != octEnd; ++octIter)
661 datasize += octIter->copyData(dev,latestTag);
685 if (counter < maxGuessedEvents)
712 toString(rbItem->element->id()) +
"' is bad: skipping Event");
Event to store all LCLS Data.
vector< char > _databuffer
the buffer with the detector data
int normalizeID
id of tile to normalize to
class calculating a rate in Hz.
std::string name
the name of the detector tile
pixeldetector::Detector::frame_t::iterator start
start position of the tile within the frame
detectors_t & dets()
instrument setter
int tagAdvance
how much the last tag should be advanced
Exception thrown when SACLA tag is outdated.
int runNumber()
the current Run Number read from the current databuffer
uint64_t copyData(pixeldetector::Device &dev, int tag)
copy data associtated with the tag to the device of the cassevent
things written only at end of run H5Dump ProcessorSummary size
vector< char > _workbuffer
buffer needed for the retrieval function to work
file contains custom exceptions used in cass
vector< DetectorTile > tiles
vector containing the tiles of the detector
int xsize
the width of the tile
uint64_t datasize
the size of the retrieved data
static void add(Level level, const std::string &line)
add a string to the log
beginReadArray(const QString &prefix)
int runNumber()
get the latest Run Number
A Ringbuffer, handles communication between Input and Worker Threads.
front pnCCD LCLSPixelDetectors CASSID
devices_t & devices()
setters
int _sockID
the socket ID to connect to the online API
bool shouldQuit() const
query whether this thread is told to quit
void retrieveData(int tag=OL_NEWESTTAGDATA)
read the data
int CASSID
the id that the detector should have within the pixeldetector part of the CASSEvent ...
std::string toString(const Type &t)
convert any type to a string
value(const QString &key, const QVariant &defaultValue=QVariant()
DetectorTile(const string &name)
constructor
std::map< Device, DeviceBackend::shared_pointer > devices_t
mapping from device type to handler instance
int tag()
the current Tag read from the current databuffer
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
int ysize
the height of the tile
Detector containing a ccd camera image.
void pausePoint()
point where the thread will be paused
contains a logger for cass
float gain
the gain of the tile
contains class to convert sacla data to cassevent
void copyData(int tag)
copy the tile data to the frame
beginGroup(const QString &prefix)
int latestTag(int lastTag)
get the latest Tag
float relativeGain
the relative gain to normalize for