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) {}
107 : 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)
136 bool result = mInputIterator ==
other.mInputIterator;
138 if (mParser !=
nullptr &&
other.mParser !=
nullptr) {
152 if (mInputIterator != mEnd) {
153 return DataRefUtils::getHeader<o2::header::DataHeader*>(*mPartIterator);
161 if (mInputIterator != mEnd) {
162 return DataRefUtils::getHeader<o2::framework::DataProcessingHeader*>(*mPartIterator);
170 return mCurrent.raw();
176 return mCurrent.data();
182 return mCurrent.offset();
188 return mCurrent.size();
194 return mCurrent.sizeTotal();
199 template <
typename U>
202 return mCurrent.template get_if<U>();
207 if (it.mInputIterator != it.mEnd && it.mPartIterator != it.mInputIterator.end() && it.mParser !=
nullptr) {
214 template <raw_parser::FormatSpec FmtCtrl>
221 template <raw_parser::FormatSpec FmtCtrl>
224 auto const& it =
fmt.it;
225 if (it.mInputIterator != it.mEnd && it.mPartIterator != it.mInputIterator.end() && it.mParser !=
nullptr) {
239 using part_iterator =
typename input_iterator::const_iterator;
241 using parser_iterator =
typename parser_type::const_iterator;
245 auto logFailure = [
this](
const std::string&
msg,
const std::runtime_error& e) {
246 if (!this->mExtFailureCounter || (*this->mExtFailureCounter)++ < this->mMaxFailureMessages) {
247 if (this->mSeverity == fair::Severity::alarm) {
248 LOG(alarm) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
249 }
else if (this->mSeverity == fair::Severity::warn) {
250 LOG(warn) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
251 }
else if (this->mSeverity == fair::Severity::fatal) {
252 LOG(fatal) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
253 }
else if (this->mSeverity == fair::Severity::info) {
254 LOG(info) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
256 LOG(
debug) <<
msg << (*this->mInputIterator).spec->binding <<
" : " << e.what();
261 while (mInputIterator != mEnd) {
262 bool isInitial = mParser ==
nullptr;
263 while (mPartIterator != mInputIterator.end()) {
265 if (mParser && mCurrent != mParser->end() && ++mCurrent != mParser->end()) {
271 if (!isInitial && (mPartIterator == mInputIterator.end() || ++mPartIterator == mInputIterator.end())) {
277 if (mFilterSpecs.size() > 0) {
279 for (
auto const& spec : mFilterSpecs) {
288 gsl::span<const char>
raw;
290 raw = mParent.
get<gsl::span<char>>(*mPartIterator);
291 }
catch (
const std::runtime_error& e) {
292 logFailure(
"failed to read data from ", e);
294 if (
raw.size() == 0) {
299 mParser = std::make_unique<parser_type>(
raw.data(),
raw.size());
300 }
catch (
const std::runtime_error& e) {
301 logFailure(
"can not create raw parser from ", e);
304 if (mParser !=
nullptr) {
305 mCurrent = mParser->begin();
310 mPartIterator = mInputIterator.begin();
315 InputRecord& mParent;
318 part_iterator mPartIterator;
319 std::unique_ptr<parser_type> mParser;
320 parser_iterator mCurrent;
321 std::vector<InputSpec>
const& mFilterSpecs;
322 size_t mMaxFailureMessages = -1;
323 size_t* mExtFailureCounter =
nullptr;
324 fair::Severity mSeverity = fair::Severity::alarm;
331 return const_iterator(mInputs, mInputs.
begin(), mInputs.
end(), mFilterSpecs, mSeverity, mMaxFailureMessages, mExtFailureCounter);
336 return const_iterator(mInputs, mInputs.
end(), mInputs.
end(), mFilterSpecs, mSeverity, mMaxFailureMessages, mExtFailureCounter);
345 std::vector<InputSpec> mFilterSpecs;
346 size_t mMaxFailureMessages = -1;
347 size_t* mExtFailureCounter =
nullptr;
348 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 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)
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