16 #include <QtCore/QFileInfo>
55 void HDF5FileInput::instance(
string filelistname,
62 throw logic_error(
"HDF5FileInput::instance(): The instance of the base class is already initialized");
66 HDF5FileInput::HDF5FileInput(
string filelistname,
71 :
InputBase(ringbuffer,ratemeter,loadmeter,parent),
72 _quitWhenDone(quitWhenDone),
73 _filelistname(filelistname)
89 string EventIDName = s.
value(
"EventIDKey",
"EventID").toString().toStdString();
92 typedef vector<machineVal> machineVals_t;
93 machineVals_t machineVals;
95 for (
int i = 0; i <
size; ++i)
98 string machineValName(s.
value(
"HDF5Key",
"Invalid").toString().toStdString());
99 string CASSName(s.
value(
"CASSName",
"Invalid").toString().toStdString());
101 if (machineValName ==
"Invalid")
103 CASSName = CASSName ==
"Invalid" ? machineValName : CASSName;
104 machineVals.push_back(machineVals_t::value_type());
105 machineVals.back().h5key = machineValName;
106 machineVals.back().cassname = CASSName;
107 machineVals.back().idx = s.
value(
"ArrayIndex",0).toUInt();
112 typedef vector<AcqirisParams> acqirisVals_t;
113 acqirisVals_t acqirisVals;
115 for (
int i = 0; i <
size; ++i)
118 string datakey= s.
value(
"HDF5DataKey",
"Invalid").toString().toStdString();
120 if (datakey ==
"Invalid")
123 acqirisVals.back().Instrument = s.
value(
"CASSInstrumentID",1).toUInt();
124 acqirisVals.back().ChannelNumber = s.
value(
"CASSChannelNumber",0).toUInt();
125 acqirisVals.back().DataKey = datakey;
126 acqirisVals.back().HorposKey = s.
value(
"HDF5HorposKey",
"Invalid").toString().toStdString();
127 acqirisVals.back().VertOffsetKey = s.
value(
"HDF5VerticalOffsetKey",
"Invalid").toString().toStdString();
128 acqirisVals.back().GainKey = s.
value(
"HDF5GainKey",
"Invalid").toString().toStdString();
129 acqirisVals.back().SampleIntervalKey = s.
value(
"HDF5SampleIntervalKey",
"Invalid").toString().toStdString();
134 typedef vector<PixeldetectorParams> pixdetVals_t;
135 pixdetVals_t pixdetVals;
137 for (
int i = 0; i <
size; ++i)
140 string datakey= s.
value(
"HDF5DataKey",
"Invalid").toString().toStdString();
142 if (datakey ==
"Invalid")
145 pixdetVals.back().DataKey = datakey;
146 pixdetVals.back().CASSID = s.
value(
"CASSID",0).toInt();
159 if (!filelistfile.is_open())
160 throw invalid_argument(
"HDF5FileInput::run(): filelist '" +
_filelistname +
161 "' could not be opened");
162 vector<string> filelist(tokenize(filelistfile));
163 filelistfile.close();
168 vector<string>::const_iterator filelistIt(filelist.begin());
169 vector<string>::const_iterator filelistEnd(filelist.end());
171 for (;(!
shouldQuit()) && (filelistIt != filelistEnd); ++filelistIt)
174 string filename(*filelistIt);
187 list<string>::const_iterator it(events.begin());
188 list<string>::const_iterator EventsEnd(events.end());
189 for (; (!
shouldQuit()) && (it != EventsEnd); ++it)
206 if (h5handle.
dimension(*it +
"/" + EventIDName) != 0)
207 throw invalid_argument(
"HDF5FileInput:run(): EventID from '"+
208 *it +
"/" + EventIDName +
"' is not a scalar number");
209 evt.
id() = h5handle.
readScalar<
int>(*it +
"/" + EventIDName);
218 CASSEvent::devices_t::iterator devIt;
229 if (devIt == devices.end())
230 throw runtime_error(
"HDF5FileInput():The CASSEvent does not contain a Machine Data Device");
235 machineVals_t::const_iterator machineValsIter(machineVals.begin());
236 machineVals_t::const_iterator machineValsEnd(machineVals.end());
237 for (; machineValsIter != machineValsEnd; ++machineValsIter)
239 const string key(*it +
"/" + machineValsIter->h5key);
243 float machineValue(h5handle.
readScalar<
float>(key));
244 md.
BeamlineData()[machineValsIter->cassname] = machineValue;
248 vector<double> array;
251 md.
BeamlineData()[machineValsIter->cassname] = array[machineValsIter->idx];
255 throw runtime_error(
"HDF5FileInput(): file '"+ filename +
"': key '" +
256 key +
"' is neither a scalar nor an array value");
265 if (devIt == devices.end())
266 throw runtime_error(
"HDF5FileInput():The CASSEvent does not contain a Acqiris Device");
267 ACQIRIS::Device &acq (dynamic_cast<ACQIRIS::Device&>(*(devIt->second)));
269 acqirisVals_t::const_iterator acqirisValsIter(acqirisVals.begin());
270 acqirisVals_t::const_iterator acqirisValsEnd(acqirisVals.end());
271 for (; acqirisValsIter != acqirisValsEnd; ++acqirisValsIter)
278 channels.resize(acqirisValsIter->ChannelNumber + 1);
284 chan.
channelNbr() = acqirisValsIter->ChannelNumber;
285 chan.
horpos() = (acqirisValsIter->HorposKey ==
"Invalid") ? 0 : h5handle.
readScalar<
double>(*it +
"/" + acqirisValsIter->HorposKey);
286 chan.
offset() = (acqirisValsIter->VertOffsetKey ==
"Invalid") ? 0 : h5handle.
readScalar<
double>(*it +
"/" + acqirisValsIter->VertOffsetKey);
287 chan.
gain() = (acqirisValsIter->GainKey ==
"Invalid") ? 1 : h5handle.
readScalar<
double>(*it +
"/" + acqirisValsIter->GainKey);
288 chan.
sampleInterval() = (acqirisValsIter->SampleIntervalKey ==
"Invalid") ? 1e-9 : h5handle.
readScalar<
double>(*it +
"/" + acqirisValsIter->SampleIntervalKey);
290 const string dkey(*it +
"/" + acqirisValsIter->DataKey);
296 waveform.resize(length);
300 pair<size_t,size_t> shape;
302 if (shape.second != 1)
303 throw invalid_argument(
"HDF5FileInput: file '" + filename +
304 "': acqiris data key '" + dkey +
305 "' is a matrix of '" +
toString(shape.first) +
306 "x" +
toString(shape.second) +
"'");
307 waveform.resize(shape.first*shape.second);
311 throw invalid_argument(
"HDF5FileInput: file '" + filename +
312 "': acqiris data key '" + dkey +
313 "' is not an array. It has dimension '" +
316 copy(array.begin(),array.end(),waveform.begin());
317 instr.id() = evt.
id();
325 if(devIt == devices.end())
326 throw runtime_error(
"HDF5FileInput: CASSEvent does not contains a pixeldetector device");
329 pixdetVals_t::const_iterator pixdetValsIter(pixdetVals.begin());
330 pixdetVals_t::const_iterator pixdetValsEnd(pixdetVals.end());
331 for(; pixdetValsIter != pixdetValsEnd; ++pixdetValsIter)
337 string dkey(*it +
"/" + pixdetValsIter->DataKey);
339 throw invalid_argument(
"HDF5FileInput: file '" + filename +
340 "': pixeldetector data key '" + dkey +
341 "' is not a matrix. It has dimension '" +
343 pair<size_t,size_t> shape;
344 h5handle.
readMatrix(det.frame(), shape, dkey);
346 det.columns() = shape.first;
347 det.rows() = shape.second;
355 "' is missing data. Error is '" + error.what() +
"'");
364 toString(rbItem->element->id()) +
"' is bad: skipping Event");
367 rbItem->element->setFilename(filename.c_str());
std::vector< int16_t > waveform_t
define the waveform
Event to store all LCLS Data.
void readArray(std::vector< type > &array, size_t &arrayLength, const std::string &valname)
read a array with a given name into a linearized array
string h5key
the hdf5 file key
waveform_t & waveform()
setter
class calculating a rate in Hz.
sleep(unsigned long secs)
status_t _status
the internal status of the thread
file contains declaration of the CASSEvent
detectors_t & dets()
instrument setter
type readScalar(const std::string &valname)
read an scalar value with a given name as part of a given group
double & sampleInterval()
setter
things written only at end of run H5Dump ProcessorSummary size
void readMatrix(std::vector< type > &matrix, std::pair< size_t, size_t > &shape, const std::string &valname)
read a matrix with a given name into a linearized array
static void add(Level level, const std::string &line)
add a string to the log
fromStdString(const std::string &str)
Exception thrown when there is an error with the dataset.
beginReadArray(const QString &prefix)
Container for all Machine related Data.
A Ringbuffer, handles communication between Input and Worker Threads.
devices_t & devices()
setters
size_t dimension(const std::string &valname) const
get the dimension of a value with a given name
bool shouldQuit() const
query whether this thread is told to quit
file contains the declaration of the acqiris part of the CASSEvent
tokenize to return all lines of an ascii file in a vector
std::string toString(const Type &t)
convert any type to a string
value(const QString &key, const QVariant &defaultValue=QVariant()
std::map< Device, DeviceBackend::shared_pointer > devices_t
mapping from device type to handler instance
A Channel of an Acqiris Instrument.
dsetList_t rootGroups() const
get the list of groups of the root group in the file
string cassname
the name of the key within the cass event
contains container for simple pixel detector data
definitions of a machine device
std::vector< Channel > channels_t
a vector of Channels
file contains specialized class that do the settings for cass
the device containing pixel detector data
Detector containing a ccd camera image.
size_t & channelNbr()
setter
contains a logger for cass
easier api for hdf5 file writing
const bldMap_t & BeamlineData() const
getter
beginGroup(const QString &prefix)
instruments_t & instruments()
instrument setter
int idx
in case the machinval in question is contained within an array this is the inxed of the array where t...