Skip to content

Commit 8ac507c

Browse files
authored
Merge 4ea8e5c into sapling-pr-archive-ktf
2 parents 32bf0e6 + 4ea8e5c commit 8ac507c

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

Common/Utils/include/CommonUtils/EnumFlags.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <string>
2525
#include <sstream>
2626
#include <limits>
27+
#include <bit>
2728
#include <bitset>
2829
#include <initializer_list>
2930
#include <cstdint>
@@ -34,7 +35,9 @@
3435
#include <iostream>
3536
#include <iomanip>
3637

38+
#ifndef GPUCA_GPUCODE
3739
#include "CommonUtils/StringUtils.h"
40+
#endif
3841

3942
namespace o2::utils
4043
{
@@ -55,6 +58,7 @@ concept EnumFlagHelper = requires {
5558
// This is very much inspired by much more extensive libraries like magic_enum.
5659
// Inspiration by its c++20 version (https://github.com/fix8mt/conjure_enum).
5760
// NOTE: Cannot detect if bit values past the underlying type are defined.
61+
#ifndef GPUCA_GPUCODE
5862
template <EnumFlagHelper E>
5963
struct FlagsHelper final {
6064
using U = std::underlying_type_t<E>;
@@ -317,10 +321,12 @@ struct FlagsHelper final {
317321
return false;
318322
}
319323
};
324+
#endif
320325

321326
} // namespace details::enum_flags
322327

323328
// Require an enum to fullfil what one would except from a bitset.
329+
#ifndef GPUCA_GPUCODE
324330
template <typename E>
325331
concept EnumFlag = requires {
326332
// range checks
@@ -332,6 +338,10 @@ concept EnumFlag = requires {
332338
requires !details::enum_flags::FlagsHelper<E>::hasNone(); // added automatically
333339
requires !details::enum_flags::FlagsHelper<E>::hasAll(); // added automatically
334340
};
341+
#else
342+
template <typename E>
343+
concept EnumFlag = details::enum_flags::EnumFlagHelper<E>;
344+
#endif
335345

336346
/**
337347
* \brief Class to aggregate and manage enum-based on-off flags.
@@ -358,7 +368,9 @@ template <EnumFlag E>
358368
class EnumFlags
359369
{
360370
static constexpr int DefaultBase{2};
371+
#ifndef GPUCA_GPUCODE
361372
using H = details::enum_flags::FlagsHelper<E>;
373+
#endif
362374
using U = std::underlying_type_t<E>;
363375
U mBits{0};
364376

@@ -388,18 +400,21 @@ class EnumFlags
388400
// Initialize with a list of flags.
389401
constexpr EnumFlags(std::initializer_list<E> flags) noexcept
390402
{
391-
std::for_each(flags.begin(), flags.end(), [this](const E f) noexcept { mBits |= to_bit(f); });
403+
for (const E f : flags) {
404+
mBits |= to_bit(f);
405+
}
392406
}
407+
#ifndef GPUCA_GPUCODE
393408
// Init from a string.
394409
//
395410
explicit EnumFlags(const std::string& str, int base = DefaultBase)
396411
{
397412
set(str, base);
398413
}
399-
// Destructor.
400-
constexpr ~EnumFlags() = default;
414+
#endif
401415

402-
static constexpr U None{0}; // Represents no flags set.
416+
static constexpr U None{0}; // Represents no flags set.
417+
#ifndef GPUCA_GPUCODE
403418
static constexpr U All{H::MaxRep}; // Represents all flags set.
404419

405420
// Return list of all enum values
@@ -432,6 +447,7 @@ class EnumFlags
432447
throw;
433448
}
434449
}
450+
#endif
435451
// Returns the raw bitset value.
436452
[[nodiscard]] constexpr auto value() const noexcept
437453
{
@@ -493,6 +509,7 @@ class EnumFlags
493509
}
494510

495511
// Checks if all flags are set.
512+
#ifndef GPUCA_GPUCODE
496513
[[nodiscard]] constexpr bool all() const noexcept
497514
{
498515
return mBits == All;
@@ -537,6 +554,7 @@ class EnumFlags
537554
}
538555
return oss.str();
539556
}
557+
#endif
540558

541559
// Checks if any flag is set (Boolean context).
542560
[[nodiscard]] constexpr explicit operator bool() const noexcept
@@ -645,6 +663,7 @@ class EnumFlags
645663
}
646664

647665
// Serializes the flag set to a string.
666+
#ifndef GPUCA_GPUCODE
648667
[[nodiscard]] std::string serialize() const
649668
{
650669
return std::to_string(mBits);
@@ -659,6 +678,7 @@ class EnumFlags
659678
}
660679
mBits = static_cast<U>(v);
661680
}
681+
#endif
662682

663683
// Counts the number of set bits (active flags).
664684
[[nodiscard]] constexpr size_t count() const noexcept
@@ -686,6 +706,7 @@ class EnumFlags
686706

687707
private:
688708
// Set implementation, bits was zeroed before.
709+
#ifndef GPUCA_GPUCODE
689710
void setImpl(const std::string& s, int base = 2)
690711
{
691712
// Helper to check if character is valid for given base
@@ -782,14 +803,17 @@ class EnumFlags
782803
throw std::invalid_argument("Cannot parse string!");
783804
}
784805
}
806+
#endif
785807
};
786808

809+
#ifndef GPUCA_GPUCODE
787810
template <EnumFlag E>
788811
std::ostream& operator<<(std::ostream& os, const EnumFlags<E>& f)
789812
{
790813
os << f.pstring(true);
791814
return os;
792815
}
816+
#endif
793817

794818
} // namespace o2::utils
795819

Framework/Core/src/DataProcessingDevice.cxx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@ DataProcessingDevice::DataProcessingDevice(RunningDeviceRef running, ServiceRegi
212212
});
213213
}
214214

215-
// Callback to execute the processing. Notice how the data is
216-
// is a vector of DataProcessorContext so that we can index the correct
217-
// one with the thread id. For the moment we simply use the first one.
215+
// Callback to execute the processing. Receives and relays data (doPrepare)
216+
// happens on the main thread before this is queued, so we only dispatch here.
218217
void run_callback(uv_work_t* handle)
219218
{
220219
auto* task = (TaskStreamInfo*)handle->data;
@@ -223,7 +222,6 @@ void run_callback(uv_work_t* handle)
223222
auto& dataProcessorContext = ref.get<DataProcessorContext>();
224223
O2_SIGNPOST_ID_FROM_POINTER(sid, device, &dataProcessorContext);
225224
O2_SIGNPOST_START(device, sid, "run_callback", "Starting run callback on stream %d", task->id.index);
226-
DataProcessingDevice::doPrepare(ref);
227225
DataProcessingDevice::doRun(ref);
228226
O2_SIGNPOST_END(device, sid, "run_callback", "Done processing data for stream %d", task->id.index);
229227
}
@@ -1332,6 +1330,10 @@ void DataProcessingDevice::Run()
13321330
handleRegionCallbacks(mServiceRegistry, mPendingRegionInfos);
13331331
}
13341332

1333+
// Receive and relay incoming data on the main thread so that I/O
1334+
// overlaps with computation running concurrently on work threads.
1335+
DataProcessingDevice::doPrepare(ref);
1336+
13351337
assert(mStreams.size() == mHandles.size());
13361338
/// Decide which task to use
13371339
TaskStreamRef streamRef{-1};

Framework/Core/src/FragmentToBatch.cxx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ void FragmentToBatch::fill(std::shared_ptr<arrow::Schema> schema, std::shared_pt
4444
options->dataset_schema = schema;
4545
auto scanner = format->ScanBatchesAsync(options, mFragment);
4646
auto batch = (*scanner)();
47-
mRecordBatch = *batch.result();
47+
auto result = batch.result();
48+
if (!result.ok()) {
49+
throw std::runtime_error("FragmentToBatch::fill: scan failed: " + result.status().ToString());
50+
}
51+
mRecordBatch = *result;
52+
if (!mRecordBatch) {
53+
throw std::runtime_error("FragmentToBatch::fill: scan returned null RecordBatch");
54+
}
4855
// Notice that up to here the buffer was not yet filled.
4956
}
5057

0 commit comments

Comments
 (0)