|
| 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 | +#include "Framework/ConfigParamSpec.h" |
| 12 | +#include "Framework/AlgorithmSpec.h" |
| 13 | +#include "Framework/Configurable.h" |
| 14 | +#include "Framework/Logger.h" |
| 15 | +#include "Framework/CallbackService.h" |
| 16 | +#include "Framework/Signpost.h" |
| 17 | + |
| 18 | +O2_DECLARE_DYNAMIC_LOG(crash_test); |
| 19 | + |
| 20 | +using namespace o2::framework; |
| 21 | + |
| 22 | +struct WorkflowOptions { |
| 23 | + Configurable<std::string> crashType{"crash-type", "fatal-init", {"how should this crash? (fatal-init, fatal-run, runtime-init, runtime-fail, abort-init, abort-run)"}}; |
| 24 | +}; |
| 25 | + |
| 26 | +#include "Framework/runDataProcessing.h" |
| 27 | + |
| 28 | +AlgorithmSpec simpleCrashingSource(std::string const& what) |
| 29 | +{ |
| 30 | + return AlgorithmSpec{adaptStateful([what](InitContext& ctx) { |
| 31 | + O2_SIGNPOST_ID_FROM_POINTER(ii, crash_test, &ctx); |
| 32 | + O2_SIGNPOST_START(crash_test, ii, "Init", "Starting Init"); |
| 33 | + O2_SIGNPOST_EVENT_EMIT(crash_test, ii, "Init", "%{public}s selected", what.c_str()); |
| 34 | + |
| 35 | + if (what == "fatal-init") { |
| 36 | + LOG(fatal) << "This should have a fatal"; |
| 37 | + } else if (what == "runtime-init") { |
| 38 | + throw std::runtime_error("This is a std::runtime_error"); |
| 39 | + } else if (what == "abort-init") { |
| 40 | + abort(); |
| 41 | + } else if (what == "framework-init") { |
| 42 | + throw o2::framework::runtime_error("This is a o2::framework::runtime_error"); |
| 43 | + } else if (what == "framework-prerun") { |
| 44 | + ctx.services().get<CallbackService>().set<CallbackService::Id::PreProcessing>([](ServiceRegistryRef, int) { |
| 45 | + throw o2::framework::runtime_error("This is o2::framework::runtime_error in PreProcessing"); |
| 46 | + }); |
| 47 | + } else if (what == "runtime-prerun") { |
| 48 | + ctx.services().get<CallbackService>().set<CallbackService::Id::PreProcessing>([](ServiceRegistryRef, int) { |
| 49 | + throw std::runtime_error("This is std::runtime_error in PreProcessing"); |
| 50 | + }); |
| 51 | + } |
| 52 | + O2_SIGNPOST_END(crash_test, ii, "Init", "Init Done"); |
| 53 | + return adaptStateless([what](ProcessingContext& pCtx) { |
| 54 | + O2_SIGNPOST_ID_FROM_POINTER(ri, crash_test, &pCtx); |
| 55 | + O2_SIGNPOST_START(crash_test, ri, "Run", "Starting Run"); |
| 56 | + O2_SIGNPOST_EVENT_EMIT(crash_test, ri, "Run", "%{public}s selected", what.c_str()); |
| 57 | + if (what == "fatal-run") { |
| 58 | + LOG(fatal) << "This should have a fatal"; |
| 59 | + } else if (what == "runtime-run") { |
| 60 | + throw std::runtime_error("This is a std::runtime_error"); |
| 61 | + } else if (what == "abort-run") { |
| 62 | + abort(); |
| 63 | + } else if (what == "framework-run") { |
| 64 | + throw o2::framework::runtime_error("This is a o2::framework::runtime_error"); |
| 65 | + } |
| 66 | + O2_SIGNPOST_EVENT_EMIT_ERROR(crash_test, ri, "Run", "Unknown option for crash-type: %{public}s.", what.c_str()); |
| 67 | + O2_SIGNPOST_END(crash_test, ri, "Init", "Run Done"); |
| 68 | + exit(1); |
| 69 | + }); |
| 70 | + })}; |
| 71 | +} |
| 72 | + |
| 73 | +// This is how you can define your processing in a declarative way |
| 74 | +WorkflowSpec defineDataProcessing(ConfigContext const& config) |
| 75 | +{ |
| 76 | + auto crashType = config.options().get<std::string>("crash-type"); |
| 77 | + DataProcessorSpec a{ |
| 78 | + .name = "deliberately-crashing", |
| 79 | + .outputs = {OutputSpec{{"a1"}, "TST", "A1"}}, |
| 80 | + .algorithm = AlgorithmSpec{simpleCrashingSource(crashType)}}; |
| 81 | + DataProcessorSpec b{ |
| 82 | + .name = "B", |
| 83 | + .inputs = {InputSpec{"x", "TST", "A1", Lifetime::Timeframe}}, |
| 84 | + .algorithm = AlgorithmSpec{adaptStateless([](ProcessingContext&) {})}}; |
| 85 | + |
| 86 | + return workflow::concat(WorkflowSpec{a, b}); |
| 87 | +} |
| 88 | + |
0 commit comments