Project
Loading...
Searching...
No Matches
test_Timers.cxx
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.
12#include "Framework/InputSpec.h"
16#include <uv.h>
17
18using namespace o2::framework;
19
20// This is how you can define your processing in a declarative way
22{
23 // every 2 second for the first 10s, then every second for 5 seconds.
24 std::vector<TimerSpec> timers{{TimerSpec{2000000000, 10},
25 TimerSpec{1000000000, 5}}};
26
27 std::vector<InputSpec> inputs = {{{"timer"}, "TST", "TIMER", 0, Lifetime::Timer, timerSpecs(timers)}};
28
29 return WorkflowSpec{
30 {
31 .name = "test-timer",
32 .inputs = inputs,
33 .outputs = {OutputSpec{"TST", "A", 0}},
34 .algorithm = AlgorithmSpec{adaptStateless(
35 [](DataAllocator& outputs, ControlService& control) {
36 LOGP(info, "Processing callback invoked");
37 outputs.make<int>(Output{"TST", "A", 0}, 1);
38 static int64_t counter = 0;
39 static int64_t counterA = 0;
40 static int64_t start = uv_hrtime();
41 int64_t lastTime = uv_hrtime();
42 auto elapsed = lastTime - start;
43
44 LOGP(info, "Elapsed time: {} ns", elapsed);
45 if ((lastTime - start) < 10000000000) {
46 auto diff = (counter * 2000000000) - (lastTime - start);
47 if (diff > 100000000) {
48 LOGP(fatal, "2s timer is not accurate enough: {}, count {}", diff, counter);
49 }
50 counter++;
51 counterA++;
52 } else {
53 if (counterA != 5) {
54 LOGP(fatal, "2s timer did not do all the expected iterations {} != 5", counterA);
55 }
56 int64_t diff = 2000000000LL * 5 + 1000000000 * (counter - 5) - (lastTime - start);
57 if (diff > 10000000) {
58 LOGP(fatal, "1s timer is not accurate enough: {}, count ", diff, counter);
59 }
60 counter++;
61 }
62 LOGP(info, "Counter: {}", counter);
63 if (counter == 15) {
64 control.readyToQuit(QuitRequest::All);
65 }
66 })},
67 }};
68}
void readyToQuit(bool all)
Compatibility with old API.
decltype(auto) make(const Output &spec, Args... args)
GLuint start
Definition glcorearb.h:469
GLuint counter
Definition glcorearb.h:3987
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< DataProcessorSpec > WorkflowSpec
AlgorithmSpec::ProcessCallback adaptStateless(LAMBDA l)
std::vector< ConfigParamSpec > timerSpecs(std::vector< TimerSpec > intervals)
WorkflowSpec defineDataProcessing(ConfigContext const &ctx)
This function hooks up the the workflow specifications into the DPL driver.