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
4 changes: 4 additions & 0 deletions DataFormats/Parameters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@

o2_add_library(DataFormatsParameters
SOURCES src/GRPObject.cxx
src/LHCIFData.cxx
PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants
O2::CommonTypes
O2::DetectorsCommonDataFormats)

o2_target_root_dictionary(DataFormatsParameters
HEADERS include/DataFormatsParameters/GRPObject.h
include/DataFormatsParameters/LHCIFData.h
LINKDEF src/ParametersDataLinkDef.h)


# note we are explicitely giving the LINKDEF parameter as the LinkDef does not
# follow the usual naming scheme [module]LinkDef.h
#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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.

/// \file LHCIFData.h
/// \brief container for the LHC InterFace data

#ifndef O2_GRP_LHCIFDATA_H
#define O2_GRP_LHCIFDATA_H

#include <Rtypes.h>
#include <string>
#include <cstdint>

namespace o2
{
namespace parameters
{

class LHCIFData
{
public:
LHCIFData() = default;
~LHCIFData() = default;

std::pair<long, int32_t> getBeamEnergy() const { return mBeamEnergy; }
std::pair<long, int32_t> getFillNumber() const { return mFillNumber; }
std::pair<long, std::string> getInjectionScheme() const { return mInjectionScheme; }
std::pair<long, int32_t> getAtomicNumberB1() const { return mAtomicNumberB1; }
std::pair<long, int32_t> getAtomicNumberB2() const { return mAtomicNumberB2; }

int32_t getBeamEnergyVal() const { return mBeamEnergy.second; }
int32_t getFillNumberVal() const { return mFillNumber.second; }
std::string getInjectionSchemeVal() const { return mInjectionScheme.second; }
int32_t getAtomicNumberB1Val() const { return mAtomicNumberB1.second; }
int32_t getAtomicNumberB2Val() const { return mAtomicNumberB2.second; }

long getBeamEnergyTime() const { return mBeamEnergy.first; }
long getFillNumberTime() const { return mFillNumber.first; }
long getInjectionSchemeTime() const { return mInjectionScheme.first; }
long getAtomicNumberB1Time() const { return mAtomicNumberB1.first; }
long getAtomicNumberB2Time() const { return mAtomicNumberB2.first; }

void setBeamEnergy(std::pair<long, int32_t> p) { mBeamEnergy = p; }
void setFillNumber(std::pair<long, int32_t> p) { mFillNumber = p; }
void setInjectionScheme(std::pair<long, std::string> p) { mInjectionScheme = p; }
void setAtomicNumberB1(std::pair<long, int32_t> p) { mAtomicNumberB1 = p; }
void setAtomicNumberB2(std::pair<long, int32_t> p) { mAtomicNumberB2 = p; }

void setBeamEnergy(long t, int32_t v) { mBeamEnergy = std::make_pair(t, v); }
void setFillNumber(long t, int32_t v) { mFillNumber = std::make_pair(t, v); }
void setInjectionScheme(long t, std::string v) { mInjectionScheme = std::make_pair(t, v); }
void setAtomicNumberB1(long t, int32_t v) { mAtomicNumberB1 = std::make_pair(t, v); }
void setAtomicNumberB2(long t, int32_t v) { mAtomicNumberB2 = std::make_pair(t, v); }

private:
std::pair<long, int32_t> mBeamEnergy;
std::pair<long, int32_t> mFillNumber;
std::pair<long, std::string> mInjectionScheme;
std::pair<long, int32_t> mAtomicNumberB1;
std::pair<long, int32_t> mAtomicNumberB2;

ClassDefNV(LHCIFData, 1);
};
} // namespace parameters
} // namespace o2
#endif
15 changes: 15 additions & 0 deletions DataFormats/Parameters/src/LHCIFData.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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.

/// \file LHCIFData.cxx
/// \brief Implementation of the LHC InterFace data

#include "DataFormatsParameters/LHCIFData.h"
2 changes: 2 additions & 0 deletions DataFormats/Parameters/src/ParametersDataLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
#pragma link off all functions;

#pragma link C++ class o2::parameters::GRPObject + ;
#pragma link C++ class o2::parameters::LHCIFData + ;
#pragma link C++ class std::pair < long, std::string> + ;

#endif
2 changes: 2 additions & 0 deletions Detectors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ if(ENABLE_UPGRADES)
else()
message(STATUS "Not building detectors for upgrades")
endif()

add_subdirectory(GRP)
35 changes: 26 additions & 9 deletions Detectors/DCS/testWorkflow/src/dcs-config-proxy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using namespace o2::framework;
using DetID = o2::detectors::DetID;

std::array<o2::header::DataOrigin, 1> exceptionsDetID{"GRP"};

void sendAnswer(const std::string& what, const std::string& ack_chan, FairMQDevice& device)
{
if (!ack_chan.empty()) {
Expand All @@ -44,10 +46,21 @@ void sendAnswer(const std::string& what, const std::string& ack_chan, FairMQDevi
}
}

auto getDetID(const std::string& filename)
auto getDataOriginFromFilename(const std::string& filename)
{
// assume the filename start with detector name
return DetID::nameToID(filename.substr(0, 3).c_str(), DetID::First);
auto dIDStr = filename.substr(0, 3);
auto dID = DetID::nameToID(dIDStr.c_str(), DetID::First);
o2::header::DataOrigin dataOrigin;
if (dID < 0) {
for (auto& el : exceptionsDetID) {
if (el.as<std::string>() == dIDStr) {
return el;
}
}
return o2::header::gDataOriginInvalid;
}
return DetID(dID).getDataOrigin();
}

InjectorFunction dcs2dpl(const std::string& acknowledge)
Expand All @@ -65,15 +78,15 @@ InjectorFunction dcs2dpl(const std::string& acknowledge)
std::string filename{static_cast<const char*>(parts.At(0)->GetData()), parts.At(0)->GetSize()};
size_t filesize = parts.At(1)->GetSize();
LOG(INFO) << "received file " << filename << " of size " << filesize;
int dID = getDetID(filename);
if (dID < 0) {
o2::header::DataOrigin dataOrigin = getDataOriginFromFilename(filename);
if (dataOrigin == o2::header::gDataOriginInvalid) {
LOG(ERROR) << "unknown detector for " << filename;
sendAnswer("error1: unrecognized filename", acknowledge, device);
return;
}

o2::header::DataHeader hdrF("DCS_CONFIG_FILE", DetID(dID).getDataOrigin(), 0);
o2::header::DataHeader hdrN("DCS_CONFIG_NAME", DetID(dID).getDataOrigin(), 0);
o2::header::DataHeader hdrF("DCS_CONFIG_FILE", dataOrigin, 0);
o2::header::DataHeader hdrN("DCS_CONFIG_NAME", dataOrigin, 0);
OutputSpec outsp{hdrN.dataOrigin, hdrN.dataDescription, hdrN.subSpecification};
auto channel = channelRetriever(outsp, *timesliceId);
if (channel.empty()) {
Expand All @@ -84,14 +97,14 @@ InjectorFunction dcs2dpl(const std::string& acknowledge)

hdrN.tfCounter = *timesliceId; // this also
hdrN.payloadSerializationMethod = o2::header::gSerializationMethodNone;
hdrN.splitPayloadParts = 1;
hdrN.splitPayloadIndex = 1;
hdrN.splitPayloadParts = 2;
hdrN.splitPayloadIndex = 0;
hdrN.payloadSize = parts.At(0)->GetSize();
hdrN.firstTForbit = 0; // this should be irrelevant for DCS

hdrF.tfCounter = *timesliceId; // this also
hdrF.payloadSerializationMethod = o2::header::gSerializationMethodNone;
hdrF.splitPayloadParts = 1;
hdrF.splitPayloadParts = 2;
hdrF.splitPayloadIndex = 1;
hdrF.payloadSize = filesize;
hdrF.firstTForbit = 0; // this should be irrelevant for DCS
Expand Down Expand Up @@ -164,6 +177,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& config)
dcsOutputs.emplace_back(DetID(id).getDataOrigin(), "DCS_CONFIG_FILE", 0, Lifetime::Timeframe);
Comment thread
chiarazampolli marked this conversation as resolved.
dcsOutputs.emplace_back(DetID(id).getDataOrigin(), "DCS_CONFIG_NAME", 0, Lifetime::Timeframe);
}
for (auto& el : exceptionsDetID) {
dcsOutputs.emplace_back(el, "DCS_CONFIG_FILE", 0, Lifetime::Timeframe);
dcsOutputs.emplace_back(el, "DCS_CONFIG_NAME", 0, Lifetime::Timeframe);
}

DataProcessorSpec dcsConfigProxy = specifyExternalFairMQDeviceProxy(
devName.c_str(),
Expand Down
13 changes: 13 additions & 0 deletions Detectors/GRP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
# All rights not expressly granted are reserved.
#
# This software is distributed under the terms of the GNU General Public
# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
#
# 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.

add_subdirectory(calibration)
add_subdirectory(workflows)
19 changes: 19 additions & 0 deletions Detectors/GRP/calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
# All rights not expressly granted are reserved.
#
# This software is distributed under the terms of the GNU General Public
# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
#
# 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.

o2_add_library(GRPCalibration
TARGETVARNAME targetName
SOURCES src/LHCIFfileReader.cxx
PUBLIC_LINK_LIBRARIES Microsoft.GSL::GSL
O2::Framework)

o2_target_root_dictionary(GRPCalibration
HEADERS include/GRPCalibration/LHCIFfileReader.h)
121 changes: 121 additions & 0 deletions Detectors/GRP/calibration/include/GRPCalibration/LHCIFfileReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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 GRP_LHCIF_FILE_READER_H_
#define GRP_LHCIF_FILE_READER_H_

#include "Rtypes.h"
#include <gsl/span>
#include "Framework/Logger.h"
#include "CommonUtils/StringUtils.h"

/// @brief Class to read the LHC InterFace file coming from the DCS filepush service

namespace o2
{
namespace grp
{
class LHCIFfileReader
{
public:
LHCIFfileReader() = default; // default constructor
~LHCIFfileReader() = default; // default destructor

void loadLHCIFfile(const std::string& fileName); // load LHCIF file
void loadLHCIFfile(gsl::span<const char> configBuf); // load LHCIF file from buffer
template <typename T>
void readValue(const std::string& alias, std::string& type, int& nel, int& nmeas, std::vector<std::pair<long, std::vector<T>>>& meas);

private:
std::string mFileBuffStr; // buffer containing content of LHC IF file

ClassDefNV(LHCIFfileReader, 1);
};

template <typename T>
void LHCIFfileReader::readValue(const std::string& alias, std::string& type, int& nele, int& nmeas, std::vector<std::pair<long, std::vector<T>>>& meas)
{
// look for value 'value' in the string from the LHC

auto posStart = mFileBuffStr.find(alias);
if (posStart == std::string::npos) {
LOG(INFO) << alias << " not found in LHC IF file";
return;
}
auto posEnd = mFileBuffStr.find("\n", posStart);
LOG(DEBUG) << "posStart = " << posStart << ", posEnd = " << posEnd;
if (posEnd == std::string::npos) {
posEnd = mFileBuffStr.size();
}
std::string subStr = mFileBuffStr.substr(posStart, posEnd - posStart);
LOG(DEBUG) << "subStr = " << subStr;
auto tokensStr = o2::utils::Str::tokenize(subStr, '\t');
LOG(DEBUG) << "size of tokensStr = " << tokensStr.size();
if (tokensStr.size() < 5) {
LOG(FATAL) << "Number of tokens too small: " << tokensStr.size() << ", should be at 5 (alias, type, nelements, value(s), timestamp(s)";
}
auto tokensStr_type = o2::utils::Str::tokenize(tokensStr[1], ':');
LOG(DEBUG) << "size of tokensStr_type = " << tokensStr_type.size();

type = tokensStr_type[0];
LOG(DEBUG) << "type = " << type;

nele = std::stoi(tokensStr_type[1]); // number of elements per measurement
nmeas = std::stoi(tokensStr[2]); // number of measurements
LOG(DEBUG) << "nele = " << nele << ", nmeas = " << nmeas;
int shift = 3; // number of tokens that are not measurments (alias, type, number of measurements)
if ((tokensStr.size() - shift) != (nele + 1) * nmeas) { // +1 to account for the timestamp
LOG(FATAL) << "Wrong number of pairs (value(s), timestamp): " << tokensStr.size() - 3 << ", should be " << (nele + 1) * nmeas;
}
meas.reserve(nmeas);

for (int idx = 0; idx < nmeas; ++idx) {
std::vector<T> vect;
vect.reserve(nele);
if constexpr (std::is_same<T, int32_t>::value) {
if (type == "i" || type == "b") {
for (int iele = 0; iele < nele; ++iele) {
LOG(INFO) << alias << ": value int/bool = " << tokensStr[shift + iele];
vect.emplace_back(std::stoi(tokensStr[shift + iele]));
}
} else {
LOG(FATAL) << "templated function called with wrong type, should be int32_t or bool, but it is " << type;
}
} else if constexpr (std::is_same<T, float>::value) {
if (type == "f") {
for (int iele = 0; iele < nele; ++iele) {
LOG(INFO) << alias << ": value float = " << tokensStr[shift + iele];
vect.emplace_back(std::stof(tokensStr[shift + iele]));
}
} else {
LOG(FATAL) << "templated function called with wrong type, should be float";
}
}

else if constexpr (std::is_same<T, std::string>::value) {
if (type == "s") {
for (int iele = 0; iele < nele; ++iele) {
LOG(INFO) << alias << ": value string = " << tokensStr[shift + iele];
vect.emplace_back(tokensStr[shift + iele]);
}
} else {
LOG(FATAL) << "templated function called with wrong type, should be string";
}
}

LOG(DEBUG) << "timestamp = " << std::stof(tokensStr[shift + nele]);
Comment thread
chiarazampolli marked this conversation as resolved.
meas.emplace_back(std::stol(tokensStr[shift + nele]) * 1e6, vect); // measurement comes in seconds, we want it in microseconds
}
}

} // namespace grp
} // namespace o2
#endif
20 changes: 20 additions & 0 deletions Detectors/GRP/calibration/src/GRPCalibrationLinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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.

#ifdef __CLING__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class o2::grp::LHCIFfileReader + ;

#endif
Loading