ATLAS Offline Software
Loading...
Searching...
No Matches
PixelDeadMapCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "GaudiKernel/EventIDRange.h"
7#include "StringUtilities.h"
8
11#include <nlohmann/json.hpp>
12
13#include <fstream>
14
16using json = nlohmann::json;
17
18PixelDeadMapCondAlg::PixelDeadMapCondAlg(const std::string& name, ISvcLocator* pSvcLocator):
19 ::AthCondAlgorithm(name, pSvcLocator)
20{
21}
22
24 ATH_MSG_DEBUG("PixelDeadMapCondAlg::initialize()");
25
26 ATH_CHECK (detStore()->retrieve(m_pixelID, "PixelID") );
28 ATH_CHECK(m_writeKey.initialize());
29
30 return StatusCode::SUCCESS;
31}
32
33StatusCode PixelDeadMapCondAlg::execute(const EventContext& ctx) const {
34 ATH_MSG_DEBUG("PixelDeadMapCondAlg::execute()");
35
37 if (writeHandle.isValid()) {
38 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid.. In theory this should not be called, but may happen if multiple concurrent events are being processed out of order.");
39 return StatusCode::SUCCESS;
40 }
41
42
43 // Construct the output Cond Object and fill it in
44 std::unique_ptr<PixelDeadMapCondData> writeCdo(std::make_unique<PixelDeadMapCondData>());
45
46 const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0,
47 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
48 const EventIDBase stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1,
49 EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
50
51 EventIDRange rangeW{start, stop};
52
53 if (!m_readKey.empty()) {
55 const CondAttrListCollection* readCdo = *readHandle;
56 if (readCdo==nullptr) {
57 ATH_MSG_FATAL("Null pointer to the read conditions object");
58 return StatusCode::FAILURE;
59 }
60 // Get the validitiy range
61 if (not readHandle.range(rangeW)) {
62 ATH_MSG_FATAL("Failed to retrieve validity range for " << readHandle.key());
63 return StatusCode::FAILURE;
64 }
65
66 for (const auto & attrList : *readCdo) {
67
68 const CondAttrListCollection::AttributeList &payload = attrList.second;
69 // RUN-3 format
70 if (payload.exists("data_array") and not payload["data_array"].isNull()) {
71 const std::string &stringStatus = payload["data_array"].data<std::string>();
72 const auto & hashStatusVector = parseDeadMapString(stringStatus);
73
74 for (const auto & [hash, status] : hashStatusVector){
75 //status ==0 means its the module status to be set to '1'
76 if (status==0) writeCdo->setModuleStatus(hash, 1);
77 //...any other status will set the chip status
78 else writeCdo->setChipStatus(hash, status);
79 }
80 }
81 }
82 } // readKey not empty
83 else if (!m_JsonLocation.empty()) { // use json for dead modules if defined
84
85 ATH_MSG_DEBUG("Reading in the json file:"<<m_JsonLocation);
86 std::ifstream json_file(m_JsonLocation);
87 if (!json_file.is_open()) {
88 ATH_MSG_ERROR("Failed to open the json file with dead pixel modules");
89 return StatusCode::FAILURE;
90 }
91
92 json dead_module_data = json::parse(json_file);
93
94 for (const auto& i : dead_module_data) {
95 std::string id_mod = i["Decimal_ID"];
96 unsigned long long idull = std::stoull(id_mod);
97 Identifier id(idull);
98
99 // This assumes that I am passing identifiers only valid for pixel
100 IdentifierHash idhash = m_pixelID->wafer_hash(id);
101
102 // Switch off sensor in condition store
103 ATH_MSG_DEBUG("Disabling sensor:"<<id_mod);
104
105 writeCdo->setModuleStatus(idhash,1);
106 }
107 }
108 else { // no readKey and no jsonFiles have been defined.
109 ATH_MSG_DEBUG("No readKey and jsonFile have been passed to PixelDeadMapCondAlg.");
110 }
111
112 if (rangeW.stop().isValid() and rangeW.start()>rangeW.stop()) {
113 ATH_MSG_FATAL("Invalid intersection rangeW: " << rangeW);
114 return StatusCode::FAILURE;
115 }
116
117 if (writeHandle.record(rangeW, std::move(writeCdo)).isFailure()) {
118 ATH_MSG_FATAL("Could not record PixelDeadMapCondData " << writeHandle.key() << " with EventRange " << rangeW << " into Conditions Store");
119 return StatusCode::FAILURE;
120 }
121
122 ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << rangeW << " into Conditions Store");
123
124 return StatusCode::SUCCESS;
125}
126
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
nlohmann::json json
std::vector< std::pair< int, int > > parseDeadMapString(const std::string &s)
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
This class is a collection of AttributeLists where each one is associated with a channel number.
coral::AttributeList AttributeList
This is a "hash" representation of an Identifier.
SG::WriteCondHandleKey< PixelDeadMapCondData > m_writeKey
Gaudi::Property< std::string > m_JsonLocation
PixelDeadMapCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override final
const PixelID * m_pixelID
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
bool range(EventIDRange &r)
const std::string & key() const
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
std::vector< std::pair< int, int > > parseDeadMapString(const std::string &s)