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), mCurrentRange(it.parts()), mPartIterator(mCurrentRange.
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)
135 bool result = mInputIterator ==
other.mInputIterator;
137 if (mParser !=
nullptr &&
other.mParser !=
nullptr) {
151 if (mInputIterator != mEnd) {
152 return DataRefUtils::getHeader<o2::header::DataHeader*>(*mPartIterator);
160 if (mInputIterator != mEnd) {
161 return DataRefUtils::getHeader<o2::framework::DataProcessingHeader*>(*mPartIterator);
169 return mCurrent.raw();
175 return mCurrent.data();
181 return mCurrent.offset();
187 return mCurrent.size();
193 return mCurrent.sizeTotal();
198 template <
typename U>
201 return mCurrent.template get_if<U>();
206 if (it.mInputIterator != it.mEnd && it.mPartIterator != it.mCurrentRange.
end() && it.mParser !=
nullptr) {
213 template <raw_parser::FormatSpec FmtCtrl>
220 template <raw_parser::FormatSpec FmtCtrl>
223 auto const& it =
fmt.it;
224 if (it.mInputIterator != it.mEnd && it.mPartIterator != it.mCurrentRange.end() && it.mParser !=
nullptr) {
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 != mCurrentRange.
end()) {
270 if (mParser && mCurrent != mParser->end() && ++mCurrent != mParser->end()) {
276 if (!isInitial && ++mPartIterator == mCurrentRange.
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 mCurrentRange = mInputIterator.parts();
316 mPartIterator = mCurrentRange.
begin();
321 InputRecord& mParent;
324 part_range mCurrentRange;
325 part_iterator mPartIterator;
326 std::unique_ptr<parser_type> mParser;
327 parser_iterator mCurrent;
328 std::vector<InputSpec>
const& mFilterSpecs;
329 size_t mMaxFailureMessages = -1;
330 size_t* mExtFailureCounter =
nullptr;
331 fair::Severity mSeverity = fair::Severity::alarm;
338 return const_iterator(mInputs, mInputs.
begin(), mInputs.
end(), mFilterSpecs, mSeverity, mMaxFailureMessages, mExtFailureCounter);
343 return const_iterator(mInputs, mInputs.
end(), mInputs.
end(), mFilterSpecs, mSeverity, mMaxFailureMessages, mExtFailureCounter);
352 std::vector<InputSpec> mFilterSpecs;
353 size_t mMaxFailureMessages = -1;
354 size_t* mExtFailureCounter =
nullptr;
355 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 ITS Vertex explicitly as messageable.
bool isSelected(const ExtendedTrack &track)
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