Skip to content

Commit d048f0e

Browse files
committed
[DCS] Add helper functions to generate (random) DCS data points.
The main functions are `o2::dcs::generateRandomDataPoints` and `o2::dcs::expandAliases`, the latter being used to create easily large lists of data point aliases from basic patterns. For instance the compact description "DET/Crate[0..3]/Channel[000.042]/[iMon,vMon]" would be expanded to 344 (4x43x2) aliases.
1 parent c05f333 commit d048f0e

17 files changed

Lines changed: 1064 additions & 45 deletions

Detectors/DCS/CMakeLists.txt

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,64 @@
88
# granted to it by virtue of its status as an Intergovernmental Organization or
99
# submit itself to any jurisdiction.
1010

11-
o2_add_library(DetectorsDCS
12-
TARGETVARNAME targetName
13-
SOURCES src/Clock.cxx
14-
src/DataPointCompositeObject.cxx
15-
src/DataPointIdentifier.cxx
16-
src/DataPointValue.cxx
17-
src/DeliveryType.cxx
18-
src/GenericFunctions.cxx
19-
src/StringUtils.cxx
20-
src/DCSProcessor.cxx
21-
PUBLIC_LINK_LIBRARIES O2::Headers
22-
O2::CommonUtils
23-
O2::CCDB
24-
O2::DetectorsCalibration
25-
ms_gsl::ms_gsl)
11+
o2_add_library(
12+
DetectorsDCS
13+
TARGETVARNAME targetName
14+
SOURCES src/AliasExpander.cxx
15+
src/DCSProcessor.cxx
16+
src/DataPointCompositeObject.cxx
17+
src/DataPointCreator.cxx
18+
src/DataPointGenerator.cxx
19+
src/DataPointIdentifier.cxx
20+
src/DataPointValue.cxx
21+
src/DeliveryType.cxx
22+
src/GenericFunctions.cxx
23+
src/StringUtils.cxx
24+
src/Clock.cxx
25+
PUBLIC_LINK_LIBRARIES O2::Headers O2::CommonUtils O2::CCDB
26+
O2::DetectorsCalibration ms_gsl::ms_gsl)
2627

27-
o2_target_root_dictionary(DetectorsDCS
28-
HEADERS include/DetectorsDCS/DataPointCompositeObject.h
29-
include/DetectorsDCS/DataPointIdentifier.h
30-
include/DetectorsDCS/DataPointValue.h
31-
include/DetectorsDCS/DCSProcessor.h)
28+
o2_target_root_dictionary(
29+
DetectorsDCS
30+
HEADERS include/DetectorsDCS/DataPointCompositeObject.h
31+
include/DetectorsDCS/DataPointIdentifier.h
32+
include/DetectorsDCS/DataPointValue.h
33+
include/DetectorsDCS/DCSProcessor.h)
3234

33-
o2_add_executable(dcs-data-workflow
34-
COMPONENT_NAME dcs
35-
SOURCES testWorkflow/dcs-data-workflow.cxx
36-
PUBLIC_LINK_LIBRARIES O2::Framework
37-
O2::DetectorsDCS)
35+
o2_add_executable(
36+
data-workflow
37+
COMPONENT_NAME dcs
38+
SOURCES testWorkflow/dcs-data-workflow.cxx
39+
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)
3840

39-
if (OpenMP_CXX_FOUND)
40-
target_compile_definitions(${targetName} PRIVATE WITH_OPENMP)
41-
target_link_libraries(${targetName} PRIVATE OpenMP::OpenMP_CXX)
41+
o2_add_executable(
42+
random-data-workflow
43+
COMPONENT_NAME dcs
44+
SOURCES testWorkflow/dcs-random-data-workflow.cxx
45+
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)
46+
47+
if(OpenMP_CXX_FOUND)
48+
target_compile_definitions(${targetName} PRIVATE WITH_OPENMP)
49+
target_link_libraries(${targetName} PRIVATE OpenMP::OpenMP_CXX)
50+
endif()
51+
52+
if(BUILD_TESTING)
53+
o2_add_test(
54+
data-point-types
55+
SOURCES test/testDataPointTypes.cxx
56+
COMPONENT_NAME dcs
57+
LABELS "dcs"
58+
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)
59+
o2_add_test(
60+
alias-expander
61+
SOURCES test/testAliasExpander.cxx
62+
COMPONENT_NAME dcs
63+
LABELS "dcs"
64+
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)
65+
o2_add_test(
66+
data-point-generator
67+
SOURCES test/testDataPointGenerator.cxx
68+
COMPONENT_NAME dcs
69+
LABELS "dcs"
70+
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)
4271
endif()

Detectors/DCS/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- doxy
2+
\page refDetectorsDCS DCS
3+
/doxy -->
4+
5+
# Export of DCS to CCDB
6+
7+
To be written
8+
9+
# Generating DCS aliases
10+
11+
For test purposes, DCS aliases can be generated making use of the helper
12+
function `generateRandomDataPoints`. For example :
13+
14+
```c++
15+
#include "DetectorsDCS/DataPointGenerator.h"
16+
std::vector<std::string> patterns = { "DET/HV/Crate[0.9]/Channel[00.42]/vMon" };
17+
auto dps = o2::dcs::generateRandomDataPoints(patterns,0.0,1200.0);
18+
```
19+
20+
would generate 420 data points.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef O2_DCS_ALIAS_EXPANDER_H
12+
#define O2_DCS_ALIAS_EXPANDER_H
13+
14+
#include <vector>
15+
#include <string>
16+
17+
namespace o2::dcs
18+
{
19+
/**
20+
* expandAlias converts a single pattern into a list of strings.
21+
*
22+
* @param pattern a pattern is made of a number of "XX[YY]" blocks (at least one)
23+
*
24+
* where :
25+
* - XX is any text
26+
* - YY describes either a integral range or a textual list
27+
*
28+
* An integral range is [a..b] where the formatting of the biggest of the
29+
* two integers a and b dictates, by default, the formatting of the output
30+
* alias. For instance [0..3] is expanded to the set 0,1,2,3 while [00..03]
31+
* is expanded to 00,01,02,03. If you want more control on the formatting,
32+
* you can use a python/fmt format {} e.g. [0..15{:d}] would yields 0,1,
33+
* 2,...,14,15 simply (no 0 filling).
34+
*
35+
* A textual list is simply a list of values separated by commas,
36+
* e.g. "vMon,iMon"
37+
*
38+
* @returns a vector of strings containing all the possible expansions of
39+
* the pattern. That vector is not guaranteed to be sorted.
40+
*
41+
* For example, pattern=DET[A,B]/Channel[000,002]/[iMon,vMon] yields :
42+
*
43+
* - DETA/Channel000/iMon
44+
* - DETA/Channel001/iMon
45+
* - DETA/Channel002/iMon
46+
* - DETA/Channel000/vMon
47+
* - DETA/Channel001/vMon
48+
* - DETA/Channel002/vMon
49+
* - DETB/Channel000/iMon
50+
* - DETB/Channel001/iMon
51+
* - DETB/Channel002/iMon
52+
* - DETB/Channel000/vMon
53+
* - DETB/Channel001/vMon
54+
* - DETB/Channel002/vMon
55+
56+
*/
57+
std::vector<std::string> expandAlias(const std::string& pattern);
58+
59+
/** expandAliases converts a list of patterns into a list of strings.
60+
*
61+
* each input pattern is treated by expandAlias()
62+
*
63+
* @returns a _sorted_ vector of strings containing all the possible
64+
* expansions of the pattern.
65+
*/
66+
std::vector<std::string> expandAliases(const std::vector<std::string>& patternedAliases);
67+
} // namespace o2::dcs
68+
69+
#endif
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef O2_DCS_DATAPOINT_CREATOR_H
12+
#define O2_DCS_DATAPOINT_CREATOR_H
13+
14+
#include "DataPointCompositeObject.h"
15+
16+
namespace o2::dcs
17+
{
18+
/**
19+
* createDataPointCompositeObject is a convenience function to
20+
* simplify the creation of a DataPointCompositeObject.
21+
*
22+
* @param alias the DataPoint alias name (max 56 characters)
23+
* @param val the value of the datapoint
24+
* @param flags value for ADAPOS flags.
25+
* @param milliseconds value for milliseconds.
26+
* @param seconds value for seconds.
27+
*
28+
* @returns a DataPointCompositeObject
29+
*
30+
* The actual DeliveryType of the returned
31+
* DataPointCompositeObject is deduced from the type of val.
32+
*
33+
* Note that only a few relevant specialization are actually provided
34+
*
35+
* - T=int32_t : DeliveryType = RAW_INT
36+
* - T=uint32_t : DeliveryType = RAW_UINT
37+
* - T=double : DeliveryType = RAW_DOUBLE
38+
* - T=bool : DeliveryType = RAW_BOOL
39+
* - T=char : DeliveryType = RAW_CHAR
40+
* - T=std::string : DeliveryType = RAW_STRING
41+
*
42+
*/
43+
template <typename T>
44+
o2::dcs::DataPointCompositeObject createDataPointCompositeObject(const std::string& alias, T val, uint32_t seconds, uint16_t msec, uint16_t flags = 0);
45+
} // namespace o2::dcs
46+
47+
#endif
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef O2_DCS_DATAPOINT_GENERATOR_H
12+
#define O2_DCS_DATAPOINT_GENERATOR_H
13+
14+
#include "DetectorsDCS/DeliveryType.h"
15+
#include "DetectorsDCS/DataPointCompositeObject.h"
16+
#include <vector>
17+
18+
namespace o2::dcs
19+
{
20+
/**
21+
* Generate random data points, uniformly distributed between two values.
22+
*
23+
* @tparam T the type of value of the data points to be generated. Only
24+
* a few types are supported : double, uint32_t, int32_t, char, bool
25+
*
26+
* @param aliases the list of aliases to be generated. Those can use
27+
* patterns that will be expanded, @see AliasExpander
28+
* @param minValue the minimum value of the values to be generated
29+
* @param maxValue the maximum value of the values to be generated
30+
* @param refDate the date to be associated with all data points
31+
* in `%Y-%b-%d %H:%M:%S` format. If refDate="" the current date is used.
32+
*
33+
* @returns a vector of DataPointCompositeObject objects
34+
*/
35+
template <typename T>
36+
std::vector<DataPointCompositeObject> generateRandomDataPoints(const std::vector<std::string>& aliases,
37+
T min,
38+
T max,
39+
std::string refDate = "");
40+
41+
} // namespace o2::dcs
42+
43+
#endif

0 commit comments

Comments
 (0)