ATLAS Offline Software
LArCalibParams.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "GaudiKernel/ServiceHandle.h"
10 
12  m_onlineHelper(nullptr),
13  m_uniqueConfig(false)
14 {}
15 
17 {
18  //Get online Helper via DetectorStore
19  ServiceHandle<StoreGateSvc> detStore("DetectorStore", "LArCalibParams");
20  CHECK_WITH_CONTEXT( detStore.isValid(), "LArCalibParams" );
21  CHECK_WITH_CONTEXT( detStore->retrieve(m_onlineHelper, "LArOnlineID"), "LArCalibParams" );
22  return (StatusCode::SUCCESS);
23 }
24 
25 
27 {
28 }
29 
30 void LArCalibParams::set(const HWIdentifier CalibModuleID, const unsigned nTrigger,
31  const std::vector<unsigned>& Pattern, const std::vector<unsigned>& DAC, const std::vector<unsigned>& Delay)
32 
33 {if (m_uniqueConfig) //Had unique configuration before
34  {m_mCalibBoards.clear(); //Clear parameters
35  m_uniqueConfig=false;
36  }
37  m_mCalibBoards[CalibModuleID].m_nTrigger=nTrigger;
38  for (unsigned i=0;i<DAC.size();i++)
39  m_mCalibBoards[CalibModuleID].m_DAC.push_back(DAC[i]);
40  for (unsigned i=0;i<Delay.size();i++)
41  m_mCalibBoards[CalibModuleID].m_Delay.push_back(Delay[i]);
42  for (unsigned i=0;i<Pattern.size();i++) {
43  m_mCalibBoards[CalibModuleID].m_Pattern.push_back(Pattern[i]);
44  }
45  return;
46 }
47 
48 
49 void LArCalibParams::set(const unsigned nTrigger, const std::vector<unsigned>& Pattern,
50  const std::vector<unsigned>& DAC, const std::vector<unsigned>& Delay)
51 {// Assume only one set of parameters, valid for all boards.
52  m_mCalibBoards.clear();
53  m_uniqueConfig=true;
54  const HWIdentifier CalibModuleID(0);
55  m_mCalibBoards[CalibModuleID].m_nTrigger=nTrigger;
56  for (unsigned i=0;i<DAC.size();i++)
57  m_mCalibBoards[CalibModuleID].m_DAC.push_back(DAC[i]);
58  for (unsigned i=0;i<Delay.size();i++)
59  m_mCalibBoards[CalibModuleID].m_Delay.push_back(Delay[i]);
60  for (unsigned i=0;i<Pattern.size();i++)
61  m_mCalibBoards[CalibModuleID].m_Pattern.push_back(Pattern[i]);
62  return;
63 }
64 
65 
66 /* We assume that calib-board configuration is set in the following order:
67 1) Trigger
68 2) Pattern
69 3) Delay
70 4) DAC
71 
72 */
73 
74 bool LArCalibParams::CalibBoard::isPulsed(const unsigned event, const unsigned short lineNumber) const
75 { //The pattern is changed after nTrigger events.
76  const unsigned PatternStepSize=m_nTrigger;
77  unsigned iPattern=(event/PatternStepSize)%(m_Pattern.size()/4);
78  iPattern*=4; //A pattern consists of 4 words (4*32bit= 128 bit)
79  const unsigned nWord=lineNumber>>5; //lineNumber/32;
80  const unsigned Pattern=m_Pattern[iPattern+nWord];
81  const unsigned nBit=lineNumber&0x1f; //lineNumber%32;
82  return Pattern>>nBit & 0x1;
83 }
84 
85 
86 unsigned LArCalibParams::CalibBoard::Delay(const unsigned event) const
87 { //The delay value is changed after nTrigger*nPattern events
88  const unsigned DelayStepSize=m_nTrigger*m_Pattern.size()/4; //1 pattern = 4 words
89  const unsigned iDelay=(event/DelayStepSize)%m_Delay.size();
90  return m_Delay[iDelay];
91 }
92 
93 
94 unsigned LArCalibParams::CalibBoard::DAC(const unsigned event) const
95 { //The DAC is changed after nTrigger*nDelay*nPattern events
96  const unsigned DACStepSize=m_nTrigger*m_Delay.size()*m_Pattern.size()/4; //1 pattern = 4 words
97  const unsigned iDAC=event/DACStepSize;
98  if (iDAC<m_DAC.size()) {
99  //std::cout << "CalibBoard Returning DAC=" << m_DAC[iDAC] << " Index=" << iDAC << " Stepsize=" << DACStepSize << std::endl;
100  return m_DAC[iDAC];
101  }
102  else {
103  MsgStream log(Athena::getMessageSvc(), "LArCalibParams::DAC");
104  log << MSG::ERROR << "Event #" << event << ": DAC index out of range! ("
105  << iDAC << "max=" << m_DAC.size() << "). Return kmaxDAC" << endmsg;
106  return kmaxDAC;
107  }
108 }
109 
110 
111 
112 unsigned LArCalibParams::Delay(const unsigned event, const HWIdentifier calibLineID) const
113 {if (calibLineID.get_compact()==0) return 0; //Disconnected channel
114  if (m_uniqueConfig && !m_mCalibBoards.empty())
115  return m_mCalibBoards.begin()->second.Delay(event);
116  else {
117  if (!m_onlineHelper) {
118  MsgStream log(Athena::getMessageSvc(), "LArCalibParams::Delay");
119  log << MSG::ERROR << "LArOnlineID not defined! Can't determine Delay value." << endmsg;
120  return 0;
121  }
122  const HWIdentifier calibModuleID=m_onlineHelper->calib_module_Id(calibLineID);
123  const std::map<HWIdentifier, CalibBoard>::const_iterator map_it=m_mCalibBoards.find(calibModuleID);
124  if (map_it==m_mCalibBoards.end())
125  return 0; //Can't find Board configuration -> Assume board is not configured.
126  else
127  return map_it->second.Delay(event);
128  }
129 }
130 
131 unsigned LArCalibParams::DAC(const unsigned event, const HWIdentifier calibLineID) const
132 {if (calibLineID.get_compact()==0) return 0; //Disconnected channel
133  if (m_uniqueConfig && !m_mCalibBoards.empty())
134  return m_mCalibBoards.begin()->second.DAC(event);
135  else {
136  if (!m_onlineHelper) {
137  MsgStream log(Athena::getMessageSvc(), "LArCalibParams::DAC");
138  log << MSG::ERROR << "LArOnlineID not defined! Can't determine DAC value." << endmsg;
139  return 0;
140  }
141  const HWIdentifier calibModuleID=m_onlineHelper->calib_module_Id(calibLineID);
142  const std::map<HWIdentifier, CalibBoard>::const_iterator map_it=m_mCalibBoards.find(calibModuleID);
143  if (map_it==m_mCalibBoards.end())
144  return 0; //Can't find Board configuration -> Assume board is not configured.
145  else
146  return map_it->second.DAC(event);
147  }
148 }
149 
150 
151 bool LArCalibParams::isPulsed(const unsigned event, const HWIdentifier calibLineID) const
152 {
153  if (calibLineID.get_compact()==0) return false; //Disconnected channel
154  if (!m_onlineHelper) {
155  MsgStream log(Athena::getMessageSvc(), "LArCalibParams::isPulsed");
156  log << MSG::ERROR << "LArOnlineID not defined! Can't determine isPulsed value." << endmsg;
157  return false;
158  }
159  const int line=m_onlineHelper->channel(calibLineID);
160  if (m_uniqueConfig && !m_mCalibBoards.empty())
161  return m_mCalibBoards.begin()->second.isPulsed(event, line);
162  else
163  {const HWIdentifier calibModuleID=m_onlineHelper->calib_module_Id(calibLineID);
164  const std::map<HWIdentifier, CalibBoard>::const_iterator map_it=m_mCalibBoards.find(calibModuleID);
165  if (map_it==m_mCalibBoards.end()) {
166  return false;//Can't find Board configuration -> Assume board is not configured.
167  }
168  else
169  return map_it->second.isPulsed(event,line);
170  }
171 }
172 
173 
174 unsigned LArCalibParams::getNumberConfig(const HWIdentifier calibModuleID) const
175 { //Number of configurations is nDAC*nDelay*nPattern
176  if (m_uniqueConfig && !m_mCalibBoards.empty()) {
177  const unsigned nConfig=m_mCalibBoards.begin()->second.m_DAC.size()*
178  m_mCalibBoards.begin()->second.m_Delay.size()*m_mCalibBoards.begin()->second.m_Pattern.size()/4;
179  return nConfig;
180  }
181  else {
182  const std::map<HWIdentifier, CalibBoard>::const_iterator map_it=m_mCalibBoards.find(calibModuleID);
183  if (map_it==m_mCalibBoards.end())
184  return 1; //Can't find Board configuration -> Assume board is not configured.(always the same values)
185  else {
186  const unsigned nConfig=map_it->second.m_DAC.size()*
187  map_it->second.m_Delay.size()*map_it->second.m_Pattern.size()/4;
188  return nConfig;
189  }
190  }
191 }
192 
193 
194 
195 unsigned LArCalibParams::NTrigger(const HWIdentifier calibModuleID) const
196 {
197  if (m_uniqueConfig && !m_mCalibBoards.empty())
198  return m_mCalibBoards.begin()->second.m_nTrigger;
199  else {
200  const std::map<HWIdentifier, CalibBoard>::const_iterator map_it=m_mCalibBoards.find(calibModuleID);
201  if (map_it==m_mCalibBoards.end())
202  return 0xFFFFFFFF; //Can't find Board configuration -> Assume board is not configured.(nothing ever changes)
203  else
204  return map_it->second.m_nTrigger;
205  }
206 }
207 /*
208 const CalibBoard& LArCalibParams::getCalibBoardParams(const HWIdentifier calibModuleID) const
209 {
210  if (m_uniqueConfig && m_mCalibBoards.size()==1)
211  return m_mCalibBoards.begin()->second;
212  else
213  return m_mCalibBoards[calibModuleID]; //Find would be better....
214 }
215 */
216 
217 unsigned LArCalibParams::getNumberPatterns(const HWIdentifier calibModuleID) const
218 { //Number of configurations is nDAC*nDelay*nPattern
219  if ((m_uniqueConfig && m_mCalibBoards.size()==1) || // one calib board configured
220  calibModuleID == HWIdentifier(0)) { // assuming equal config for all b. boards configured
221  const unsigned nPatt = m_mCalibBoards.begin()->second.m_Pattern.size()/4;
222  return nPatt;
223  }
224  else {
225  const std::map<HWIdentifier, CalibBoard>::const_iterator map_it=m_mCalibBoards.find(calibModuleID);
226  if (map_it==m_mCalibBoards.end())
227  return 0; //Can't find Board configuration -> Assume board is not configured.
228  else {
229  const unsigned nPatt = map_it->second.m_Pattern.size()/4;
230  return nPatt;
231  }
232  }
233 }
234 
235 
checkFileSG.line
line
Definition: checkFileSG.py:75
LArCalibParams::getNumberPatterns
unsigned getNumberPatterns(const HWIdentifier calibModuleID) const
Definition: LArCalibParams.cxx:217
CHECK_WITH_CONTEXT
#define CHECK_WITH_CONTEXT(...)
Evaluate an expression and check for errors, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:396
LArCalibParams::CalibBoard::Delay
unsigned Delay(const unsigned event) const
Definition: LArCalibParams.cxx:86
LArCalibParams::NTrigger
unsigned NTrigger(const HWIdentifier calibModuleID) const
Definition: LArCalibParams.cxx:195
LArCalibParams::m_uniqueConfig
bool m_uniqueConfig
Definition: LArCalibParams.h:74
Identifier::get_compact
value_type get_compact() const
Get the compact id.
LArOnlineID_Base::calib_module_Id
HWIdentifier calib_module_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Build calibration module identifier from fields.
Definition: LArOnlineID_Base.h:573
HWIdentifier
Definition: HWIdentifier.h:13
LArCalibParams::m_mCalibBoards
std::map< HWIdentifier, CalibBoard > m_mCalibBoards
Definition: LArCalibParams.h:72
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
LArCalibParams::CalibBoard::m_Pattern
std::vector< unsigned > m_Pattern
Definition: LArCalibParams.h:62
LArCalibParams::LArCalibParams
LArCalibParams()
Definition: LArCalibParams.cxx:11
LArCalibParams::~LArCalibParams
virtual ~LArCalibParams()
Definition: LArCalibParams.cxx:26
kmaxDAC
#define kmaxDAC
This class contains the LAr Calibration Board settings and a set of functions to decoded them.
Definition: LArCalibParams.h:26
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1963
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LArCalibParams::isPulsed
bool isPulsed(const unsigned event, const HWIdentifier calibLineID) const
Definition: LArCalibParams.cxx:151
LArCalibParams::m_onlineHelper
const LArOnlineID * m_onlineHelper
Definition: LArCalibParams.h:73
LArCalibParams::CalibBoard::m_nTrigger
unsigned m_nTrigger
Definition: LArCalibParams.h:61
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
LArCalibParams::DAC
unsigned DAC(const unsigned event, const HWIdentifier calibLineID) const
Definition: LArCalibParams.cxx:131
LArCalibParams::CalibBoard::DAC
unsigned DAC(const unsigned event) const
Definition: LArCalibParams.cxx:94
errorcheck.h
Helpers for checking error return status codes and reporting errors.
LArCalibParams::Delay
unsigned Delay(const unsigned event, const HWIdentifier calibLineID) const
Definition: LArCalibParams.cxx:112
LArCalibParams::getNumberConfig
unsigned getNumberConfig(const HWIdentifier calibModuleID) const
Definition: LArCalibParams.cxx:174
LArCalibParams::CalibBoard::isPulsed
bool isPulsed(const unsigned event, const unsigned short calibLine) const
Definition: LArCalibParams.cxx:74
LArCalibParams.h
Trk::Pattern
@ Pattern
Definition: ParametersCommon.h:29
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArCalibParams::initialize
virtual StatusCode initialize()
Definition: LArCalibParams.cxx:16
StoreGateSvc.h
LArCalibParams::set
void set(const HWIdentifier CalibModuleID, const unsigned nTrigger, const std::vector< unsigned > &Pattern, const std::vector< unsigned > &DAC, const std::vector< unsigned > &Delay)
Definition: LArCalibParams.cxx:30
LArOnlineID.h
ServiceHandle< StoreGateSvc >