|
| 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/DataTakingContext.h" |
| 13 | +#include "Framework/CompletionPolicyHelpers.h" |
| 14 | +#include "Framework/DeviceSpec.h" |
| 15 | +#include "Framework/RawDeviceService.h" |
| 16 | +#include "Framework/ControlService.h" |
| 17 | +#include "Framework/Configurable.h" |
| 18 | +#include "Framework/RunningWorkflowInfo.h" |
| 19 | +#include "Framework/RateLimiter.h" |
| 20 | +#include <fairmq/Device.h> |
| 21 | + |
| 22 | +#include <iostream> |
| 23 | +#include <chrono> |
| 24 | +#include <thread> |
| 25 | +#include <vector> |
| 26 | + |
| 27 | +using namespace o2::framework; |
| 28 | + |
| 29 | +#include "Framework/runDataProcessing.h" |
| 30 | + |
| 31 | +// This is how you can define your processing in a declarative way |
| 32 | +WorkflowSpec defineDataProcessing(ConfigContext const& specs) |
| 33 | +{ |
| 34 | + DataProcessorSpec a{ |
| 35 | + .name = "A", |
| 36 | + .outputs = {OutputSpec{{"data"}, "TST", "A1", 0}}, |
| 37 | + .algorithm = AlgorithmSpec{adaptStateless( |
| 38 | + [](DataAllocator& outputs, RawDeviceService& device, DataTakingContext& context, ProcessingContext& pcx) { |
| 39 | + LOG(info) << "Data TST/A1/0 created"; |
| 40 | + outputs.make<int>(OutputRef{"data"}, 1); |
| 41 | + })}, |
| 42 | + }; |
| 43 | + DataProcessorSpec b{ |
| 44 | + .name = "B", |
| 45 | + .outputs = {OutputSpec{{"sporadic"}, "TST", "B1", 0, Lifetime::Sporadic}}, |
| 46 | + .algorithm = AlgorithmSpec{adaptStateless( |
| 47 | + [](DataAllocator& outputs, RawDeviceService& device, DataTakingContext& context, ProcessingContext& pcx) { |
| 48 | + // This will always be late, however since the oldest possible timeframe |
| 49 | + // will be used to decide the scheduling, it will not be dropped. |
| 50 | + sleep(1); |
| 51 | + // We also create it only every second time, so that we can check that |
| 52 | + // the sporadic output is not mandatory. |
| 53 | + static int i = 0; |
| 54 | + if (i++ % 2 == 0) { |
| 55 | + LOG(info) << "Data TST/B1/0 created"; |
| 56 | + outputs.make<int>(OutputRef{"sporadic"}, 1); |
| 57 | + } |
| 58 | + })}, |
| 59 | + }; |
| 60 | + DataProcessorSpec d{ |
| 61 | + .name = "D", |
| 62 | + .inputs = {InputSpec{"a1", "TST", "A1", 0, Lifetime::Timeframe}, |
| 63 | + InputSpec{"b1", "TST", "B1", 0, Lifetime::Sporadic}}, |
| 64 | + .algorithm = AlgorithmSpec{adaptStateless( |
| 65 | + [](InputRecord& inputs) { |
| 66 | + auto refA = inputs.get("a1"); |
| 67 | + auto headerA = o2::header::get<const DataProcessingHeader*>(refA.header); |
| 68 | + LOG(info) << "Start time: " << headerA->startTime; |
| 69 | + auto refB = inputs.get("b1"); |
| 70 | + if (!refB.header) { |
| 71 | + LOG(info) << "No sporadic input for start time " << headerA->startTime; |
| 72 | + return; |
| 73 | + } |
| 74 | + auto headerB = o2::header::get<const DataProcessingHeader*>(refB.header); |
| 75 | + LOG(info) << "Start time: " << headerB->startTime; |
| 76 | + })}, |
| 77 | + }; |
| 78 | + |
| 79 | + return workflow::concat(WorkflowSpec{a}, |
| 80 | + WorkflowSpec{b}, |
| 81 | + WorkflowSpec{d}); |
| 82 | +} |
0 commit comments