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"
15
16#include <fstream>
17#include <map>
18#include <sstream>
19
20using uint = unsigned int;
21
22LArOFPhaseFill::LArOFPhaseFill(const std::string& name, ISvcLocator* pSvcLocator) :
23 AthAlgorithm(name, pSvcLocator),
24 m_lar_on_id(nullptr),
26{ }
27
29{
30 if(m_isSC) {
31 ATH_MSG_INFO("Processing LAr SuperCells");
32 const LArOnline_SuperCellID* onlID;
33 ATH_CHECK(detStore()->retrieve(onlID,"LArOnline_SuperCellID"));
34 m_lar_on_id=onlID; // cast to base-class
35 } else {
36 ATH_MSG_INFO("Processing regular LArCells");
37 const LArOnlineID* onlID;
38 ATH_CHECK(detStore()->retrieve(onlID, "LArOnlineID"));
39 m_lar_on_id=onlID; // cast to base-class
40 }
41
42 if ( m_groupingName == "Unknown" ) {
44 } else if ( m_groupingName == "SingleGroup" ) {
46 } else if ( m_groupingName == "SubDetector" ) {
48 } else if ( m_groupingName == "FeedThrough" ) {
50 } else if ( m_groupingName == "ExtendedFeedThrough" ) {
52 } else if ( m_groupingName == "ExtendedSubDet" ) {
54 } else if ( m_groupingName == "SuperCells" ) {
56 } else {
57 ATH_MSG_ERROR ( "Grouping type " << m_groupingName << " is not foreseen!" );
58 ATH_MSG_ERROR( "Only \"Unknown\", \"SingleGroup\", \"SubDetector\", \"FeedThrough\", \"ExtendedFeedThrough\", \"ExtendedSubDetector\" and \"SuperCells\" are allowed" ) ;
59 return StatusCode::FAILURE ;
60 }
61
63
64 return StatusCode::SUCCESS;
65}
66
67
69{
70 ATH_MSG_DEBUG(" In stop() " );
71
72 typedef std::pair<HWIdentifier, int> idi;
73 std::map<idi, uint > inmap;
74 uint b_ec=0, p_n=0, ft=0, sl=0, ch=0, g=0, onlid=0;
75 uint count, gmax;
77
78 // Open a file and read it - if exists
79 if(m_InputFile.size() > 0) {
80 std::ifstream in (m_InputFile.toString());
81 if(!in.good()) {
82 ATH_MSG_ERROR("Could not open map file "<<m_InputFile);
83 ATH_MSG_ERROR("Using default phase " << m_defaultPhase << " for all channels");
84 } else {
85 uint phase;
86 count = 0;
87 char line[100];
88 do {
89 in.getline(line,99);
90 if((!in.good()) || in.eof()) break;
91 if(line[0]=='#') continue;
92 std::istringstream iss(line);
93 if(m_isID)
94 if(m_isSC)
95 iss>>std::dec>>onlid>>phase;
96 else
97 iss>>std::dec>>onlid>>g>>phase;
98 else{
99 if(m_isSC)
100 iss>>std::dec>>b_ec>>p_n>>ft>>sl>>ch>>g>>phase;
101 if(!iss.good()) {
102 ATH_MSG_WARNING("Wrong line: "<<line);
103 continue;
104 }
105 if(b_ec > 1) {
106 ATH_MSG_ERROR("Wrong barrel_ec: "<<b_ec<<", not taken");
107 continue;
108 }
109 if(p_n > 1) {
110 ATH_MSG_ERROR("Wrong pos_neg: "<<p_n<<", not taken");
111 continue;
112 }
113 if(ft > 31) {
114 ATH_MSG_ERROR("Wrong FTH: "<<ft<<", not taken");
115 continue;
116 }
117 if(sl == 0 || sl > 15) {
118 ATH_MSG_ERROR("Wrong slot: "<<sl<<", not taken");
119 continue;
120 }
121 if(ch > 127) {
122 ATH_MSG_ERROR("Wrong channel: "<<ch<<", not taken");
123 continue;
124 }
125 if((int)g < (int)CaloGain::LARHIGHGAIN || g > CaloGain::LARLOWGAIN) {
126 ATH_MSG_ERROR("Wrong gain: "<<g<<", not taken");
127 continue;
128 }
129 if(phase > 50) {
130 ATH_MSG_ERROR("Wrong phase: "<<phase<<", not taken");
131 continue;
132 }
133 }
134 HWIdentifier oc;
135 if(m_isID) oc=HWIdentifier(onlid); else oc = m_lar_on_id->channel_Id(b_ec, p_n, ft, sl, ch);
136 ATH_MSG_DEBUG("Read " << onlid << " gain " << g <<" phase: "<<phase);
137 inmap[std::make_pair(oc,g)] = phase;
138 ++count;
139 }while(!in.eof());
140 ATH_MSG_INFO(count<<" lines read out");
141 }
142 }
143
144 std::vector<HWIdentifier>::const_iterator it = m_lar_on_id->channel_begin();
145 std::vector<HWIdentifier>::const_iterator it_e = m_lar_on_id->channel_end();
146
147 StatusCode sc;
148 LArOFCBinComplete* OFCbin = new LArOFCBinComplete();
150 ATH_CHECK( OFCbin->initialize() );
151
152 int fphase;
153 count = 0;
154 for(; it!=it_e;++it){
155 const HWIdentifier id = *it;
156 sl = m_lar_on_id->slot(id);
157 ch = m_lar_on_id->channel(id);
158 ft = m_lar_on_id->feedthrough(id);
159 p_n = m_lar_on_id->pos_neg(id);
160 b_ec = m_lar_on_id->barrel_ec(id);
161 HWIdentifier oc = m_lar_on_id->channel_Id(b_ec, p_n, ft, sl, ch);
162 if(id != oc) {
163 std::cout <<"Something wrong: "<<id<<" "<<oc<<std::endl;
164 }
165 ++count;
166 for(g = CaloGain::LARHIGHGAIN; g <= gmax; ++g) {
167 if(inmap.find(std::make_pair(oc,g)) != inmap.end()) {
168 fphase = inmap[std::make_pair(oc,g)];
169 } else{
170 fphase = m_defaultPhase;
171 }
172 ATH_MSG_DEBUG("B_EC: "<<b_ec<<" Pos_Neg: "<<p_n<<" FT: "<<ft<<" Slot: "<<sl<<" Chan: "<<ch<<" Phase: "<<fphase);
173 OFCbin->set(id,g,fphase);
174 }
175 }
176
177 ATH_MSG_DEBUG(" Loop over " << count << " cells" );
178 ATH_CHECK( detStore()->record(OFCbin, m_keyOFCbin) );
179 return StatusCode::SUCCESS;
180}
181
#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)
defines and typedefs for IOVSvc
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