Skip to content

Commit c68bd37

Browse files
committed
Emulator for ADAPOS DCS DPs data
1 parent 5004f97 commit c68bd37

3 files changed

Lines changed: 116 additions & 2 deletions

File tree

Detectors/DCS/testWorkflow/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ cp ~/alice/O2/Detectors/DCS/testWorkflow/src/dcs*.cpp ./
9595
cp ~/alice/O2/Detectors/DCS/testWorkflow/src/compile-dcs-emulator.sh ./
9696
source ./compile-dcs-emulator.sh
9797
```
98-
This will compile two executables `dcssend` and `dcsclient`. The former one is the `DCS server emulator` which has the following options:
98+
This will compile tree executables `dcssend`, `dcsclient` and dcssendDPs. The former one is the `DCS server emulator` which has the following options:
9999
```
100100
./dcssend -h
101101
```
@@ -110,3 +110,5 @@ In case of problems you can validate the receiving process using `dcsclient` tes
110110
```
111111
./dcsclient -o 5556 -a 5557
112112
```
113+
114+
The `dcssendDPs` can be used to emulate the DCS DPs data coming from the ADAPOS server.

Detectors/DCS/testWorkflow/src/compile-dcs-emulator.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ source ${WORK_DIR}/${ARCH}/cppzmq/latest/etc/profile.d/init.sh
44
source ${WORK_DIR}/${ARCH}/boost/latest/etc/profile.d/init.sh
55
g++ dcssend.cpp -o dcssend -I$BOOST_ROOT/include -I$CPPZMQ_ROOT/include -I$ZEROMQ_ROOT/include -L $BOOST_ROOT/lib -l boost_program_options -L$ZEROMQ_ROOT/lib -l zmq
66
g++ dcsclient.cpp -o dcsclient -I$BOOST_ROOT/include -I$CPPZMQ_ROOT/include -I$ZEROMQ_ROOT/include -L $BOOST_ROOT/lib -l boost_program_options -L$ZEROMQ_ROOT/lib -l zmq
7-
7+
g++ dcssendDPs.cpp -o dcssendDPs -I$BOOST_ROOT/include -I$CPPZMQ_ROOT/include -I$ZEROMQ_ROOT/include -L $BOOST_ROOT/lib -I$ROOTSYS/include -I$O2_ROOT/include -l boost_program_options -L$ZEROMQ_ROOT/lib -l zmq -L$O2_ROOT/lib -lO2DetectorsDCS
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include <string>
2+
#include <zmq.hpp>
3+
#include <zmq_addon.hpp>
4+
#include <vector>
5+
#include <iostream>
6+
#include <fstream>
7+
#include <chrono>
8+
9+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
10+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
11+
// All rights not expressly granted are reserved.
12+
//
13+
// This software is distributed under the terms of the GNU General Public
14+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
15+
//
16+
// In applying this license CERN does not waive the privileges and immunities
17+
// granted to it by virtue of its status as an Intergovernmental Organization
18+
// or submit itself to any jurisdiction.
19+
20+
#include <thread>
21+
#include <boost/program_options.hpp>
22+
23+
#include "DetectorsDCS/DataPointIdentifier.h"
24+
#include "DetectorsDCS/DataPointValue.h"
25+
#include "DetectorsDCS/DataPointCompositeObject.h"
26+
#include "DetectorsDCS/DataPointCreator.h"
27+
28+
namespace bpo = boost::program_options;
29+
30+
int main(int argc, char** argv)
31+
{
32+
using DPCOM = o2::dcs::DataPointCompositeObject;
33+
34+
bpo::variables_map vm;
35+
bpo::options_description opt_general("Usage:\n " + std::string(argv[0]));
36+
bpo::options_description opt_hidden("");
37+
bpo::options_description opt_all;
38+
bpo::positional_options_description opt_pos;
39+
40+
try {
41+
auto add_option = opt_general.add_options();
42+
add_option("help,h", "Print this help message");
43+
add_option("rate,r", bpo::value<float>()->default_value(25.0f), "messages per second");
44+
add_option("size,s", bpo::value<int>()->default_value(1024 * 1024), "size per message");
45+
add_option("port,p", bpo::value<int>()->default_value(5556), "port to send the file");
46+
opt_all.add(opt_general).add(opt_hidden);
47+
bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
48+
49+
if (vm.count("help")) {
50+
std::cout << opt_general << std::endl;
51+
exit(0);
52+
}
53+
bpo::notify(vm);
54+
} catch (bpo::error& e) {
55+
std::cerr << "ERROR: " << e.what() << std::endl;
56+
std::cerr << opt_general << std::endl;
57+
exit(1);
58+
} catch (std::exception& e) {
59+
std::cerr << e.what() << ", application will now exit" << std::endl;
60+
exit(2);
61+
}
62+
63+
// init --------------------
64+
zmq::context_t context(1);
65+
zmq::socket_t publisher(context, zmq::socket_type::push);
66+
67+
int pub_port = vm["port"].as<int>();
68+
size_t sz = vm["size"].as<int>();
69+
70+
publisher.bind("tcp://127.0.0.1:" + std::to_string(pub_port));
71+
72+
std::chrono::duration<float> wait{1. / std::max(0.01f, vm["rate"].as<float>())};
73+
// end of init -------------
74+
75+
auto timerStart = std::chrono::system_clock::now();
76+
auto timer0 = std::chrono::system_clock::now();
77+
// std::cout << "will wait for " << wait << " s between injections\n"
78+
79+
size_t trial = 0, datasize = 0;
80+
while (1) {
81+
std::this_thread::sleep_for(wait);
82+
83+
// send -------------------------
84+
std::vector<zmq::message_t> data;
85+
86+
std::vector<o2::dcs::DataPointCompositeObject> myVector;
87+
auto timeNow = std::chrono::high_resolution_clock::now();
88+
auto timeNowMs = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow.time_since_epoch()).count(); // in ms
89+
auto timeNowS = std::chrono::duration_cast<std::chrono::seconds>(timeNow.time_since_epoch()).count(); // in ms
90+
91+
size_t locSize = 0;
92+
do {
93+
myVector.emplace_back(o2::dcs::createDataPointCompositeObject("ADAPOS_LG/TEST_000100", 12345.6789, timeNowS, std::abs(timeNowMs - timeNowS * 1000)));
94+
locSize += myVector.size() * sizeof(DPCOM);
95+
} while (locSize < sz);
96+
97+
// fill in filename
98+
data.push_back(zmq::message_t((void*)myVector.data(), myVector.size() * sizeof(DPCOM)));
99+
datasize += locSize;
100+
zmq::send_multipart(publisher, data);
101+
// end of send ------------------
102+
103+
trial++;
104+
auto timerNow = std::chrono::system_clock::now();
105+
std::chrono::duration<float, std::ratio<1>> dur0 = timerNow - timer0;
106+
if (dur0.count() > 1) {
107+
timer0 = timerNow;
108+
std::chrono::duration<float, std::ratio<1>> durationStart = timerNow - timerStart;
109+
std::cout << trial << " messages sent in " << durationStart.count() << " s, total size: " << datasize << " bytes\n";
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)