13#include "CoralBase/Attribute.h"
14#include "CoralBase/AttributeListSpecification.h"
15#include "GaudiKernel/ConcurrencyFlags.h"
29 ATH_MSG_ERROR(
"There's no point in setting up this algorithm if neither A or B Lines shall be processed");
30 return StatusCode::FAILURE;
39 return StatusCode::SUCCESS;
47 if (writeALineHandle.
isValid()) {
49 <<
". In theory this should not be called, but may happen"
50 <<
" if multiple concurrent events are being processed out of order.");
51 return StatusCode::SUCCESS;
60 if (writeBLineHandle.
isValid()) {
62 <<
". In theory this should not be called, but may happen"
63 <<
" if multiple concurrent events are being processed out of order.");
64 return StatusCode::SUCCESS;
68 std::unique_ptr<ALineContainer> writeALineCdo{std::make_unique<ALineContainer>()};
69 std::unique_ptr<BLineContainer> writeBLineCdo{std::make_unique<BLineContainer>()};
76 if (!inStream.good()) {
78 return StatusCode::FAILURE;
87 return StatusCode::SUCCESS;
89template <
class ContType>
92 std::unique_ptr<ContType>&&
container)
const {
93 if (writeKey.
empty()) {
94 ATH_MSG_DEBUG(
"The key of type "<<
typeid(ContType).name()<<
" is not set. Assume that nothing shall be written.");
95 return StatusCode::SUCCESS;
103 ATH_MSG_FATAL(
"Failed to load alignment folder "<<key.fullKey());
104 return StatusCode::FAILURE;
106 ATH_MSG_INFO(
"Attach new dependency from <"<<readHandle.
key()<<
"> to the "<<
typeid(ContType).name()<<
". IOV: "<<readHandle.
getRange());
110 return StatusCode::SUCCESS;
119 ATH_MSG_FATAL(
"Failed to load alignment folder "<<key.fullKey());
120 return StatusCode::FAILURE;
126 const coral::AttributeList& atr = itr->second;
128 if (atr[
"data"].specification().
type() ==
typeid(coral::Blob)) {
132 return StatusCode::FAILURE;
135 data = *(
static_cast<const std::string*
>((atr[
"data"]).addressOfData()));
137 nlohmann::json lines;
141 nlohmann::json j = nlohmann::json::parse(
data);
142 lines = j[
"corrections"];
150 return StatusCode::SUCCESS;
157 for (
auto& corr : lines.items()) {
158 nlohmann::json line = corr.value();
161 const std::string stationType = line[
"typ"];
162 const int stationPhi = line[
"jff"];
163 const int stationEta = line[
"jzz"];
164 const int multiLayer = line[
"job"];
167 if (stationType[0] ==
'M') {
169 ATH_MSG_VERBOSE(
"No Mms defined skipping: "<<stationType<<
","<<
","<<stationEta<<
","<<stationPhi<<
","<<multiLayer);
172 id =
m_idHelperSvc->mmIdHelper().channelID(stationType, stationEta, stationPhi, multiLayer, 1, 1);
173 }
else if (stationType[0] ==
'S') {
175 ATH_MSG_VERBOSE(
"No sTgcs defined skipping: "<<stationType<<
","<<
","<<stationEta<<
","<<stationPhi<<
","<<multiLayer);
178 id =
m_idHelperSvc->stgcIdHelper().elementID(stationType, stationEta, stationPhi);
179 id =
m_idHelperSvc->stgcIdHelper().multilayerID(
id, multiLayer);
180 }
else if (stationType[0] ==
'T') {
183 ATH_MSG_VERBOSE(
"No Tgcs defined skipping: "<<stationType<<
","<<
","<<stationEta<<
","<<stationPhi);
187 int stEta = stationEta > 0 ? 1 : -1;
188 if (multiLayer != 0) {
190 stEta = stationEta > 0 ? multiLayer: - multiLayer;
192 id =
m_idHelperSvc->tgcIdHelper().elementID(stationType, stEta, stPhi);
193 }
else if (stationType[0] ==
'C') {
195 ATH_MSG_VERBOSE(
"No Cscs defined skipping: "<<stationType<<
","<<
","<<stationEta<<
","<<stationPhi);
198 id =
m_idHelperSvc->cscIdHelper().elementID(stationType, stationEta, stationPhi);
199 }
else if (stationType.substr(0, 3) ==
"BML" && std::abs(stationEta) == 7) {
201 ATH_MSG_VERBOSE(
"No Rpcs defined skipping "<<stationType<<
","<<
","<<stationEta<<
","<<stationPhi);
205 id =
m_idHelperSvc->rpcIdHelper().elementID(stationType, stationEta, stationPhi, 1);
211 <<
" eta " << stationEta
212 <<
" phi " << stationPhi);
220 newALine.
setAmdbId(stationType, stationEta, stationPhi, multiLayer);
221 newALine.
setParameters(line[
"svalue"], line[
"zvalue"], line[
"tvalue"],
222 line[
"tsv"], line[
"tzv"], line[
"ttv"]);
223 auto aLineInsert = writeALineCdo.insert(newALine);
224 if (newALine && !aLineInsert.second) {
226 <<
" because "<<(*aLineInsert.first)<<
" has been added before");
230 if (line.find(
"bz") == line.end()) {
235 line[
"sp"], line[
"sn"], line[
"tw"],
236 line[
"pg"], line[
"tr"], line[
"eg"],
237 line[
"ep"], line[
"en"]);
239 newBLine.
setAmdbId(stationType, stationEta, stationPhi, multiLayer);
240 ATH_MSG_VERBOSE(
" HardwareChamberName " <<
static_cast<std::string
>(line[
"hwElement"]));
241 auto bLineInsert = writeBLineCdo.insert(newBLine);
242 if (newBLine && !bLineInsert.second){
244 <<
" because "<<(*bLineInsert.first)<<
" has been added before.");
247 return StatusCode::SUCCESS;
251 bool loadBLines)
const {
254 constexpr std::string_view delimiter{
"\n"};
256 json = nlohmann::json::array();
258 for (
const std::string& blobline : lines) {
260 constexpr std::string_view delimiter{
":"};
264 if (tokens.empty()) {
266 return StatusCode::FAILURE;
268 const std::string_view &
type = tokens[0];
270 if (
type[0] ==
'#') {
281 if (
type.compare(0, 4,
"Corr") == 0) {
282 constexpr std::string_view delimiter{
" "};
284 if (tokens.size() != 25) {
285 ATH_MSG_FATAL(
"Invalid length in string retrieved. String length is " << tokens.size());
286 return StatusCode::FAILURE;
291 line[
"typ"] = std::string(tokens[ival++]);
323 line[
"hwElement"] = std::string(tokens[ival++]);
325 json.push_back(std::move(line));
328 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)
Base class for conditions algorithms.
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.
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteCondHandleKey< BLineContainer > m_writeBLineKey
virtual StatusCode initialize() override
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 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...
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< std::string > m_readFromJSON
Load the alignment parameters from a JSON file.
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
Gaudi::Property< bool > m_newFormat2020
SG::ReadCondHandleKeyArray< CondAttrListCollection > m_alignKeys
MuonAlignmentCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode parseDataFromJSON(const nlohmann::json &lines, ALineContainer &writeALineCdo, BLineContainer &writeBLineCdo) const
Parse the JSON blob to fill the A & B Line containers.
Gaudi::Property< bool > m_loadBLines
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)
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.