Project
Loading...
Searching...
No Matches
O2DataModelHelpers.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_FRAMEWORK_O2DATAMODELHELPERS_H_
13#define O2_FRAMEWORK_O2DATAMODELHELPERS_H_
14
15#include "Headers/DataHeader.h"
16#include <fairmq/Parts.h>
18
19namespace o2::framework
20{
27 template <typename F>
28 static void for_each_header(fair::mq::Parts& parts, F&& f)
29 {
30 size_t i = 0;
31 while (i < parts.Size()) {
32 auto* dh = o2::header::get<o2::header::DataHeader*>(parts.At(i)->GetData());
33 f(dh);
34 // One for the header, plus the number of split parts.
35 // When 0 it means we have a single part.
36 i += 1 + (dh->splitPayloadParts ? dh->splitPayloadParts : 1);
37 }
38 }
39
40 // Return true if F returns true for any of the headers
41 template <typename F>
42 static bool any_header_matching(fair::mq::Parts& parts, F&& f)
43 {
44 size_t i = 0;
45 while (i < parts.Size()) {
46 auto* dh = o2::header::get<o2::header::DataHeader*>(parts.At(i)->GetData());
47 if (f(dh)) {
48 return true;
49 }
50 // One for the header, plus the number of split parts.
51 // When 0 it means we have a single part.
52 i += 1 + (dh->splitPayloadParts ? dh->splitPayloadParts : 1);
53 }
54 return false;
55 }
56
57 // Return true if F returns true for any of the headers
58 template <typename F>
59 static bool all_headers_matching(fair::mq::Parts& parts, F&& f)
60 {
61 size_t i = 0;
62 while (i < parts.Size()) {
63 auto* dh = o2::header::get<o2::header::DataHeader*>(parts.At(i)->GetData());
64 if (!f(dh)) {
65 return false;
66 }
67 // One for the header, plus the number of split parts.
68 // When 0 it means we have a single part.
69 i += 1 + (dh->splitPayloadParts ? dh->splitPayloadParts : 1);
70 }
71 return true;
72 }
73 static void updateMissingSporadic(fair::mq::Parts& parts, std::vector<OutputSpec> const& specs, std::vector<bool>& present);
74 static bool validateOutputs(std::vector<bool>& present)
75 {
76 for (auto p : present) {
77 if (!p) {
78 return false;
79 }
80 }
81 return true;
82 }
83 static std::string describeMissingOutputs(std::vector<OutputSpec> const& specs, std::vector<bool> const& present);
84};
85} // namespace o2::framework
86
87#endif // O2_FRAMEWORK_O2DATAMODELHELPERS_H_
int32_t i
GLdouble f
Definition glcorearb.h:310
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
static void for_each_header(fair::mq::Parts &parts, F &&f)
static bool validateOutputs(std::vector< bool > &present)
static void updateMissingSporadic(fair::mq::Parts &parts, std::vector< OutputSpec > const &specs, std::vector< bool > &present)
static bool any_header_matching(fair::mq::Parts &parts, F &&f)
static std::string describeMissingOutputs(std::vector< OutputSpec > const &specs, std::vector< bool > const &present)
static bool all_headers_matching(fair::mq::Parts &parts, F &&f)