Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 57 additions & 28 deletions Detectors/DCS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,64 @@
# granted to it by virtue of its status as an Intergovernmental Organization or
# submit itself to any jurisdiction.

o2_add_library(DetectorsDCS
TARGETVARNAME targetName
SOURCES src/Clock.cxx
src/DataPointCompositeObject.cxx
src/DataPointIdentifier.cxx
src/DataPointValue.cxx
src/DeliveryType.cxx
src/GenericFunctions.cxx
src/StringUtils.cxx
src/DCSProcessor.cxx
PUBLIC_LINK_LIBRARIES O2::Headers
O2::CommonUtils
O2::CCDB
O2::DetectorsCalibration
ms_gsl::ms_gsl)
o2_add_library(
DetectorsDCS
TARGETVARNAME targetName
SOURCES src/AliasExpander.cxx
src/DCSProcessor.cxx
src/DataPointCompositeObject.cxx
src/DataPointCreator.cxx
src/DataPointGenerator.cxx
src/DataPointIdentifier.cxx
src/DataPointValue.cxx
src/DeliveryType.cxx
src/GenericFunctions.cxx
src/StringUtils.cxx
src/Clock.cxx
PUBLIC_LINK_LIBRARIES O2::Headers O2::CommonUtils O2::CCDB
O2::DetectorsCalibration ms_gsl::ms_gsl)

o2_target_root_dictionary(DetectorsDCS
HEADERS include/DetectorsDCS/DataPointCompositeObject.h
include/DetectorsDCS/DataPointIdentifier.h
include/DetectorsDCS/DataPointValue.h
include/DetectorsDCS/DCSProcessor.h)
o2_target_root_dictionary(
DetectorsDCS
HEADERS include/DetectorsDCS/DataPointCompositeObject.h
include/DetectorsDCS/DataPointIdentifier.h
include/DetectorsDCS/DataPointValue.h
include/DetectorsDCS/DCSProcessor.h)

o2_add_executable(dcs-data-workflow
COMPONENT_NAME dcs
SOURCES testWorkflow/dcs-data-workflow.cxx
PUBLIC_LINK_LIBRARIES O2::Framework
O2::DetectorsDCS)
o2_add_executable(
data-workflow
COMPONENT_NAME dcs
SOURCES testWorkflow/dcs-data-workflow.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)

if (OpenMP_CXX_FOUND)
target_compile_definitions(${targetName} PRIVATE WITH_OPENMP)
target_link_libraries(${targetName} PRIVATE OpenMP::OpenMP_CXX)
o2_add_executable(
random-data-workflow
COMPONENT_NAME dcs
SOURCES testWorkflow/dcs-random-data-workflow.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)

if(OpenMP_CXX_FOUND)
target_compile_definitions(${targetName} PRIVATE WITH_OPENMP)
target_link_libraries(${targetName} PRIVATE OpenMP::OpenMP_CXX)
endif()

if(BUILD_TESTING)
o2_add_test(
data-point-types
SOURCES test/testDataPointTypes.cxx
COMPONENT_NAME dcs
LABELS "dcs"
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)
o2_add_test(
alias-expander
SOURCES test/testAliasExpander.cxx
COMPONENT_NAME dcs
LABELS "dcs"
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)
o2_add_test(
data-point-generator
SOURCES test/testDataPointGenerator.cxx
COMPONENT_NAME dcs
LABELS "dcs"
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)
endif()
20 changes: 20 additions & 0 deletions Detectors/DCS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- doxy
\page refDetectorsDCS DCS
/doxy -->

# Export of DCS to CCDB

To be written

# Generating DCS aliases

For test purposes, DCS aliases can be generated making use of the helper
function `generateRandomDataPoints`. For example :

```c++
#include "DetectorsDCS/DataPointGenerator.h"
std::vector<std::string> patterns = { "DET/HV/Crate[0.9]/Channel[00.42]/vMon" };
auto dps = o2::dcs::generateRandomDataPoints(patterns,0.0,1200.0);
```

would generate 420 data points.
69 changes: 69 additions & 0 deletions Detectors/DCS/include/DetectorsDCS/AliasExpander.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef O2_DCS_ALIAS_EXPANDER_H
#define O2_DCS_ALIAS_EXPANDER_H

#include <vector>
#include <string>

namespace o2::dcs
{
/**
* expandAlias converts a single pattern into a list of strings.
*
* @param pattern a pattern is made of a number of "XX[YY]" blocks (at least one)
*
* where :
* - XX is any text
* - YY describes either a integral range or a textual list
*
* An integral range is [a..b] where the formatting of the biggest of the
* two integers a and b dictates, by default, the formatting of the output
* alias. For instance [0..3] is expanded to the set 0,1,2,3 while [00..03]
* is expanded to 00,01,02,03. If you want more control on the formatting,
* you can use a python/fmt format {} e.g. [0..15{:d}] would yields 0,1,
* 2,...,14,15 simply (no 0 filling).
*
* A textual list is simply a list of values separated by commas,
* e.g. "vMon,iMon"
*
* @returns a vector of strings containing all the possible expansions of
* the pattern. That vector is not guaranteed to be sorted.
*
* For example, pattern=DET[A,B]/Channel[000,002]/[iMon,vMon] yields :
*
* - DETA/Channel000/iMon
* - DETA/Channel001/iMon
* - DETA/Channel002/iMon
* - DETA/Channel000/vMon
* - DETA/Channel001/vMon
* - DETA/Channel002/vMon
* - DETB/Channel000/iMon
* - DETB/Channel001/iMon
* - DETB/Channel002/iMon
* - DETB/Channel000/vMon
* - DETB/Channel001/vMon
* - DETB/Channel002/vMon

*/
std::vector<std::string> expandAlias(const std::string& pattern);

/** expandAliases converts a list of patterns into a list of strings.
*
* each input pattern is treated by expandAlias()
*
* @returns a _sorted_ vector of strings containing all the possible
* expansions of the pattern.
*/
std::vector<std::string> expandAliases(const std::vector<std::string>& patternedAliases);
} // namespace o2::dcs

#endif
21 changes: 21 additions & 0 deletions Detectors/DCS/include/DetectorsDCS/DataPointCompositeObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,29 @@ struct alignas(128) DataPointCompositeObject final {
(char*)&dpcom.data.payload_pt1, 56);
}
}

/**
* The destructor for DataPointCompositeObject so it is not deleted
* and thus DataPointCompositeObject is trivially copyable
*/
~DataPointCompositeObject() noexcept = default;
ClassDefNV(DataPointCompositeObject, 1);
};

/**
* Return the value contained in the DataPointCompositeObject, if possible.
*
* @tparam T the expected type of the value
*
* @param dpcom the DataPointCompositeObject the value is extracted from
*
* @returns the value of the data point
*
* @throws if the DeliveryType of the data point is not compatible with T
*/
template <typename T>
T getValue(const DataPointCompositeObject& dpcom);

} // namespace dcs
} // namespace o2

Expand Down
47 changes: 47 additions & 0 deletions Detectors/DCS/include/DetectorsDCS/DataPointCreator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef O2_DCS_DATAPOINT_CREATOR_H
#define O2_DCS_DATAPOINT_CREATOR_H

#include "DataPointCompositeObject.h"

namespace o2::dcs
{
/**
* createDataPointCompositeObject is a convenience function to
* simplify the creation of a DataPointCompositeObject.
*
* @param alias the DataPoint alias name (max 56 characters)
* @param val the value of the datapoint
* @param flags value for ADAPOS flags.
* @param milliseconds value for milliseconds.
* @param seconds value for seconds.
*
* @returns a DataPointCompositeObject
*
* The actual DeliveryType of the returned
* DataPointCompositeObject is deduced from the type of val.
*
* Note that only a few relevant specialization are actually provided
*
* - T=int32_t : DeliveryType = RAW_INT
* - T=uint32_t : DeliveryType = RAW_UINT
* - T=double : DeliveryType = RAW_DOUBLE
* - T=bool : DeliveryType = RAW_BOOL
* - T=char : DeliveryType = RAW_CHAR
* - T=std::string : DeliveryType = RAW_STRING
*
*/
template <typename T>
o2::dcs::DataPointCompositeObject createDataPointCompositeObject(const std::string& alias, T val, uint32_t seconds, uint16_t msec, uint16_t flags = 0);
} // namespace o2::dcs

#endif
43 changes: 43 additions & 0 deletions Detectors/DCS/include/DetectorsDCS/DataPointGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef O2_DCS_DATAPOINT_GENERATOR_H
#define O2_DCS_DATAPOINT_GENERATOR_H

#include "DetectorsDCS/DeliveryType.h"
#include "DetectorsDCS/DataPointCompositeObject.h"
#include <vector>

namespace o2::dcs
{
/**
* Generate random data points, uniformly distributed between two values.
*
* @tparam T the type of value of the data points to be generated. Only
* a few types are supported : double, uint32_t, int32_t, char, bool
*
* @param aliases the list of aliases to be generated. Those can use
* patterns that will be expanded, @see AliasExpander
* @param minValue the minimum value of the values to be generated
* @param maxValue the maximum value of the values to be generated
* @param refDate the date to be associated with all data points
* in `%Y-%b-%d %H:%M:%S` format. If refDate="" the current date is used.
*
* @returns a vector of DataPointCompositeObject objects
*/
template <typename T>
std::vector<DataPointCompositeObject> generateRandomDataPoints(const std::vector<std::string>& aliases,
T min,
T max,
std::string refDate = "");

} // namespace o2::dcs

#endif
2 changes: 1 addition & 1 deletion Detectors/DCS/include/DetectorsDCS/DataPointValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ struct alignas(64) DataPointValue final {
*/
inline std::unique_ptr<std::string> get_timestamp() const noexcept
{
#ifdef __linux__
#if defined(__linux__) || defined(__APPLE__)
// time_t should be uint64_t (compatible) on 64-bit Linux platforms:
char buffer[17];
std::time_t ts((uint64_t)sec);
Expand Down
Loading