-
Notifications
You must be signed in to change notification settings - Fork 510
Implementation of parsing of LHC-IF file #7148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
DataFormats/Parameters/include/DataFormatsParameters/LHCIFData.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,3 +55,5 @@ if(ENABLE_UPGRADES) | |
| else() | ||
| message(STATUS "Not building detectors for upgrades") | ||
| endif() | ||
|
|
||
| add_subdirectory(GRP) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
121
Detectors/GRP/calibration/include/GRPCalibration/LHCIFfileReader.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]); | ||
|
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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.