14 #include <tr1/functional>
16 #include <QtCore/QFileInfo>
150 const uint64_t &eventId,
151 pixeldetector::Detector::frame_t::iterator dframe,
152 pixeldetector::Detector::frame_t::iterator gframe,
153 pixeldetector::Detector::frame_t::iterator mframe,
157 map<uint64_t,size_t>::const_iterator idxIt(tile.
idToIdx.find(eventId));
158 if (idxIt == tile.
idToIdx.end())
168 advance(dTileBegin,tile.
size*idxIt->second);
169 auto dTileEnd(dTileBegin);
170 advance(dTileEnd,tile.
size);
172 auto dTileInFrame(dframe+tile.
id*tile.
size);
173 copy(dTileBegin,dTileEnd,dTileInFrame);
177 advance(gTileBegin,tile.
size*idxIt->second);
178 auto gTileEnd(gTileBegin);
179 advance(gTileEnd,tile.
size);
181 auto gTileInFrame(gframe+tile.
id*tile.
size);
182 copy(gTileBegin,gTileEnd,gTileInFrame);
186 advance(mTileBegin,tile.
size*idxIt->second);
187 auto mTileEnd(mTileBegin);
188 advance(mTileEnd,tile.
size);
190 auto mTileInFrame(mframe+tile.
id*tile.
size);
191 copy(mTileBegin,mTileEnd,mTileInFrame);
199 part.
dims.push_back(1);
204 part.
offset[0] = idxIt->second;
211 pixeldetector::Detector::frame_t::iterator dTileInFrame(dframe+tile.
id*tile.
size);
212 pixeldetector::Detector::frame_t::iterator gTileInFrame(gframe+tile.
id*tile.
size);
213 pixeldetector::Detector::frame_t::iterator mTileInFrame(mframe+tile.
id*tile.
size);
216 tile.
fh->readPartialMultiDim<
float>(dTileInFrame,part,tile.
dataDsetName);
217 tile.
fh->readPartialMultiDim<
float>(gTileInFrame,part,tile.
gainDsetName);
218 tile.
fh->readPartialMultiDim<
float>(mTileInFrame,part,tile.
maskDsetName);
224 void XFELHDF5FileInput::instance(
string filelistname,
231 throw logic_error(
"HDF5FileInput::instance(): The instance of the base class is already initialized");
235 XFELHDF5FileInput::XFELHDF5FileInput(
string filelistname,
240 :
InputBase(ringbuffer,ratemeter,loadmeter,parent),
241 _quitWhenDone(quitWhenDone),
242 _filelistname(filelistname),
259 const bool precache(s.
value(
"PreCacheData",
true).toBool());
260 const size_t maxPulseId(s.
value(
"MaxPulseId",65).toUInt());
266 int DataCASSID(s.
value(
"DataCASSID",30).toInt());
267 int MaskCASSID(s.
value(
"MaskCASSID",31).toInt());
268 int GainCASSID(s.
value(
"GainCASSID",32).toInt());
271 vector<AGIPDTile> agiptiles;
273 for (
int i = 0; i <
size; ++i)
278 const int tileid(s.
value(
"Id",-1).toInt());
283 const string fn(s.
value(
"HDF5FileName",
"Invalid").toString().toStdString());
292 tile.
fh->open(fn,
"r");
297 tile.
fh->open(fn,
"r",128);
300 catch (
const std::invalid_argument & error)
302 Log::add(
Log::ERROR,
string(error.what()) +
": File '"+fn+
"' doesn't exist; ignoring it");
333 "' to list of tiles to be processed");
334 agiptiles.push_back(tile);
342 vector<MachineInfo> machinevalues;
344 for (
int i = 0; i <
size; ++i)
351 const string fn(s.
value(
"HDF5FileName",
"Invalid").toString().toStdString());
360 catch (
const std::invalid_argument & error)
362 Log::add(
Log::ERROR,
string(error.what()) +
": File '"+fn+
"' doesn't exist; ignoring it");
367 mi.
cassname = s.
value(
"CASSName",
"Invalid").toString().toStdString();
383 machinevalues.push_back(mi);
402 #pragma omp parallel for num_threads(agiptiles.size())
405 for (
size_t i = 0; i<agiptiles.size(); ++i)
407 auto &tile(agiptiles[i]);
411 tile.fh->readMultiDim<uint64_t>(tile.trainIds,shape,tile.trainIdDsetName);
412 vector<uint64_t> pulseIds;
413 tile.fh->readMultiDim<uint64_t>(pulseIds,shape,tile.cellIdDsetName);
415 if (pulseIds.size() != tile.trainIds.size())
416 cout <<
"BAD!!"<<endl;
417 for (
size_t i(0); i<pulseIds.size(); ++i)
419 const uint64_t trainId(tile.trainIds[i]);
420 const uint64_t pulseId(pulseIds[i]);
421 const uint64_t id(((trainId & 0x0000FFFFFFFFFFFF)<<16) +
422 (pulseId & 0x000000000000FFFF));
423 tile.idToIdx[id] = i;
431 tile.fh->readMultiDim<AGIPDTile::corImage_t::value_type>(tile.dataCache,shape,tile.dataDsetName);
432 tile.fh->readMultiDim<AGIPDTile::mask_t::value_type>(tile.maskCache,shape,tile.maskDsetName);
433 tile.fh->readMultiDim<AGIPDTile::gain_t::value_type>(tile.gainCache,shape,tile.gainDsetName);
440 for (
auto &mv : machinevalues)
443 mv.cassname +
"' and precache the data");
445 vector<uint64_t> trainIds;
446 mv.fh->readMultiDim<uint64_t>(trainIds,shape,mv.trainIdDsetName);
447 for (
size_t i(0); i<trainIds.size(); ++i)
448 mv.idxToTrainId[trainIds[i]] = i;
453 mv.fh->readMultiDim<
float>(mv.cache,mv.shape,mv.hdf5DsetName);
458 std::set<uint64_t> trainIds;
459 for (
const auto &tile : agiptiles)
461 for (
const auto &trainId : tile.trainIds)
463 trainIds.emplace(trainId);
468 toString(trainIds.size()) +
"' long");
473 for (
const auto &trainId : trainIds)
483 for (
size_t pulseId(0); pulseId<maxPulseId; ++pulseId)
500 evt.
id() = (((trainId & 0x0000FFFFFFFFFFFF)<<16) +
501 (pulseId & 0x000000000000FFFF));
505 CASSEvent::devices_t::iterator devIt;
508 if(devIt == devices.end())
509 throw runtime_error(
string(
"xfelhdf5fileinput: CASSEvent does not") +
510 " contain a pixeldetector device");
514 const size_t nRows(512);
515 const size_t nCols(128);
516 const size_t nTiles(16);
520 data.columns() = nCols;
521 data.rows() = nRows*nTiles;
524 dataframe.resize(nRows*nCols*nTiles,0);
528 mask.columns() = nCols;
529 mask.rows() = nRows*nTiles;
532 maskframe.resize(nRows*nCols*nTiles,0);
535 gain.
id() = evt.
id();
536 gain.columns() = nCols;
537 gain.rows() = nRows*nTiles;
540 gainframe.resize(nRows*nCols*nTiles,0);
545 for_each(agiptiles.begin(),agiptiles.end(),
558 if(devIt == devices.end())
559 throw runtime_error(
string(
"xfelhdf5fileinput: CASSEvent does not") +
560 " contain a machinedata device");
565 for (
const auto& mv : machinevalues)
568 map<uint64_t,size_t>::const_iterator idxIt(mv.idxToTrainId.find(trainId));
569 if (idxIt == mv.idxToTrainId.end())
573 auto mBegin(mv.cache.begin());
574 advance(mBegin, pulseId + idxIt->second*mv.shape[1]);
580 part.
dims.push_back(1);
581 part.
dims.push_back(1);
584 part.
offset[0] = idxIt->second;
591 vector<float> mval(1,0);
592 mv.fh->readPartialMultiDim<
float>(mval.begin(), part, mv.hdf5DsetName);
std::string cellIdDsetName
name of the cell id dataset in the hdf5 file
hdf5::shape_t shape
shape of the cached data
Event to store all LCLS Data.
vector< float > cache
cache to store the data in
class calculating a rate in Hz.
sleep(unsigned long secs)
std::vector< hsize_t > count
the count
vector< uint8_t > gain_t
define the type of the gain data
status_t _status
the internal status of the thread
vector< uint64_t > trainIds
container for the train ids
file contains declaration of the CASSEvent
detectors_t & dets()
instrument setter
size_t nCols
the number of columns of the tile
std::string hdf5DsetName
name of the machine dataset in the hdf5 file
std::string pulseIdDsetName
name of the pulse id dataset in the hdf5 file
tr1::shared_ptr< hdf5::Handler > h5handle_t
define a pointer to the handler
things written only at end of run H5Dump ProcessorSummary size
std::string gainDsetName
name of the mask dataset in the hdf5 file
std::string maskDsetName
name of the mask dataset in the hdf5 file
tr1::shared_ptr< hdf5::Handler > h5handle_t
define a pointer to the handler
std::string trainIdDsetName
name of the train id dataset in the hdf5 file
std::string trainIdDsetName
name of the train id dataset in the hdf5 file
static void add(Level level, const std::string &line)
add a string to the log
void tileToFrames(const AGIPDTile &tile, const uint64_t &eventId, pixeldetector::Detector::frame_t::iterator dframe, pixeldetector::Detector::frame_t::iterator gframe, pixeldetector::Detector::frame_t::iterator mframe, const bool precache)
get the tile from the hdf5 file and copy it to the correct position in the frame
std::string cassname
name of the machineData within the CASSEvent
std::vector< hsize_t > offset
the offset of the partial data within the original data
h5handle_t fh
handler to the file containing the tile data
beginReadArray(const QString &prefix)
Container for all Machine related Data.
std::vector< hsize_t > shape_t
define the shape type
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
define the partiality parameter container
mask_t maskCache
container for the mask data
bool shouldQuit() const
query whether this thread is told to quit
file contains the declaration of the acqiris part of the CASSEvent
a struct combining the information needed to get machine values
std::vector< hsize_t > block
the block
std::vector< hsize_t > stride
the stride
std::string toString(const Type &t)
convert any type to a string
auxiliary data[Processor]
size_t nRows
the number of rows of the tile
value(const QString &key, const QVariant &defaultValue=QVariant()
std::map< Device, DeviceBackend::shared_pointer > devices_t
mapping from device type to handler instance
vector< float > corImage_t
define the type of the raw image
std::vector< hsize_t > dims
the dimensions of the partial dataset
noise and mask[Processor]
h5handle_t fh
handler to the file containing the tile data
contains container for simple pixel detector data
definitions of a machine device
std::string dataDsetName
name of the data dataset in the hdf5 file
file contains specialized class that do the settings for cass
size_t size
the datasize of the data tile
the device containing pixel detector data
vector< uint8_t > mask_t
define the type of the mask data
Detector containing a ccd camera image.
map< uint64_t, size_t > idxToTrainId
map the uinque id to an index within the array
corImage_t dataCache
container for the corrrected image data
vector< uint16_t > rawImage_t
define the type of the raw image
contains a logger for cass
int16_t pixel
define a pixel
easier api for hdf5 file writing
gain_t gainCache
container for the gains settings data
map< uint64_t, size_t > idToIdx
map the uinque id to an index within the array
const bldMap_t & BeamlineData() const
getter
beginGroup(const QString &prefix)
uint32_t id
id of the tile