ATLAS Offline Software
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 
5 #include "PixelDeadMapCondAlg.h"
6 #include "GaudiKernel/EventIDRange.h"
7 #include "StringUtilities.h"
8 
11 #include <nlohmann/json.hpp>
12 
13 #include <fstream>
14 
17 
18 PixelDeadMapCondAlg::PixelDeadMapCondAlg(const std::string& name, ISvcLocator* pSvcLocator):
19  ::AthReentrantAlgorithm(name, pSvcLocator)
20 {
21 }
22 
24  ATH_MSG_DEBUG("PixelDeadMapCondAlg::initialize()");
25 
26  ATH_CHECK (detStore()->retrieve(m_pixelID, "PixelID") );
29 
30  return StatusCode::SUCCESS;
31 }
32 
33 StatusCode 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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
PixelDeadMapCondAlg.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PixelDeadMapCondAlg::m_pixelID
const PixelID * m_pixelID
Definition: PixelDeadMapCondAlg.h:37
json
nlohmann::json json
Definition: HistogramDef.cxx:9
PixelConditionsAlgorithms::parseDeadMapString
std::vector< std::pair< int, int > > parseDeadMapString(const std::string &s)
Definition: StringUtilities.cxx:19
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition: ReadCondHandle.h:224
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
PixelDeadMapCondAlg::PixelDeadMapCondAlg
PixelDeadMapCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixelDeadMapCondAlg.cxx:18
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
PixelID::wafer_hash
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition: PixelID.h:387
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition: WriteCondHandle.h:41
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
PixelDeadMapCondData::setModuleStatus
void setModuleStatus(const int chanNum, const int value)
Definition: PixelDeadMapCondData.cxx:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PixelDeadMapCondAlg::m_writeKey
SG::WriteCondHandleKey< PixelDeadMapCondData > m_writeKey
Definition: PixelDeadMapCondAlg.h:44
PixelDeadMapCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: PixelDeadMapCondAlg.cxx:33
PixelDeadMapCondAlg::m_readKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
Definition: PixelDeadMapCondAlg.h:41
PixelDeadMapCondData::setChipStatus
void setChipStatus(const int chanNum, const int value)
Definition: PixelDeadMapCondData.cxx:27
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PixelDeadMapCondAlg::m_JsonLocation
Gaudi::Property< std::string > m_JsonLocation
Definition: PixelDeadMapCondAlg.h:46
PixelDeadMapCondAlg::initialize
virtual StatusCode initialize() override final
Definition: PixelDeadMapCondAlg.cxx:23
json
nlohmann::json json
Definition: PixelDeadMapCondAlg.cxx:16
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
IdentifierHash.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
StringUtilities.h
merge.status
status
Definition: merge.py:17
CondAttrListCollection::AttributeList
coral::AttributeList AttributeList
Definition: CondAttrListCollection.h:56
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:59
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
Identifier32.h
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
Identifier
Definition: IdentifierFieldParser.cxx:14