ATLAS Offline Software
Loading...
Searching...
No Matches
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
11
12//Package
13#include "SCT_TestCablingAlg.h"
14
16#include "SCT_CablingXmlTags.h"
17
18//Athena
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
36using namespace SCT_Cabling;
37
38SCT_TestCablingAlg::SCT_TestCablingAlg(const std::string& name, ISvcLocator* pSvcLocator):
39 AthReentrantAlgorithm(name, pSvcLocator) {
40 //nop
41}
42
43StatusCode
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
51std::string
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
63StatusCode
64SCT_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
144StatusCode
146 ATH_MSG_INFO("finalize()");
147 return StatusCode::SUCCESS;
148}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
static std::string to_string(const std::vector< T > &v)
Header file for utility functions used in SCT cabling code.
Header file for tags to be used in Xml output from the test algorithm.
This is an Identifier helper class for the SCT subdetector.
Header file for Algorithm to test cabling.
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
This is a "hash" representation of an Identifier.
SCT_OnlineId is a class to hold an online id number and provide check on validity,...
std::uint32_t fibre() const
Return the fibre.
std::uint32_t rod() const
Return the rod/rob Id.
SCT_SerialNumber is a class to hold a serial number and provide check on validity,...
std::string str() const
Full serial number as a string.
UnsignedIntegerProperty m_POSIXtime
const SCT_ID * m_idHelper
helper for offlineId/hash conversions
ToolHandle< ISCT_CablingTool > m_cablingTool
std::string coordString(const Identifier &offlineId) const
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi executer.
virtual StatusCode initialize() override
Gaudi initialiser.
virtual StatusCode finalize() override
Gaudi finaliser.
SCT_TestCablingAlg(const std::string &name, ISvcLocator *pSvcLocator)
int r
Definition globals.cxx:22
const std::string XmlHeader("<?xml version=\"1.0\"?>")
const std::string OpenModuleMappingTag("<textList name=\"SCT cabling mapping\" headings=\"Rod Fibre Bec LayerDisk Eta Phi Side RobId Sn\">")
std::string formatRodOutput(const unsigned int rodNum)
const std::string CloseRodMappingTag("</textList>")
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)
const std::string OpenRodMappingTag("<textList name=\"SCT Rod-Rob mapping\" headings=\"RodId RobId\">")
const std::string CloseModuleMappingTag("</textList>")
const std::string OpenRootTag("<SCT_textFile>")
const std::string CloseRootTag("</SCT_textFile>")
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.