ATLAS Offline Software
SCT_TestCablingAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
12 //Package
13 #include "SCT_TestCablingAlg.h"
14 
15 #include "SCT_CablingUtilities.h"
16 #include "SCT_CablingXmlTags.h"
17 
18 //Athena
20 #include "InDetIdentifier/SCT_ID.h"
21 
22 //Gaudi
23 #include "GaudiKernel/StatusCode.h"
24 
25 //STL
26 #include <set>
27 #include <cstdint>
28 //for o/p to file
29 #include <iostream>
30 #include <fstream>
31 //to access environment
32 #include <cstdlib>
33 #include <algorithm>
34 #include <map>
35 
36 using namespace SCT_Cabling;
37 
38 SCT_TestCablingAlg::SCT_TestCablingAlg(const std::string& name, ISvcLocator* pSvcLocator):
39  AthReentrantAlgorithm(name, pSvcLocator) {
40  //nop
41 }
42 
45  ATH_CHECK(detStore()->retrieve(m_idHelper, "SCT_ID"));
46  ATH_CHECK(m_cablingTool.retrieve());
47  ATH_MSG_INFO("Test algorithm for SCT_Cabling");
48  return StatusCode::SUCCESS;
49 }
50 
51 std::string
52 SCT_TestCablingAlg::coordString(const Identifier& offlineId) const {
53  using std::to_string;
54  const std::string sep{", "};
55  std::string result{std::string("[") + to_string(m_idHelper->barrel_ec(offlineId)) + sep};
56  result += to_string(m_idHelper->layer_disk(offlineId)) + sep;
57  result += to_string(m_idHelper->phi_module(offlineId)) + sep;
58  result += to_string(m_idHelper->eta_module(offlineId)) + sep;
59  result += to_string(m_idHelper->side(offlineId)) + "]";
60  return result;
61 }
62 
64 SCT_TestCablingAlg::execute(const EventContext& ctx) const {
65  // const string testAreaPath{CoveritySafe::getenv("TestArea")};
66  const std::string testAreaPath = ".";
67  std::string filename{testAreaPath+"/cabling.txt"};
68  ATH_MSG_INFO("Filename: " << filename << " will be written to your $TestArea.");
69  std::ofstream opFile1{filename.c_str(), std::ios::out};
70  ATH_MSG_INFO("Executing...");
71  ATH_MSG_INFO("hash, offline Id, online Id(hex), serial number");
72  const unsigned int nHashesInCabling{2*m_cablingTool->size(ctx)};
73  for (unsigned int i{0}; i!=nHashesInCabling; ++i) {
74  IdentifierHash hash{i};
75  Identifier offlineId{m_idHelper->wafer_id(hash)};
76  SCT_OnlineId onlineId{m_cablingTool->getOnlineIdFromHash(hash, ctx)};
77  SCT_SerialNumber sn{m_cablingTool->getSerialNumberFromHash(hash, ctx)};
78  ATH_MSG_INFO(i << " " << offlineId << " " << std::hex << onlineId << std::dec << " " << sn << " " << coordString(offlineId));
79  opFile1 << i << " " << offlineId << " " << std::hex << onlineId << std::dec << " " << sn << " " << coordString(offlineId) << std::endl;
80  if (m_cablingTool->getHashFromOnlineId(onlineId, ctx) != hash){
81  ATH_MSG_ERROR("?? " << m_cablingTool->getHashFromOnlineId(onlineId, ctx));
82  }
83  }
84  opFile1.close();
85  ATH_MSG_INFO("Size: " << m_cablingTool->size(ctx));
86  std::vector<unsigned int> rods;
87  m_cablingTool->getAllRods(rods, ctx);
88  ATH_MSG_INFO("Num. of rods= " << rods.size());
89  ATH_MSG_INFO("First rod id " << std::hex << rods[0] << std::dec);
90  std::string sn{"20220130000299"};
91  ATH_MSG_INFO("Hash from serial number " << m_cablingTool->getHashFromSerialNumber(sn, ctx));
92  int tsn{130000299};
93  ATH_MSG_INFO("Hash from truncated serial number " << m_cablingTool->getHashFromSerialNumber(tsn, ctx));
94  unsigned long long snll{20220130000299LL};
95  ATH_MSG_INFO("Hash from truncated serial number " << m_cablingTool->getHashFromSerialNumber(snll, ctx));
96  ATH_MSG_INFO("Hash from onlineid " << m_cablingTool->getHashFromOnlineId(0x3d230006, ctx));
97  ATH_MSG_INFO("Hash from invalid onlineid " << m_cablingTool->getHashFromOnlineId(0x3d250006, ctx));
98  ATH_MSG_INFO("Hash from textfile onlineid " << m_cablingTool->getHashFromOnlineId(0x3d220010, ctx));
99  ATH_MSG_INFO("Hash from db onlineid " << m_cablingTool->getHashFromOnlineId(0x3d220105, ctx));
100  std::vector<IdentifierHash> hashVec;
101  m_cablingTool->getHashesForRod(hashVec, 0x220005, ctx);
102  ATH_MSG_INFO("number of hashes for rod 0x220005: " << hashVec.size());
103  //new section December 2014
104 
105  //make a 'rodHash'
106  std::sort(rods.begin(), rods.end());
107  std::map<unsigned int, unsigned int> rodHashMap;
108  for (unsigned int i{0}; i!=rods.size(); ++i) {
109  rodHashMap[rods[i]]=i;
110  }
111  //open a file for writing
112  const std::string fullFileName{testAreaPath + "/SCT_Cabling_svc" + (m_POSIXtime ? ("_" +std::to_string(m_POSIXtime)) : "") + ".dat"};
113  ATH_MSG_INFO("Open file for write " << fullFileName);
114  std::ofstream opFile{fullFileName.c_str(), std::ios::out};
115  opFile << XmlHeader << std::endl;
116  opFile << OpenRootTag << std::endl;
117  opFile << OpenRodMappingTag << std::endl;
118  for (auto r: rods) {
119  opFile << formatRodOutput(r) << std::endl;
120  }
121  opFile << CloseRodMappingTag << std::endl;
122  opFile << OpenModuleMappingTag << std::endl;
123  for (unsigned int i{0}; i!=nHashesInCabling; ++i) {
124  IdentifierHash hash{i};
125  Identifier offlineId{m_idHelper->wafer_id(hash)};
126  SCT_OnlineId onlineId{m_cablingTool->getOnlineIdFromHash(hash, ctx)};
127  SCT_SerialNumber sn{m_cablingTool->getSerialNumberFromHash(hash, ctx)};
128  //rod, fibre, bec, layerDisk, eta, phi, side, robId, sn
129  const int bec{m_idHelper->barrel_ec(offlineId)};
130  const int layer{m_idHelper->layer_disk(offlineId)};
131  const int eta{m_idHelper->eta_module(offlineId)};
132  const int phi{m_idHelper->phi_module(offlineId)};
133  const int side{m_idHelper->side(offlineId)};
134  const unsigned int rodIndex{rodHashMap[onlineId.rod()]};
135  opFile << formatModuleOutput(rodIndex, onlineId.fibre(), bec, layer, eta, phi, side, onlineId.rod() ,sn.str()) << std::endl;
136  }
137  opFile << CloseModuleMappingTag << std::endl;
138  opFile << CloseRootTag << std::endl;
139  opFile.close();
140  return StatusCode::SUCCESS;
141 }
142 
143 
146  ATH_MSG_INFO("finalize()");
147  return StatusCode::SUCCESS;
148 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
beamspotman.r
def r
Definition: beamspotman.py:676
SCT_TestCablingAlg::finalize
virtual StatusCode finalize() override
Gaudi finaliser.
Definition: SCT_TestCablingAlg.cxx:145
SCT_CablingUtilities.h
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
get_generator_info.result
result
Definition: get_generator_info.py:21
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SCT_TestCablingAlg::SCT_TestCablingAlg
SCT_TestCablingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SCT_TestCablingAlg.cxx:38
SCT_Cabling::OpenRodMappingTag
const std::string OpenRodMappingTag("<textList name=\"SCT Rod-Rob mapping\" headings=\"RodId RobId\">")
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
SCT_Cabling::OpenRootTag
const std::string OpenRootTag("<SCT_textFile>")
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
SCT_OnlineId
Definition: SCT_OnlineId.h:22
SCT_Cabling::CloseRootTag
const std::string CloseRootTag("</SCT_textFile>")
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
SCT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: SCT_ID.h:740
SCT_Cabling
Definition: SCT_CablingUtilities.cxx:17
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
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SCT_Cabling::XmlHeader
const std::string XmlHeader("<?xml version=\"1.0\"?>")
TRT::Hit::side
@ side
Definition: HitInfo.h:83
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SCT_TestCablingAlg::coordString
std::string coordString(const Identifier &offlineId) const
Definition: SCT_TestCablingAlg.cxx:52
SCT_Cabling::formatModuleOutput
std::string formatModuleOutput(const unsigned int rod, const unsigned int fibre, const int bec, const int layerDisk, const int eta, const int phi, const int side, const int robId, const std::string &fullsn)
Definition: SCT_CablingXmlTags.h:45
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
SCT_TestCablingAlg::m_POSIXtime
UnsignedIntegerProperty m_POSIXtime
Definition: SCT_TestCablingAlg.h:50
SCT_TestCablingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi executer.
Definition: SCT_TestCablingAlg.cxx:64
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCT_CablingXmlTags.h
grepfile.sep
sep
Definition: grepfile.py:38
SCT_Cabling::OpenModuleMappingTag
const std::string OpenModuleMappingTag("<textList name=\"SCT cabling mapping\" headings=\"Rod Fibre Bec LayerDisk Eta Phi Side RobId Sn\">")
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
IdentifierHash.h
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
SCT_Cabling::CloseRodMappingTag
const std::string CloseRodMappingTag("</textList>")
SCT_SerialNumber
Definition: SCT_SerialNumber.h:22
SCT_Cabling::formatRodOutput
std::string formatRodOutput(const unsigned int rodNum)
Definition: SCT_CablingXmlTags.h:39
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
SCT_TestCablingAlg::m_cablingTool
ToolHandle< ISCT_CablingTool > m_cablingTool
Definition: SCT_TestCablingAlg.h:47
SCT_ID::eta_module
int eta_module(const Identifier &id) const
Definition: SCT_ID.h:746
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
SCT_ID::side
int side(const Identifier &id) const
Definition: SCT_ID.h:752
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
SCT_TestCablingAlg::initialize
virtual StatusCode initialize() override
Gaudi initialiser.
Definition: SCT_TestCablingAlg.cxx:44
SCT_TestCablingAlg::m_idHelper
const SCT_ID * m_idHelper
helper for offlineId/hash conversions
Definition: SCT_TestCablingAlg.h:48
SCT_TestCablingAlg.h
SCT_Cabling::CloseModuleMappingTag
const std::string CloseModuleMappingTag("</textList>")