13#include "CoralBase/Attribute.h"
14#include "CoralBase/AttributeListSpecification.h"
15#include "GaudiKernel/ConcurrencyFlags.h"
25 ATH_MSG_ERROR(
"There's no point in setting up this algorithm if neither A or B Lines shall be processed");
26 return StatusCode::FAILURE;
35 return StatusCode::SUCCESS;
43 if (writeALineHandle.
isValid()) {
45 <<
". In theory this should not be called, but may happen"
46 <<
" if multiple concurrent events are being processed out of order.");
47 return StatusCode::SUCCESS;
56 if (writeBLineHandle.
isValid()) {
58 <<
". In theory this should not be called, but may happen"
59 <<
" if multiple concurrent events are being processed out of order.");
60 return StatusCode::SUCCESS;
64 auto writeALineCdo{std::make_unique<ALineContainer>()};
65 auto writeBLineCdo{std::make_unique<BLineContainer>()};
72 if (!inStream.good()) {
74 return StatusCode::FAILURE;
83 return StatusCode::SUCCESS;
85template <
class ContType>
88 std::unique_ptr<ContType>&&
container)
const {
89 if (writeKey.
empty()) {
90 ATH_MSG_DEBUG(
"The key of type "<<
typeid(ContType).name()<<
" is not set. Assume that nothing shall be written.");
91 return StatusCode::SUCCESS;
99 ATH_MSG_FATAL(
"Failed to load alignment folder "<<key.fullKey());
100 return StatusCode::FAILURE;
102 ATH_MSG_INFO(
"Attach new dependency from <"<<readHandle.
key()<<
"> to the "<<
typeid(ContType).name()<<
". IOV: "<<readHandle.
getRange());
106 return StatusCode::SUCCESS;
115 ATH_MSG_FATAL(
"Failed to load alignment folder "<<key.fullKey());
116 return StatusCode::FAILURE;
122 const coral::AttributeList& atr = itr->second;
124 if (atr[
"data"].specification().
type() ==
typeid(coral::Blob)) {
128 return StatusCode::FAILURE;
131 data = *(
static_cast<const std::string*
>((atr[
"data"]).addressOfData()));
133 nlohmann::json lines;
137 nlohmann::json j = nlohmann::json::parse(
data);
138 lines = j[
"corrections"];
146 return StatusCode::SUCCESS;
153 for (
auto& corr : lines.items()) {
154 nlohmann::json line = corr.value();
157 const std::string stationType = line[
"typ"];
160 const int multiLayer = line[
"job"];
163 if (stationType[0] ==
'M') {
169 }
else if (stationType[0] ==
'S') {
175 id =
m_idHelperSvc->stgcIdHelper().multilayerID(
id, multiLayer);
176 }
else if (stationType[0] ==
'T') {
184 if (multiLayer != 0) {
186 stEta =
stationEta > 0 ? multiLayer: - multiLayer;
188 id =
m_idHelperSvc->tgcIdHelper().elementID(stationType, stEta, stPhi);
189 }
else if (stationType[0] ==
'C') {
195 }
else if (stationType.substr(0, 3) ==
"BML" && std::abs(
stationEta) == 7) {
217 newALine.
setParameters(line[
"svalue"], line[
"zvalue"], line[
"tvalue"],
218 line[
"tsv"], line[
"tzv"], line[
"ttv"]);
219 auto aLineInsert = writeALineCdo.insert(newALine);
220 if (newALine && !aLineInsert.second) {
222 <<
" because "<<(*aLineInsert.first)<<
" has been added before");
226 if (line.find(
"bz") == line.end()) {
231 line[
"sp"], line[
"sn"], line[
"tw"],
232 line[
"pg"], line[
"tr"], line[
"eg"],
233 line[
"ep"], line[
"en"]);
236 ATH_MSG_VERBOSE(
" HardwareChamberName " <<
static_cast<std::string
>(line[
"hwElement"]));
237 auto bLineInsert = writeBLineCdo.insert(newBLine);
238 if (newBLine && !bLineInsert.second){
240 <<
" because "<<(*bLineInsert.first)<<
" has been added before.");
243 return StatusCode::SUCCESS;
247 bool loadBLines)
const {
250 constexpr std::string_view delimiter{
"\n"};
252 json = nlohmann::json::array();
254 for (
const std::string& blobline : lines) {
256 constexpr std::string_view delimiter{
":"};
260 if (tokens.empty()) {
262 return StatusCode::FAILURE;
264 const std::string_view &
type = tokens[0];
266 if (
type[0] ==
'#') {
277 if (
type.compare(0, 4,
"Corr") == 0) {
278 constexpr std::string_view delimiter{
" "};
280 if (tokens.size() != 25) {
281 ATH_MSG_FATAL(
"Invalid length in string retrieved. String length is " << tokens.size());
282 return StatusCode::FAILURE;
287 line[
"typ"] = std::string(tokens[ival++]);
319 line[
"hwElement"] = std::string(tokens[ival++]);
321 json.push_back(std::move(line));
324 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
std::set< ALinePar, std::less<> > ALineContainer
std::set< BLinePar, std::less<> > BLineContainer
char data[hepevt_bytes_allocation_ATLAS]
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
void setParameters(float s, float z, float t, float rotS, float rotZ, float rotT)
void setParameters(float bz, float bp, float bn, float sp, float sn, float tw, float pg, float tr, float eg, float ep, float en)
Cast the parameter to an unsigned int.
ChanAttrListMap::const_iterator const_iterator
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
void setIdentifier(const Identifier &id)
Setters and getters for the Athena Identifier.
void setAmdbId(const std::string &stName, int stEta, int stPhi, int stJob)
AMDB identifiers. They're often not the same as the ATLAS ones (TGCs)
Gaudi::Property< bool > m_newFormat2020
StatusCode loadCoolFolder(const EventContext &ctx, const SG::ReadCondHandleKey< CondAttrListCollection > &key, ALineContainer &writeALineCdo, BLineContainer &writeBLineCdo) const
Retrieves the alignment parameters from a COOL folder.
Gaudi::Property< bool > m_loadALines
StatusCode parseDataFromJSON(const nlohmann::json &lines, ALineContainer &writeALineCdo, BLineContainer &writeBLineCdo) const
Parse the JSON blob to fill the A & B Line containers.
StatusCode loadDataFromLegacy(const std::string &data, nlohmann::json &json, bool loadBLines) const
Load the Alignment data from the legacy format where the channels are parsed line wise The data is th...
StatusCode writeContainer(const EventContext &ctx, const SG::WriteCondHandleKey< ContType > &writeKey, std::unique_ptr< ContType > &&container) const
Attaches the dependencies of the Alignment keys onto the A & Bline container.
SG::WriteCondHandleKey< ALineContainer > m_writeALineKey
SG::ReadCondHandleKeyArray< CondAttrListCollection > m_alignKeys
Gaudi::Property< bool > m_loadBLines
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< std::string > m_readFromJSON
Load the alignment parameters from a JSON file.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::WriteCondHandleKey< BLineContainer > m_writeBLineKey
const std::string & key() const
const EventIDRange & getRange()
bool empty() const
Test if the key is blank.
void addDependency(const EventIDRange &range)
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
bool readBlobAsString(const coral::Blob &, std::string &)
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.
double atof(std::string_view str)
Converts a string into a double / float.
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
int stationPhiTGC(std::string_view stName, int fi, int zi_input)
Converts the AMDB phi index to the Identifier phi Index.
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.