14 #include "pdsdata/xtc/Xtc.hh"
15 #include "pdsdata/xtc/TypeId.hh"
16 #include "pdsdata/xtc/DetInfo.hh"
17 #include "pdsdata/pnCCD/ConfigV1.hh"
18 #include "pdsdata/pnCCD/ConfigV2.hh"
19 #include "pdsdata/pnCCD/FrameV1.hh"
20 #include "pdsdata/camera/FrameV1.hh"
21 #include "pdsdata/cspad/ConfigV1.hh"
22 #include "pdsdata/cspad/ConfigV2.hh"
23 #include "pdsdata/cspad/ConfigV3.hh"
24 #include "pdsdata/cspad/ConfigV4.hh"
25 #include "pdsdata/cspad/ConfigV5.hh"
26 #include "pdsdata/cspad/ElementHeader.hh"
27 #include "pdsdata/cspad/ElementIterator.hh"
28 #include "pdsdata/cspad2x2/ConfigV1.hh"
29 #include "pdsdata/cspad2x2/ConfigV2.hh"
30 #include "pdsdata/cspad2x2/ElementHeader.hh"
31 #include "pdsdata/psddl/epix.ddl.h"
45 using std::tr1::shared_ptr;
68 if(devIt == devices.end())
70 throw runtime_error(
"pixeldetector::retrieveDet: There is no pixeldetector device within the CASSEvent");
72 Device &dev (dynamic_cast<Device&>(*(devIt->second)));
73 return (dev.
dets()[key]);
87 vector<uint8_t> payload(xtc->sizeofPayload());
88 copy(xtc->payload(),xtc->payload()+xtc->sizeofPayload(),payload.begin());
105 size_t & rowsOfSegment,
size_t &columnsOfSegment)
109 columnsOfSegment = 512;
124 size_t & rowsOfSegment,
size_t &columnsOfSegment)
126 det.
rows() = cfg.numRows();
127 det.
columns() = cfg.numChannels();
128 det.
info().assign(cfg.info());
131 rowsOfSegment = cfg.numSubmoduleRows();
132 columnsOfSegment = cfg.numSubmoduleChannels();
133 if(det.
rows()>1024||det.
columns()>1024||rowsOfSegment>512||columnsOfSegment>512)
154 template <
typename ConfigType>
157 const PNCCD::FrameV1* frameSegment
158 (reinterpret_cast<const Pds::PNCCD::FrameV1*>(xtc->payload()));
160 size_t rowsOfSegment(0);
161 size_t columnsOfSegment(0);
165 const size_t sizeOfOneSegment = frameSegment->sizeofData(cfg);
166 if (sizeOfOneSegment != rowsOfSegment*columnsOfSegment)
168 throw runtime_error(
"copyPnCCDFrame: size of one segment '" +
170 "' is inconsistent with number of rows '" +
171 toString(rowsOfSegment) +
"' colums '" +
172 toString(columnsOfSegment) +
"' of the segments");
174 const size_t NbrOfSegments = cfg.numLinks();
175 const size_t FrameSize = sizeOfOneSegment * NbrOfSegments;
176 det.
frame().resize(FrameSize);
178 vector<const uint16_t*> xtcSegmentPointers(NbrOfSegments,0);
179 for (
size_t i=0; i<NbrOfSegments ;++i)
182 xtcSegmentPointers[i] = frameSegment->data();
183 frameSegment = frameSegment->next(cfg);
185 const uint16_t * tileA = xtcSegmentPointers[0];
186 const uint16_t * tileB = xtcSegmentPointers[3];
187 const uint16_t * tileC = xtcSegmentPointers[1]+sizeOfOneSegment-1;
188 const uint16_t * tileD = xtcSegmentPointers[2]+sizeOfOneSegment-1;
190 Detector::frame_t::iterator
pixel = det.
frame().begin();
192 for (
size_t iRow=0; iRow<rowsOfSegment ;++iRow)
194 for (
size_t iCol=0; iCol<columnsOfSegment ;++iCol)
195 *pixel++ = *tileA++ & 0x3fff;
196 for (
size_t iCol=0; iCol<columnsOfSegment ;++iCol)
197 *pixel++ = *tileB++ & 0x3fff;
199 for (
size_t iRow=0; iRow<rowsOfSegment ;++iRow)
201 for (
size_t iCol=0; iCol<columnsOfSegment ;++iCol)
202 *pixel++ = *tileC-- & 0x3fff;
203 for (
size_t iCol=0; iCol<columnsOfSegment ;++iCol)
204 *pixel++ = *tileD-- & 0x3fff;
217 template <
typename ConfigType>
221 const int asic_nx(Pds::CsPad::MaxRowsPerASIC);
222 const int asic_ny(Pds::CsPad::ColumnsPerASIC);
223 Pds::CsPad::ElementIterator iter(cfg, *xtc);
224 const Pds::CsPad::ElementHeader* element;
226 const int pixelsPerQuadrant(2*asic_nx*8*asic_ny);
227 const int pixelsPerSegment(2*asic_nx*asic_ny);
229 const int FrameSize(4*pixelsPerQuadrant);
230 det.
frame().resize(FrameSize);
232 while( (element=iter.next() ))
234 const size_t quad(element->quad());
236 const Pds::CsPad::Section* section;
237 unsigned int section_id;
238 while(( section=iter.next(section_id) ))
240 const uint16_t* pixels = section->pixel[0];
241 for (
int ii=0; ii<pixelsPerSegment; ++ii)
251 det.
rows() = 4 * 8 * 185;
265 template <
typename ConfigType>
269 det.
columns() = cfg.numberOfColumns();
270 det.
rows() = cfg.numberOfReadableRows();
271 const char* pData(reinterpret_cast<const char*>(&element)+32);
272 const uint16_t*
data(reinterpret_cast<const uint16_t*>(pData));
275 det.
frame().resize(framesize);
276 copy(data, data+framesize, det.
frame().begin());
301 _pdsTypeList.push_back(TypeId::Id_pnCCDconfig);
302 _pdsTypeList.push_back(TypeId::Id_pnCCDframe);
303 _pdsTypeList.push_back(TypeId::Id_Frame);
304 _pdsTypeList.push_back(TypeId::Id_CspadConfig);
305 _pdsTypeList.push_back(TypeId::Id_CspadElement);
306 _pdsTypeList.push_back(TypeId::Id_Cspad2x2Element);
307 _pdsTypeList.push_back(TypeId::Id_EpixConfig);
308 _pdsTypeList.push_back(TypeId::Id_Epix10kConfig);
309 _pdsTypeList.push_back(TypeId::Id_Epix100aConfig);
310 _pdsTypeList.push_back(TypeId::Id_EpixSConfig);
311 _pdsTypeList.push_back(TypeId::Id_Epix10kaConfig);
312 _pdsTypeList.push_back(TypeId::Id_EpixElement);
319 for (
int i = 0; i <
size; ++i)
322 string type(s.
value(
"TypeName",
"Invalid").toString().toStdString());
323 TypeId::Type typeID(TypeId::NumberOf);
324 for (
int i(0); i < TypeId::NumberOf; ++i)
325 if (TypeId::name(static_cast<TypeId::Type>(i)) == type)
327 typeID =
static_cast<TypeId::Type
>(i);
331 uint32_t detID(s.
value(
"DetectorID",0).toUInt());
332 string detname(s.
value(
"DetectorName",
"Invalid").toString().toStdString());
334 for (
int i(0); i < DetInfo::NumDetector; ++i)
335 if (DetInfo::name(static_cast<DetInfo::Detector>(i)) == detname)
341 uint32_t devID(s.
value(
"DeviceID",0).toUInt());
342 string devname(s.
value(
"DeviceName",
"Invalid").toString().toStdString());
343 DetInfo::Device devnameID(DetInfo::NumDevice);
344 for (
int i(0); i < DetInfo::NumDevice; ++i)
345 if (DetInfo::name(static_cast<DetInfo::Device>(i)) == devname)
347 devnameID =
static_cast<DetInfo::Device
>(i);
352 if (typeID == TypeId::NumberOf ||
353 detnameID == DetInfo::NumDetector ||
354 devnameID == DetInfo::NumDevice)
357 Key key(typeID, detnameID, detID, devnameID, devID);
358 _LCLSToCASSId[key] = s.
value(
"CASSID",0).toInt();
366 TypeId::name(xtc->contains.id()) +
"'(" +
toString(xtc->contains.id()) +
367 "), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->detector()) +
368 "'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->detId()) +
369 "), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->device()) +
370 "'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->devId()) +
374 idmap_t::key_type lclskey(xtc->contains.id(), xtc->src.phy());
375 idmap_t::iterator lclsmapIt(_LCLSToCASSId.find(lclskey));
376 if (lclsmapIt == _LCLSToCASSId.end())
378 Log::add(
Log::DEBUG0,
string(
"pixeldetector::Converter::operator(): There is no corresponding cass key for : '") +
379 TypeId::name(xtc->contains.id()) +
"'(" +
toString(xtc->contains.id()) +
380 "), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->detector()) +
381 "'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->detId()) +
382 "), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->device()) +
383 "'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->devId()) +
387 const idmap_t::mapped_type &casskey(lclsmapIt->second);
390 switch( xtc->contains.id() )
393 case (Pds::TypeId::Id_CspadConfig) :
394 case (Pds::TypeId::Id_Cspad2x2Config) :
395 case (Pds::TypeId::Id_pnCCDconfig) :
396 case (Pds::TypeId::Id_EpixConfig):
397 case (Pds::TypeId::Id_Epix10kConfig):
398 case (Pds::TypeId::Id_Epix100aConfig):
399 case (Pds::TypeId::Id_EpixSConfig):
400 case (Pds::TypeId::Id_Epix10kaConfig):
402 if (xtc->contains.id() == Pds::TypeId::Id_pnCCDconfig && 2 < xtc->contains.version())
403 throw runtime_error(
"pixeldetector::Converter::operator: pnCCD Config version" +
404 toString(xtc->contains.version()) +
"is not supported");
407 switch (xtc->contains.version())
411 const Pds::PNCCD::ConfigV2 &cfg
412 (reinterpret_cast<const Pds::PNCCD::ConfigV2&>(*(xtc->payload())));
413 string out(
string(
"pixeldetector::Converter::operator(): ")
414 + TypeId::name(xtc->contains.id()) +
"'(" +
toString(xtc->contains.id())
415 +
"), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->detector())
416 +
"'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->detId())
417 +
"), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->device())
418 +
"'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->devId())
419 +
"): CASSID '"+
toString(casskey)+
"'"
420 +
"', rows'" +
toString(cfg.numRows())
421 +
"', cols'" +
toString(cfg.numChannels())
422 +
"', info'" + cfg.info()
423 +
"', tfileName'" + cfg.timingFName()
424 +
"', camaxMagic'" +
toString(cfg.camexMagic())
425 +
"', SegRows'" +
toString(cfg.numSubmoduleRows())
426 +
"', SegCols'" +
toString(cfg.numSubmoduleChannels())
436 if (xtc->contains.id() == Pds::TypeId::Id_CspadConfig && 5 < xtc->contains.version())
437 throw runtime_error(
"pixeldetector::Converter::operator: csPad Config version" +
438 toString(xtc->contains.version()) +
"is not supported");
439 if (xtc->contains.id() == Pds::TypeId::Id_Cspad2x2Config && 2 < xtc->contains.version())
440 throw runtime_error(
"pixeldetector::Converter::operator: csPad2x2 Config version" +
441 toString(xtc->contains.version()) +
"is not supported");
442 if (xtc->contains.id() == Pds::TypeId::Id_EpixConfig && 1 < xtc->contains.version())
443 throw runtime_error(
"pixeldetector::Converter::operator: Epix Config version" +
444 toString(xtc->contains.version()) +
"is not supported");
445 if (xtc->contains.id() == Pds::TypeId::Id_Epix10kConfig && 1 < xtc->contains.version())
446 throw runtime_error(
"pixeldetector::Converter::operator: Epix10k Config version" +
447 toString(xtc->contains.version()) +
"is not supported");
448 if (xtc->contains.id() == Pds::TypeId::Id_Epix100aConfig && 2 < xtc->contains.version())
449 throw runtime_error(
"pixeldetector::Converter::operator: Epix100a Config version" +
450 toString(xtc->contains.version()) +
"is not supported");
451 if (xtc->contains.id() == Pds::TypeId::Id_EpixSConfig && 1 < xtc->contains.version())
452 throw runtime_error(
"pixeldetector::Converter::operator: EpixS Config version" +
453 toString(xtc->contains.version()) +
"is not supported");
454 if (xtc->contains.id() == Pds::TypeId::Id_Epix10kaConfig && 1 < xtc->contains.version())
455 throw runtime_error(
"pixeldetector::Converter::operator: EpixS Config version" +
456 toString(xtc->contains.version()) +
"is not supported");
457 _configStore[casskey] = make_pair(xtc->contains.value(),
extractPayload(xtc));
462 case (Pds::TypeId::Id_EpixElement) :
465 if (xtc->contains.version() != 3)
468 "Version '" +
toString(xtc->contains.version()) +
469 "' of EpixElement is not yet supported");
472 const Pds::Epix::ElementV3& element
473 (reinterpret_cast<const Pds::Epix::ElementV3&>(*(xtc->payload())));
476 configStore_t::const_iterator storeIt(_configStore.find(casskey));
477 if(storeIt == _configStore.end())
479 Log::add(
Log::ERROR,
string(
"pixeldetector::Converter::operator(): No configuration to read the data of '") +
480 TypeId::name(xtc->contains.id()) +
"'(" +
toString(xtc->contains.id()) +
481 "), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->detector()) +
482 "'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->detId()) +
483 "), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->device()) +
484 "'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->devId()) +
488 const config_t config(storeIt->second);
489 const TypeId& configId(reinterpret_cast<const TypeId&>(config.first));
490 if (configId.value() != config.first)
491 throw logic_error(
"we've to implment the conversion from value to typeid differntly");
493 det.
id() = evt->
id();
495 switch (configId.id())
497 case (TypeId::Id_EpixConfig):
499 const Pds::Epix::ConfigV1 &cfg
500 (reinterpret_cast<const Pds::Epix::ConfigV1&>(config.second.front()));
505 case (TypeId::Id_Epix100aConfig):
507 switch (configId.version())
511 const Pds::Epix::Config100aV1 &cfg
512 (reinterpret_cast<const Pds::Epix::Config100aV1&>(config.second.front()));
519 const Pds::Epix::Config100aV2 &cfg
520 (reinterpret_cast<const Pds::Epix::Config100aV2&>(config.second.front()));
526 throw runtime_error(
"LCLSConverter: Unknown epix100aconfig version '" +
527 toString(configId.version()) +
"'");
534 throw runtime_error(
"LCLSConverter: Unknown epix configuration typeid '" +
540 case (Pds::TypeId::Id_pnCCDframe) :
542 configStore_t::const_iterator storeIt(_configStore.find(casskey));
543 if(storeIt == _configStore.end())
545 Log::add(
Log::ERROR,
string(
"pixeldetector::Converter::operator(): No configuration to read the data of '") +
546 TypeId::name(xtc->contains.id()) +
"'(" +
toString(xtc->contains.id()) +
547 "), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->detector()) +
548 "'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->detId()) +
549 "), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->device()) +
550 "'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->devId()) +
554 const config_t config(storeIt->second);
555 const TypeId& configId(reinterpret_cast<const TypeId&>(config.first));
557 det.
id() = evt->
id();
558 switch (configId.version())
562 const Pds::PNCCD::ConfigV1 &cfg
563 (reinterpret_cast<const Pds::PNCCD::ConfigV1&>(config.second.front()));
570 const Pds::PNCCD::ConfigV2 &cfg
571 (reinterpret_cast<const Pds::PNCCD::ConfigV2&>(config.second.front()));
577 throw runtime_error(
"LCLSConverter: Unknown PnCCD Version '" +
583 case (Pds::TypeId::Id_CspadElement) :
586 configStore_t::const_iterator storeIt(_configStore.find(casskey));
587 if(storeIt == _configStore.end())
589 Log::add(
Log::ERROR,
string(
"pixeldetector::Converter::operator(): No configuration to read the data of '") +
590 TypeId::name(xtc->contains.id()) +
"'(" +
toString(xtc->contains.id()) +
591 "), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->detector()) +
592 "'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->detId()) +
593 "), '" + DetInfo::name(reinterpret_cast<const DetInfo*>(&xtc->src)->device()) +
594 "'(" +
toString(reinterpret_cast<const DetInfo*>(&xtc->src)->devId()) +
598 const config_t config(storeIt->second);
599 const TypeId& configId(reinterpret_cast<const TypeId&>(config.first));
601 det.
id() = evt->
id();
602 switch (configId.version())
606 const Pds::CsPad::ConfigV1 &cfg
607 (reinterpret_cast<const Pds::CsPad::ConfigV1&>(config.second.front()));
614 const Pds::CsPad::ConfigV2 &cfg
615 (reinterpret_cast<const Pds::CsPad::ConfigV2&>(config.second.front()));
622 const Pds::CsPad::ConfigV3 &cfg
623 (reinterpret_cast<const Pds::CsPad::ConfigV3&>(config.second.front()));
630 const Pds::CsPad::ConfigV4 &cfg
631 (reinterpret_cast<const Pds::CsPad::ConfigV4&>(config.second.front()));
638 const Pds::CsPad::ConfigV5 &cfg
639 (reinterpret_cast<const Pds::CsPad::ConfigV5&>(config.second.front()));
645 throw runtime_error(
"LCLSConverter: Unknown CsPad Configuration Version '" +
653 case (Pds::TypeId::Id_Cspad2x2Element):
656 det.
id() = evt->
id();
657 const int asic_nx(Pds::CsPad::MaxRowsPerASIC);
658 const int asic_ny(Pds::CsPad::ColumnsPerASIC);
659 Pds::CsPad2x2::ElementHeader* head
660 (reinterpret_cast<Pds::CsPad2x2::ElementHeader*>(xtc->payload()));
661 const int pixelsPerSegment(2*asic_nx*asic_ny);
662 const int framesize(2*pixelsPerSegment);
663 det.
frame().resize(framesize);
664 uint16_t*
data =
reinterpret_cast<uint16_t*
>(head+1);
665 uint16_t* End = data + framesize;
666 Detector::frame_t::iterator firstSegment(det.
frame().begin());
667 Detector::frame_t::iterator secondSegment(det.
frame().begin() + pixelsPerSegment);
670 *firstSegment++ = *data++;
671 *secondSegment++ = *data++;
674 det.
rows() = 2 * 185;
678 case (Pds::TypeId::Id_Frame) :
681 det.
id() = evt->
id();
682 const Camera::FrameV1 &frame
683 (*reinterpret_cast<const Camera::FrameV1*>(xtc->payload()));
685 det.
rows() = frame.height();
686 const uint16_t* framedata (reinterpret_cast<const uint16_t*>(frame.data()));
687 const size_t framesize(frame.width()*frame.height());
688 det.
frame().resize(framesize);
689 transform(framedata,framedata + framesize,
691 bind2nd(minus<float>(),static_cast<float>(frame.offset())));
692 fill(det.
frame().begin(),det.
frame().begin()+8,*(det.
frame().begin()+9));
definition of front detector[PixelDetectors] FrontPnCCD Detector
Event to store all LCLS Data.
std::pair< uint32_t, std::vector< uint8_t > > config_t
pair the typeid of the config with a shared pointer of the config
std::string & info()
setter
file contains declaration of the CASSEvent
detectors_t & dets()
instrument setter
void copyCsPadFrame(const Pds::Xtc *xtc, const ConfigType &cfg, Detector &det)
copy the cspad frame to the detector
void copyPnCCDFrame(const Pds::Xtc *xtc, const ConfigType &cfg, Detector &det)
copy the pnCCD frame into the detector
things written only at end of run H5Dump ProcessorSummary size
uint16_t & columns()
setter
Detector & retrieveDet(CASSEvent &evt, const Device::detectors_t::key_type &key)
extract the right detector from the CASSEvent
static void add(Level level, const std::string &line)
add a string to the log
float pixel_t
define a pixel of the pixel detector
static QMutex _mutex
singleton locker for mutithreaded requests
void copyEpixFrame(const Pds::Epix::ElementV3 &element, const ConfigType &cfg, Detector &det)
copy the epix frame to the detector
beginReadArray(const QString &prefix)
vector< uint8_t > extractPayload(const Pds::Xtc *xtc)
copy payload of xtc into a bytearray
void operator()(const Pds::Xtc *xtc, cass::CASSEvent *evt)
operator to convert the LCLS Data to CASSEvent
devices_t & devices()
setters
std::string & timingFilename()
setter
static ConversionBackend::shared_pointer _instance
the singleton container
void copyAdditionalPnccdInfo(const Pds::PNCCD::ConfigV1 &, Detector &det, size_t &rowsOfSegment, size_t &columnsOfSegment)
copy additional info about the pnCCD
std::string toString(const Type &t)
convert any type to a string
uint32_t & camaxMagic()
setter
auxiliary data[Processor]
std::tr1::shared_ptr< ConversionBackend > shared_pointer
typedef
value(const QString &key, const QVariant &defaultValue=QVariant()
std::map< Device, DeviceBackend::shared_pointer > devices_t
mapping from device type to handler instance
Converter for pnCCD, CsPad and commercial CCD Data.
contains container for simple pixel detector data
file contains specialized class that do the settings for cass
the device containing pixel detector data
Detector containing a ccd camera image.
static ConversionBackend::shared_pointer instance()
create singleton if doesnt exist already
contains the converters to convert ccd and pnccd data to CASSEvent
contains a logger for cass
int16_t pixel
define a pixel
beginGroup(const QString &prefix)