11#ifndef FRAMEWORK_UTILS_DPLRAWPARSER_H
12#define FRAMEWORK_UTILS_DPLRAWPARSER_H
66template <
bool BOUNDS_CHECKS = true>
74 DPLRawParser(
InputRecord& inputs, std::vector<InputSpec> filterSpecs = {}, fair::Severity sev = fair::Severity::alarm) : mInputs(inputs), mFilterSpecs(filterSpecs), mSeverity(sev) {}
108 : mParent(parent), mInputIterator(it), mEnd(
end), mPartIterator(mInputIterator.
begin()), mParser(
std::make_unique<
parser_type>(reinterpret_cast<const
char*>(&
initializer), sizeof(
initializer))), mCurrent(mParser->
begin()), mFilterSpecs(filterSpecs), mMaxFailureMessages(maxErrMsg), mExtFailureCounter(cntErrMsg), mSeverity(sev)
137 bool result = mInputIterator ==
other.mInputIterator;
139 if (mParser !=
nullptr &&
other.mParser !=
nullptr) {
153 if (mInputIterator != mEnd) {
154 return DataRefUtils::getHeader<o2::header::DataHeader*>(*mPartIterator);
162 if (mInputIterator != mEnd) {
163 return DataRefUtils::getHeader<o2::framework::DataProcessingHeader*>(*mPartIterator);
171 return mCurrent.raw();
177 return mCurrent.data();
183 return mCurrent.offset();
189 return mCurrent.size();
195 return mCurrent.sizeTotal();
200 template <
typename U>
203 return mCurrent.template get_if<U>();
208 if (it.mInputIterator != it.mEnd && it.mPartIterator != it.mInputIterator.end() && it.mParser !=
nullptr) {
215 template <raw_parser::FormatSpec FmtCtrl>
222 template <raw_parser::FormatSpec FmtCtrl>
225 auto const& it =
fmt.it;
226 if (it.mInputIterator != it.mEnd && it.mPartIterator != it.mInputIterator.end() && it.mParser !=
nullptr) {
240 using part_iterator =
typename input_iterator::const_iterator;
242 using parser_iterator =
typename parser_type::const_iterator;
246 auto logFailure = [
this](
const std::string&
msg,
const std::runtime_error& e) {
247 if (!this->mExtFailureCounter || (*this->mExtFailureCounter)++ < this->mMaxFailureMessages) {
248 if (this->mSeverity == fair::Severity::alarm) {
249 LOG(alarm) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
250 }
else if (this->mSeverity == fair::Severity::warn) {
251 LOG(warn) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
252 }
else if (this->mSeverity == fair::Severity::fatal) {
253 LOG(fatal) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
254 }
else if (this->mSeverity == fair::Severity::critical) {
255 LOG(critical) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
256 }
else if (this->mSeverity == fair::Severity::error) {
257 LOG(error) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
258 }
else if (this->mSeverity == fair::Severity::info) {
259 LOG(info) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
261 LOG(
debug) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
266 while (mInputIterator != mEnd) {
267 bool isInitial = mParser ==
nullptr;
268 while (mPartIterator != mInputIterator.end()) {
270 if (mParser && mCurrent != mParser->end() && ++mCurrent != mParser->end()) {
276 if (!isInitial && (mPartIterator == mInputIterator.end() || ++mPartIterator == mInputIterator.end())) {
282 if (mFilterSpecs.size() > 0) {
284 for (
auto const& spec : mFilterSpecs) {
293 gsl::span<const char>
raw;
295 raw = mParent.
get<gsl::span<char>>(*mPartIterator);
296 }
catch (
const std::runtime_error& e) {
297 logFailure(
"failed to read data from ", e);
299 if (
raw.size() == 0) {
304 mParser = std::make_unique<parser_type>(
raw.data(),
raw.size());
305 }
catch (
const std::runtime_error& e) {
306 logFailure(
"can not create raw parser from ", e);
309 if (mParser !=
nullptr) {
310 mCurrent = mParser->begin();
315 mPartIterator = mInputIterator.begin();
320 InputRecord& mParent;
323 part_iterator mPartIterator;
324 std::unique_ptr<parser_type> mParser;
325 parser_iterator mCurrent;
326 std::vector<InputSpec>
const& mFilterSpecs;
327 size_t mMaxFailureMessages = -1;
328 size_t* mExtFailureCounter =
nullptr;
329 fair::Severity mSeverity = fair::Severity::alarm;
336 return const_iterator(mInputs, mInputs.
begin(), mInputs.
end(), mFilterSpecs, mSeverity, mMaxFailureMessages, mExtFailureCounter);
341 return const_iterator(mInputs, mInputs.
end(), mInputs.
end(), mFilterSpecs, mSeverity, mMaxFailureMessages, mExtFailureCounter);
350 std::vector<InputSpec> mFilterSpecs;
351 size_t mMaxFailureMessages = -1;
352 size_t* mExtFailureCounter =
nullptr;
353 fair::Severity mSeverity = fair::Severity::alarm;
Generic parser for consecutive raw pages.
self_type operator++(int)
decltype(std::declval< InputRecord >().begin()) input_iterator
std::forward_iterator_tag iterator_category
o2::header::DataHeader const * o2DataHeader() const
get DataHeader of the current input message
size_t sizeTotal() const
get size of header + payload at current position
buffer_type const * raw() const
get pointer to raw block at current position, rdh starts here
friend std::ostream & operator<<(std::ostream &os, self_type const &it)
bool operator!=(const self_type &rh) const
buffer_type const * data() const
get pointer to payload at current position
o2::framework::DataProcessingHeader const * o2DataProcessingHeader() const
get DataProcessingHeader of the current input message
size_t offset() const
offset of payload at current position
Iterator(InputRecord &parent, input_iterator it, input_iterator end, std::vector< InputSpec > const &filterSpecs, fair::Severity sev=fair::Severity::alarm, size_t maxErrMsg=-1, size_t *cntErrMsg=nullptr)
rawparser_type const parser_type
size_t size() const
get size of payload at current position
friend std::ostream & operator<<(std::ostream &os, Fmt< FmtCtrl > const &fmt)
bool operator==(const self_type &other) const
The parser handles transparently input in the format of raw pages.
static constexpr o2::header::RAWDataHeader initializer
const_iterator end() const
Iterator< DataRef const > const_iterator
static void setErrorMode(int v)
static void setCheckIncompleteHBF(bool v)
typename rawparser_type::buffer_type buffer_type
void setMaxFailureMessages(size_t n)
typename o2::framework::DPLRawParser< BOUNDS_CHECKS >::const_iterator::template Fmt< raw_parser::FormatSpec::Info > RDHInfo
void setExtFailureCounter(size_t *cnt)
DPLRawParser(InputRecord &inputs, std::vector< InputSpec > filterSpecs={}, fair::Severity sev=fair::Severity::alarm)
const_iterator begin() const
unsigned char buffer_type
static void setCheckIncompleteHBF(bool v)
static void setErrorMode(int v)
FormatSpec
specifier for printout
Defining PrimaryVertex explicitly as messageable.
bool isSelected(const ExtendedTrack &track)
Defining DataPointCompositeObject explicitly as copiable.
Fmt(self_type const &_it)
static constexpr raw_parser::FormatSpec format_control
static bool match(DataRef const &ref, const char *binding)
VectorOfTObjectPtrs other
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
uint64_t const void const *restrict const msg