Project
Loading...
Searching...
No Matches
o2FairMQHeaderSizeTest.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.
11
17
25
26#include <chrono>
27#include <thread>
28#include <vector>
29#include <random>
30
31using namespace o2::framework;
32
33static std::random_device rd;
34static std::mt19937 gen(rd());
35
36std::string random_string(size_t length)
37{
38 static const char alphanum[] =
39 "0123456789"
40 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
41 "abcdefghijklmnopqrstuvwxyz";
42
43 std::uniform_int_distribution<> dis(0, sizeof(alphanum) - 2);
44
45 std::string randomString;
46 randomString.reserve(length);
47
48 for (int i = 0; i < length; ++i) {
49 randomString.push_back(alphanum[dis(gen)]);
50 }
51
52 return randomString;
53}
54
55std::string filename()
56{
57 std::stringstream ss;
58 ss << "messages_count_" << random_string(10) << ".data";
59 return std::move(ss).str();
60}
61
63{
64 return WorkflowSpec{
65 {"A",
66 Inputs{},
67 {OutputSpec{{"a"}, "TST", "A"}},
69 [numberOfMessages = 0, filename = filename()](ProcessingContext& ctx) mutable {
70 using namespace std::chrono;
71 ++numberOfMessages;
72 // LOG(info) << "Generating message #" << ++numberOfMessages;
73
74 {
75 auto file = std::ofstream(filename, std::ios_base::out | std::ios_base::trunc);
76 // file << duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() << "," << numberOfMessages << "\n";
77 file << numberOfMessages;
78 }
79
80 auto& aData = ctx.outputs().make<int>(Output{"TST", "A", 0}, 1);
81 aData[0] = 1;
82 }}},
83 {"B",
84 {InputSpec{"x", "TST", "A"}},
85 Outputs{},
87 return [](ProcessingContext& ctx) {
88 while (true) {
89 std::this_thread::sleep_for(std::chrono::milliseconds{100});
90 }
91 // auto& data = ctx.inputs().get<int>("x");
92 // LOG(info) << "Reading message: " << data;
93 };
94 }}},
95 };
96}
default_random_engine gen(dev())
int32_t i
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< DataProcessorSpec > WorkflowSpec
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
WorkflowSpec defineDataProcessing(ConfigContext const &specs)
This function hooks up the the workflow specifications into the DPL driver.
std::string random_string(size_t length)
std::string filename()
std::random_device rd