ATLAS Offline Software
Loading...
Searching...
No Matches
LArOFPhaseFill.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12#include "GaudiKernel/ISvcLocator.h"
13#include "GaudiKernel/IToolSvc.h"
14
15#include <fstream>
16#include <map>
17#include <sstream>
18
19using uint = unsigned int;
20
21LArOFPhaseFill::LArOFPhaseFill(const std::string& name, ISvcLocator* pSvcLocator) :
22 AthAlgorithm(name, pSvcLocator),
23 m_lar_on_id(nullptr),
25{ }
26
28{
29 if(m_isSC) {
30 ATH_MSG_INFO("Processing LAr SuperCells");
31 const LArOnline_SuperCellID* onlID;
32 ATH_CHECK(detStore()->retrieve(onlID,"LArOnline_SuperCellID"));
33 m_lar_on_id=onlID; // cast to base-class
34 } else {
35 ATH_MSG_INFO("Processing regular LArCells");
36 const LArOnlineID* onlID;
37 ATH_CHECK(detStore()->retrieve(onlID, "LArOnlineID"));
38 m_lar_on_id=onlID; // cast to base-class
39 }
40
41 if ( m_groupingName == "Unknown" ) {
43 } else if ( m_groupingName == "SingleGroup" ) {
45 } else if ( m_groupingName == "SubDetector" ) {
47 } else if ( m_groupingName == "FeedThrough" ) {
49 } else if ( m_groupingName == "ExtendedFeedThrough" ) {
51 } else if ( m_groupingName == "ExtendedSubDet" ) {
53 } else if ( m_groupingName == "SuperCells" ) {
55 } else {
56 ATH_MSG_ERROR ( "Grouping type " << m_groupingName << " is not foreseen!" );
57 ATH_MSG_ERROR( "Only \"Unknown\", \"SingleGroup\", \"SubDetector\", \"FeedThrough\", \"ExtendedFeedThrough\", \"ExtendedSubDetector\" and \"SuperCells\" are allowed" ) ;
58 return StatusCode::FAILURE ;
59 }
60
62
63 return StatusCode::SUCCESS;
64}
65
66
68{
69 ATH_MSG_DEBUG(" In stop() " );
70
71 typedef std::pair<HWIdentifier, int> idi;
72 std::map<idi, uint > inmap;
73 uint b_ec=0, p_n=0, ft=0, sl=0, ch=0, g=0, onlid=0;
74 uint count, gmax;
76
77 // Open a file and read it - if exists
78 if(m_InputFile.size() > 0) {
79 std::ifstream in (m_InputFile.toString());
80 if(!in.good()) {
81 ATH_MSG_ERROR("Could not open map file "<<m_InputFile);
82 ATH_MSG_ERROR("Using default phase " << m_defaultPhase << " for all channels");
83 } else {
84 uint phase;
85 count = 0;
86 char line[100];
87 do {
88 in.getline(line,99);
89 if((!in.good()) || in.eof()) break;
90 if(line[0]=='#') continue;
91 std::istringstream iss(line);
92 if(m_isID)
93 if(m_isSC)
94 iss>>std::dec>>onlid>>phase;
95 else
96 iss>>std::dec>>onlid>>g>>phase;
97 else{
98 if(m_isSC)
99 iss>>std::dec>>b_ec>>p_n>>ft>>sl>>ch>>g>>phase;
100 if(!iss.good()) {
101 ATH_MSG_WARNING("Wrong line: "<<line);
102 continue;
103 }
104 if(b_ec > 1) {
105 ATH_MSG_ERROR("Wrong barrel_ec: "<<b_ec<<", not taken");
106 continue;
107 }
108 if(p_n > 1) {
109 ATH_MSG_ERROR("Wrong pos_neg: "<<p_n<<", not taken");
110 continue;
111 }
112 if(ft > 31) {
113 ATH_MSG_ERROR("Wrong FTH: "<<ft<<", not taken");
114 continue;
115 }
116 if(sl == 0 || sl > 15) {
117 ATH_MSG_ERROR("Wrong slot: "<<sl<<", not taken");
118 continue;
119 }
120 if(ch > 127) {
121 ATH_MSG_ERROR("Wrong channel: "<<ch<<", not taken");
122 continue;
123 }
124 if((int)g < (int)CaloGain::LARHIGHGAIN || g > CaloGain::LARLOWGAIN) {
125 ATH_MSG_ERROR("Wrong gain: "<<g<<", not taken");
126 continue;
127 }
128 if(phase > 50) {
129 ATH_MSG_ERROR("Wrong phase: "<<phase<<", not taken");
130 continue;
131 }
132 }
133 HWIdentifier oc;
134 if(m_isID) oc=HWIdentifier(onlid); else oc = m_lar_on_id->channel_Id(b_ec, p_n, ft, sl, ch);
135 ATH_MSG_DEBUG("Read " << onlid << " gain " << g <<" phase: "<<phase);
136 inmap[std::make_pair(oc,g)] = phase;
137 ++count;
138 }while(!in.eof());
139 ATH_MSG_INFO(count<<" lines read out");
140 }
141 }
142
143 std::vector<HWIdentifier>::const_iterator it = m_lar_on_id->channel_begin();
144 std::vector<HWIdentifier>::const_iterator it_e = m_lar_on_id->channel_end();
145
146 StatusCode sc;
147 LArOFCBinComplete* OFCbin = new LArOFCBinComplete();
149 ATH_CHECK( OFCbin->initialize() );
150
151 int fphase;
152 count = 0;
153 for(; it!=it_e;++it){
154 const HWIdentifier id = *it;
155 sl = m_lar_on_id->slot(id);
156 ch = m_lar_on_id->channel(id);
157 ft = m_lar_on_id->feedthrough(id);
158 p_n = m_lar_on_id->pos_neg(id);
159 b_ec = m_lar_on_id->barrel_ec(id);
160 HWIdentifier oc = m_lar_on_id->channel_Id(b_ec, p_n, ft, sl, ch);
161 if(id != oc) {
162 std::cout <<"Something wrong: "<<id<<" "<<oc<<std::endl;
163 }
164 ++count;
165 for(g = CaloGain::LARHIGHGAIN; g <= gmax; ++g) {
166 if(inmap.find(std::make_pair(oc,g)) != inmap.end()) {
167 fphase = inmap[std::make_pair(oc,g)];
168 } else{
169 fphase = m_defaultPhase;
170 }
171 ATH_MSG_DEBUG("B_EC: "<<b_ec<<" Pos_Neg: "<<p_n<<" FT: "<<ft<<" Slot: "<<sl<<" Chan: "<<ch<<" Phase: "<<fphase);
172 OFCbin->set(id,g,fphase);
173 }
174 }
175
176 ATH_MSG_DEBUG(" Loop over " << count << " cells" );
177 ATH_CHECK( detStore()->record(OFCbin, m_keyOFCbin) );
178 return StatusCode::SUCCESS;
179}
180
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
unsigned int uint
static Double_t sc
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
void setGroupingType(GroupingType type)
allow group type to be set externally - need to (re)initialize after setting grouping type
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
void set(const HWIdentifier &chid, const int &gain, const int &bin)
BooleanProperty m_isID
Gaudi::Property< unsigned int > m_defaultPhase
LArOFPhaseFill(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize()
StringProperty m_keyOFCbin
const LArOnlineID_Base * m_lar_on_id
StatusCode stop()
StringProperty m_groupingName
StringProperty m_InputFile
BooleanProperty m_isSC
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
@ LARLOWGAIN
Definition CaloGain.h:18
@ LARHIGHGAIN
Definition CaloGain.h:18