Skip to content

Commit 0faa89d

Browse files
Implementation of parsing of LHC-IF file
Parser Workflow and data type space checker clang-format remove file added by mistake
1 parent 98bc1f3 commit 0faa89d

14 files changed

Lines changed: 627 additions & 2 deletions

File tree

DataFormats/Parameters/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
# or submit itself to any jurisdiction.
1111

1212
o2_add_library(DataFormatsParameters
13-
SOURCES src/GRPObject.cxx
13+
SOURCES src/GRPObject.cxx
14+
src/LHCIFData.cxx
1415
PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants
1516
O2::CommonTypes
1617
O2::DetectorsCommonDataFormats)
1718

1819
o2_target_root_dictionary(DataFormatsParameters
19-
HEADERS include/DataFormatsParameters/GRPObject.h
20+
HEADERS include/DataFormatsParameters/GRPObject.h
21+
include/DataFormatsParameters/LHCIFData.h
2022
LINKDEF src/ParametersDataLinkDef.h)
2123
# note we are explicitely giving the LINKDEF parameter as the LinkDef does not
2224
# follow the usual naming scheme [module]LinkDef.h
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
12+
/// \file LHCIFData.h
13+
/// \brief container for the LHC InterFace data
14+
15+
#ifndef O2_GRP_LHCIFDATA_H
16+
#define O2_GRP_LHCIFDATA_H
17+
18+
#include <Rtypes.h>
19+
#include <string>
20+
#include <cstdint>
21+
22+
namespace o2
23+
{
24+
namespace parameters
25+
{
26+
27+
class LHCIFData
28+
{
29+
public:
30+
LHCIFData() = default;
31+
~LHCIFData() = default;
32+
33+
std::pair<float, int32_t> getBeamEnergy() const { return mBeamEnergy; }
34+
std::pair<float, std::string> getFillNumber() const { return mFillNumber; }
35+
std::pair<float, std::string> getInjectionSchema() const { return mInjectionSchema; }
36+
std::pair<float, int32_t> getAtomicNumberB1() const { return mAtomicNumberB1; }
37+
std::pair<float, int32_t> getAtomicNumberB2() const { return mAtomicNumberB2; }
38+
39+
int32_t getBeamEnergyVal() const { return mBeamEnergy.second; }
40+
std::string getFillNumberVal() const { return mFillNumber.second; }
41+
std::string getInjectionSchemaVal() const { return mInjectionSchema.second; }
42+
int32_t getAtomicNumberB1Val() const { return mAtomicNumberB1.second; }
43+
int32_t getAtomicNumberB2Val() const { return mAtomicNumberB2.second; }
44+
45+
float getBeamEnergyTime() const { return mBeamEnergy.first; }
46+
float getFillNumberTime() const { return mFillNumber.first; }
47+
float getInjectionSchemaTime() const { return mInjectionSchema.first; }
48+
float getAtomicNumberB1Time() const { return mAtomicNumberB1.first; }
49+
float getAtomicNumberB2Time() const { return mAtomicNumberB2.first; }
50+
51+
void setBeamEnergy(std::pair<float, int32_t> p) { mBeamEnergy = p; }
52+
void setFillNumber(std::pair<float, std::string> p) { mFillNumber = p; }
53+
void setInjectionSchema(std::pair<float, std::string> p) { mInjectionSchema = p; }
54+
void setAtomicNumberB1(std::pair<float, int32_t> p) { mAtomicNumberB1 = p; }
55+
void setAtomicNumberB2(std::pair<float, int32_t> p) { mAtomicNumberB2 = p; }
56+
57+
void setBeamEnergy(float t, int32_t v) { mBeamEnergy = std::make_pair(t, v); }
58+
void setFillNumber(float t, std::string v) { mFillNumber = std::make_pair(t, v); }
59+
void setInjectionSchema(float t, std::string v) { mInjectionSchema = std::make_pair(t, v); }
60+
void setAtomicNumberB1(float t, int32_t v) { mAtomicNumberB1 = std::make_pair(t, v); }
61+
void setAtomicNumberB2(float t, int32_t v) { mAtomicNumberB2 = std::make_pair(t, v); }
62+
63+
private:
64+
std::pair<float, int32_t> mBeamEnergy;
65+
std::pair<float, std::string> mFillNumber;
66+
std::pair<float, std::string> mInjectionSchema;
67+
std::pair<float, int32_t> mAtomicNumberB1;
68+
std::pair<float, int32_t> mAtomicNumberB2;
69+
70+
ClassDefNV(LHCIFData, 1);
71+
};
72+
} // namespace parameters
73+
} // namespace o2
74+
#endif
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
12+
/// \file LHCIFData.cxx
13+
/// \brief Implementation of the LHC InterFace data
14+
15+
#include "DataFormatsParameters/LHCIFData.h"

DataFormats/Parameters/src/ParametersDataLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
#pragma link off all functions;
2525

2626
#pragma link C++ class o2::parameters::GRPObject + ;
27+
#pragma link C++ class o2::parameters::LHCIFData + ;
2728

2829
#endif

Detectors/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@ if(ENABLE_UPGRADES)
5555
else()
5656
message(STATUS "Not building detectors for upgrades")
5757
endif()
58+
59+
add_subdirectory(GRP)

Detectors/GRP/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
12+
add_subdirectory(calibration)
13+
add_subdirectory(workflows)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
12+
o2_add_library(GRPCalibration
13+
TARGETVARNAME targetName
14+
SOURCES src/LHCIFfileReader.cxx
15+
PUBLIC_LINK_LIBRARIES Microsoft.GSL::GSL
16+
O2::Framework)
17+
18+
o2_target_root_dictionary(GRPCalibration
19+
HEADERS include/GRPCalibration/LHCIFfileReader.h)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
12+
#ifndef GRP_LHCIF_FILE_READER_H_
13+
#define GRP_LHCIF_FILE_READER_H_
14+
15+
#include "Rtypes.h"
16+
#include <gsl/span>
17+
#include "Framework/Logger.h"
18+
#include <boost/tokenizer.hpp>
19+
#include <boost/lexical_cast.hpp>
20+
21+
/// @brief Class to read the LHC InterFace file coming from the DCS filepush service
22+
23+
namespace o2
24+
{
25+
namespace grp
26+
{
27+
class LHCIFfileReader
28+
{
29+
public:
30+
LHCIFfileReader() = default; // default constructor
31+
~LHCIFfileReader() = default; // default destructor
32+
33+
void loadLHCIFfile(const char* fileName); // load LHCIF file
34+
void loadLHCIFfile(gsl::span<const char> configBuf); // load LHCIF file from buffer
35+
template <typename T>
36+
void readValue(const char* alias, std::string& type, int& nel, int& nmeas, std::vector<std::pair<float, std::vector<T>>>& meas);
37+
38+
private:
39+
std::string mFileBuffStr; // buffer containing content of LHC IF file
40+
41+
ClassDefNV(LHCIFfileReader, 1);
42+
};
43+
44+
template <typename T>
45+
void LHCIFfileReader::readValue(const char* alias, std::string& type, int& nele, int& nmeas, std::vector<std::pair<float, std::vector<T>>>& meas)
46+
{
47+
// look for value 'value' in the string from the LHC
48+
49+
auto posStart = mFileBuffStr.find(alias);
50+
if (posStart == std::string::npos) {
51+
LOG(INFO) << alias << " not found in LHC IF file";
52+
return;
53+
}
54+
auto posEnd = mFileBuffStr.find("\n", posStart);
55+
LOG(DEBUG) << "posStart = " << posStart << ", posEnd = " << posEnd;
56+
if (posEnd == std::string::npos) {
57+
posEnd = mFileBuffStr.size();
58+
}
59+
std::string subStr = mFileBuffStr.substr(posStart, posEnd - posStart);
60+
LOG(DEBUG) << "subStr = " << subStr;
61+
boost::char_separator<char> sep("\t");
62+
boost::tokenizer<boost::char_separator<char>> tokens(subStr, sep);
63+
std::vector<std::string> tokensStr{begin(tokens), end(tokens)};
64+
LOG(DEBUG) << "size of tokensStr = " << tokensStr.size();
65+
if (tokensStr.size() < 5) {
66+
LOG(FATAL) << "Number of tokens too small: " << tokensStr.size() << ", should be at 5 (alias, type, nelements, value(s), timestamp(s)";
67+
}
68+
boost::char_separator<char> sep_type(":");
69+
boost::tokenizer<boost::char_separator<char>> tokens_type(tokensStr[1], sep_type);
70+
std::vector<std::string> tokensStr_type{begin(tokens_type), end(tokens_type)};
71+
LOG(DEBUG) << "size of tokensStr_type = " << tokensStr_type.size();
72+
73+
type = tokensStr_type[0];
74+
LOG(DEBUG) << "type = " << type;
75+
76+
nele = std::stoi(tokensStr_type[1]); // number of elements per measurement
77+
nmeas = std::stoi(tokensStr[2]); // number of measurements
78+
LOG(DEBUG) << "nele = " << nele << ", nmeas = " << nmeas;
79+
int shift = 3; // number of tokens that are not measurments (alias, type, number of measurements)
80+
if ((tokensStr.size() - shift) != (nele + 1) * nmeas) { // +1 to account for the timestamp
81+
LOG(FATAL) << "Wrong number of pairs (value(s), timestamp): " << tokensStr.size() - 3 << ", should be " << (nele + 1) * nmeas;
82+
}
83+
meas.reserve(nmeas);
84+
85+
for (int idx = 0; idx < nmeas; ++idx) {
86+
std::vector<T> vect;
87+
vect.reserve(nele);
88+
if constexpr (std::is_same<T, int32_t>::value) {
89+
if (type == "i" || type == "b") {
90+
for (int iele = 0; iele < nele; ++iele) {
91+
LOG(INFO) << alias << ": value int/bool = " << tokensStr[shift + iele];
92+
vect.emplace_back(std::stoi(tokensStr[shift + iele]));
93+
}
94+
} else {
95+
LOG(FATAL) << "templated function called with wrong type, should be int32_t or bool, but it is " << type;
96+
}
97+
} else if constexpr (std::is_same<T, float>::value) {
98+
if (type == "f") {
99+
for (int iele = 0; iele < nele; ++iele) {
100+
LOG(INFO) << alias << ": value float = " << tokensStr[shift + iele];
101+
vect.emplace_back(std::stof(tokensStr[shift + iele]));
102+
}
103+
} else {
104+
LOG(FATAL) << "templated function called with wrong type, should be float";
105+
}
106+
}
107+
108+
else if constexpr (std::is_same<T, std::string>::value) {
109+
if (type == "s") {
110+
for (int iele = 0; iele < nele; ++iele) {
111+
LOG(INFO) << alias << ": value string = " << tokensStr[shift + iele];
112+
vect.emplace_back(tokensStr[shift + iele]);
113+
}
114+
} else {
115+
LOG(FATAL) << "templated function called with wrong type, should be string";
116+
}
117+
}
118+
119+
LOG(DEBUG) << "timestamp = " << std::stof(tokensStr[shift + nele]);
120+
meas.emplace_back(std::make_pair(std::stof(tokensStr[shift + nele]), vect));
121+
}
122+
}
123+
124+
} // namespace grp
125+
} // namespace o2
126+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
12+
#ifdef __CLING__
13+
14+
#pragma link off all globals;
15+
#pragma link off all classes;
16+
#pragma link off all functions;
17+
18+
#pragma link C++ class o2::grp::LHCIFfileReader + ;
19+
20+
#endif
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
12+
#include "GRPCalibration/LHCIFfileReader.h"
13+
#include "TSystem.h"
14+
#include <fstream>
15+
16+
namespace o2
17+
{
18+
namespace grp
19+
{
20+
21+
void LHCIFfileReader::loadLHCIFfile(const char* fileName)
22+
{
23+
// load the LHC IF file into a string
24+
char* expandedFileName = gSystem->ExpandPathName(fileName);
25+
std::ifstream ifs(expandedFileName);
26+
if (ifs) {
27+
ifs.seekg(0, std::ios::end);
28+
const auto size = ifs.tellg();
29+
mFileBuffStr.resize(size);
30+
ifs.seekg(0);
31+
ifs.read(&mFileBuffStr[0], size);
32+
ifs.close();
33+
}
34+
}
35+
36+
//_________________________________________________________________
37+
38+
void LHCIFfileReader::loadLHCIFfile(gsl::span<const char> configBuf)
39+
{
40+
// load the LHC IF file into a string from a buffer
41+
mFileBuffStr.assign(configBuf.data());
42+
}
43+
44+
//_________________________________________________________________
45+
46+
} // end namespace grp
47+
} // end namespace o2

0 commit comments

Comments
 (0)