ATLAS Offline Software
Loading...
Searching...
No Matches
TGCConnectionInPP.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include <iostream>
9#include <fstream>
10#include <sstream>
11#include <string>
12#include "ctype.h"
13
15
16namespace LVL1TGCTrigger {
17
19{
20 enum { BufferSize = 1024 };
21 char buf[BufferSize];
22 std::string label;
23
24 if (PP->getRegion() == TGCRegionType::ENDCAP) {
25 label = "E";
26 } else if (PP->getRegion() == TGCRegionType::FORWARD) {
27 label = "F";
28 }
29
30 bool found = true;
31 // select label used in database.
32 if(PP->getType()==TGCSector::WTPP) label+="WT";
33 else if(PP->getType()==TGCSector::WDPP) label+="WD";
34 else if(PP->getType()==TGCSector::STPP) label+="ST";
35 else if(PP->getType()==TGCSector::SDPP) label+="SD";
36 else if(PP->getType()==TGCSector::WIPP) label+="WI";
37 else if(PP->getType()==TGCSector::SIPP) label+="SI";
38 else found = false;
39
40 if (!found) return;
41
42 std::string fn = TGCDatabaseManager::getFilename(1);
43
44 std::string fullName = PathResolver::find_file(fn, "PWD");
45 if( fullName.length() == 0 )
46 fullName = PathResolver::find_file(fn,"DATAPATH");
47 std::ifstream file(fullName.c_str() ,std::ios::in);
48
49 // find entries match in PatchPanel type.
50 int oPP,oCon,oCh,i1PP,i2PP,totalCh;
51 std::string inLabel;
52 while(file.getline(buf,BufferSize)){
53 std::istringstream line(buf);
54 line>>inLabel>>totalCh;
55 if(label==inLabel){
56 // create arrays store entries in database.
57 for( int i=0; i<NumberOfPPOutputConnector; i+=1){
58 line>>m_nCh[i];
59 //coverity[TAINTED_SCALAR]
60 m_patchPanelIn[i] = new TGCPatchPanel* [m_nCh[i]];
61 //coverity[TAINTED_SCALAR]
62 for( int j=0; j<m_nCh[i]; j+=1) m_patchPanelIn[i][j]=0;
63 m_connectorIn[i] = new int [m_nCh[i]];
64 m_channelIn[i] = new int [m_nCh[i]];
65 }
66 while(file.getline(buf,BufferSize)&&(isspace(buf[0])||isdigit(buf[0]))){
67 int iCon = 0;
68 int iCh = 0;
69 iCon=iCh=0;
70 std::istringstream line2(buf);
71 line2 >> oPP >> oCon >> oCh >> i1PP >> iCon >> iCh;
72 // When i1PP is equal to -1, the channel isn't used.
73 if((i1PP!=-1)&&(PP->getId()==oPP)){
74 if(PP->getId()==i1PP){
75 // Channel correspond to this output channel is in same board.
76 //coverity[TAINTED_SCALAR]
77 m_patchPanelIn[oCon][oCh]=PP;
78 }else{
79 // Channel correspond to this output channel is in adjacent boards.
80 if(PP->getAdjacentPP(0)!=0){
81 if(PP->getAdjacentPP(0)->getId()==i1PP){
82 //coverity[TAINTED_SCALAR]
83 m_patchPanelIn[oCon][oCh]=PP->getAdjacentPP(0);
84 }
85 }
86 if(PP->getAdjacentPP(1)!=0){
87 //coverity[TAINTED_SCALAR]
88 if(PP->getAdjacentPP(1)->getId()==i1PP){
89 m_patchPanelIn[oCon][oCh]=PP->getAdjacentPP(1);
90 }
91 }
92 }
93 m_connectorIn[oCon][oCh]=iCon;
94 m_channelIn[oCon][oCh]=iCh;
95#ifdef TGCDEBUG_CONNECTION
96 std::cout << "TGCConnectionInPP: " << label << " PPIn= " << i1PP
97 << " " << m_connectorIn[oCon][oCh]
98 << " " << m_channelIn[oCon][oCh]
99 << " PPOut= " << oPP << " " << oCon << " " << oCh;
100#endif
101
102 i2PP=iCon=iCh=0;
103 line2 >> i2PP >> iCon >> iCh;
104 // i2PP, iCon and iCh are PatchPanel ID, connector
105 // ID and channel number ored.
106 if((i2PP>0)||(iCon!=0)||(iCh!=0)){
107 if(m_oredPatchPanelIn[oCon]==0){
108 m_oredPatchPanelIn[oCon] = new TGCPatchPanel* [m_nCh[oCon]];
109 m_oredConnectorIn[oCon] = new int [m_nCh[oCon]];
110 m_oredChannelIn[oCon] = new int [m_nCh[oCon]];
111 for(int j=0; j<m_nCh[oCon]; j+=1) m_oredPatchPanelIn[oCon][j]=0;
112 }
113 m_oredConnectorIn[oCon][oCh]=iCon;
114 m_oredChannelIn[oCon][oCh]=iCh;
115#ifdef TGCDEBUG_CONNECTION
116 std::cout << " PPOR= " << i2PP << " " << m_oredConnectorIn[oCon][oCh]
117 << " " << m_oredChannelIn[oCon][oCh];
118#endif
119
120 if(PP->getId()==i2PP){
121 m_oredPatchPanelIn[oCon][oCh]=PP;
122 }else{
123 if(PP->getAdjacentPP(0)!=0){
124 if(PP->getAdjacentPP(0)->getId()==i2PP){
125 m_oredPatchPanelIn[oCon][oCh]=PP->getAdjacentPP(0);
126 }
127 }
128 if(PP->getAdjacentPP(1)!=0){
129 if(PP->getAdjacentPP(1)->getId()==i2PP){
130 m_oredPatchPanelIn[oCon][oCh]=PP->getAdjacentPP(1);
131 }
132 }
133 }
134 }
135
136#ifdef TGCDEBUG_CONNECTION
137 std::cout << std::endl;
138#endif
139
140 }
141 }
142 break;
143 }
144 }
145 file.close();
146}
147
149{
150 for( int i=0; i<NumberOfPPOutputConnector; i+=1){
151 if(m_oredPatchPanelIn[i]!=0) return true;
152 }
153 return false;
154}
155
157{
158 std::ofstream file;
159 file.open("dumpConnection.out", std::ios::out | std::ios::app);
160 file.setf(std::ios::right);
161
162 for( int i=0; i<NumberOfPPOutputConnector; i+=1){
163 for( int j=0; j<m_nCh[i]; j+=1){
164 if(m_patchPanelIn[i]!=0){
165 file.width(3); file<<PPId;
166 file.width(3); file<<i;
167 file.width(3); file<<j;
168 if(m_patchPanelIn[i][j]!=0){
169 file.width(3); file<<m_patchPanelIn[i][j]->getId();
170 file.width(3); file<<m_connectorIn[i][j];
171 file.width(3); file<<m_channelIn[i][j];
172 if(m_oredPatchPanelIn[i]!=0){
173 if(m_oredPatchPanelIn[i][j]!=0){
174 file.width(3); file<<m_oredPatchPanelIn[i][j]->getId();
175 file.width(3); file<<m_oredConnectorIn[i][j];
176 file.width(3); file<<m_oredChannelIn[i][j];
177 }
178 }
179 }else{
180 file.width(3); file<<-1;
181 file.width(3); file<<-1;
182 file.width(3); file<<-1;
183 }
184 file<<std::endl;
185 }
186 }
187 }
188
189 file.close();
190}
191
193{
194 for( int i=0; i<NumberOfPPOutputConnector; i+=1){
195 m_nCh[i] = 0;
196 m_patchPanelIn[i] = 0;
197 m_channelIn[i] = 0;
198 m_connectorIn[i] = 0;
199 m_oredPatchPanelIn[i] = 0;
200 m_oredChannelIn[i] = 0;
201 m_oredConnectorIn[i] = 0;
202 }
203}
204
206{
207 for( int i=0; i<NumberOfPPOutputConnector; i+=1){
208 if(m_patchPanelIn[i]!=0) delete [] m_patchPanelIn[i];
209 m_patchPanelIn[i] = 0;
210 if(m_channelIn[i]!=0) delete [] m_channelIn[i];
211 m_channelIn[i] = 0;
212 if(m_connectorIn[i]!=0) delete [] m_connectorIn[i];
213 m_connectorIn[i] = 0;
214
215 if(m_oredPatchPanelIn[i]!=0) delete [] m_oredPatchPanelIn[i];
216 m_oredPatchPanelIn[i] = 0;
217 if(m_oredChannelIn[i]!=0) delete [] m_oredChannelIn[i];
218 m_oredChannelIn[i] = 0;
219 if(m_oredConnectorIn[i]!=0) delete [] m_oredConnectorIn[i];
220 m_oredConnectorIn[i] = 0;
221 }
222}
223
224
226{
227 for( int i=0; i<NumberOfPPOutputConnector; i+=1){
228 m_nCh[i] = right.m_nCh[i];
229 int nPPOutCh = m_nCh[i];
230
231 m_patchPanelIn[i] = 0;
232 if(right.m_patchPanelIn[i]) {
233 m_patchPanelIn[i] = new TGCPatchPanel* [nPPOutCh];
234 for(int iCh=0; iCh<nPPOutCh; iCh++) m_patchPanelIn[i][iCh] = right.m_patchPanelIn[i][iCh];
235 }
236
237 m_channelIn[i] = 0;
238 if(right.m_channelIn[i]) {
239 m_channelIn[i] = new int [nPPOutCh];
240 for(int iCh=0; iCh<nPPOutCh; iCh++) m_channelIn[i][iCh] = right.m_channelIn[i][iCh];
241 }
242
243 m_connectorIn[i] = 0;
244 if(right.m_connectorIn[i]) {
245 m_connectorIn[i] = new int [nPPOutCh];
246 for(int iCh=0; iCh<nPPOutCh; iCh++) m_connectorIn[i][iCh] = right.m_connectorIn[i][iCh];
247 }
248
249 m_oredPatchPanelIn[i] = 0;
250 if(right.m_oredPatchPanelIn[i]) {
251 m_oredPatchPanelIn[i] = new TGCPatchPanel* [nPPOutCh];
252 for(int iCh=0; iCh<nPPOutCh; iCh++) m_oredPatchPanelIn[i][iCh] = right.m_oredPatchPanelIn[i][iCh];
253 }
254
255 m_oredChannelIn[i] = 0;
256 if(right.m_oredChannelIn[i]) {
257 m_oredChannelIn[i] = new int [nPPOutCh];
258 for(int iCh=0; iCh<nPPOutCh; iCh++) m_oredChannelIn[i][iCh] = right.m_oredChannelIn[i][iCh];
259 }
260
261 m_oredConnectorIn[i] = 0;
262 if(right.m_oredConnectorIn[i]) {
263 m_oredConnectorIn[i] = new int [nPPOutCh];
264 for(int iCh=0; iCh<nPPOutCh; iCh++) m_oredConnectorIn[i][iCh] = right.m_oredConnectorIn[i][iCh];
265 }
266 }
267}
268
271{
272 if( this != &right ) {
273 for( int i=0; i<NumberOfPPOutputConnector; i+=1){
274 m_nCh[i] = right.m_nCh[i];
275 int nPPOutCh = m_nCh[i];
276
277 delete [] m_patchPanelIn[i];
278 m_patchPanelIn[i] = 0;
279 if(right.m_patchPanelIn[i]) {
280 m_patchPanelIn[i] = new TGCPatchPanel* [nPPOutCh];
281 for(int iCh=0; iCh<nPPOutCh; iCh++) m_patchPanelIn[i][iCh] = right.m_patchPanelIn[i][iCh];
282 }
283
284 delete [] m_channelIn[i];
285 m_channelIn[i] = 0;
286 if(right.m_channelIn[i]) {
287 m_channelIn[i] = new int [nPPOutCh];
288 for(int iCh=0; iCh<nPPOutCh; iCh++) m_channelIn[i][iCh] = right.m_channelIn[i][iCh];
289 }
290
291 delete [] m_connectorIn[i];
292 m_connectorIn[i] = 0;
293 if(right.m_connectorIn[i]) {
294 m_connectorIn[i] = new int [nPPOutCh];
295 for(int iCh=0; iCh<nPPOutCh; iCh++) m_connectorIn[i][iCh] = right.m_connectorIn[i][iCh];
296 }
297
298 delete [] m_oredPatchPanelIn[i];
299 m_oredPatchPanelIn[i] = 0;
300 if(right.m_oredPatchPanelIn[i]) {
301 m_oredPatchPanelIn[i] = new TGCPatchPanel* [nPPOutCh];
302 for(int iCh=0; iCh<nPPOutCh; iCh++) m_oredPatchPanelIn[i][iCh] = right.m_oredPatchPanelIn[i][iCh];
303 }
304
305 delete [] m_oredChannelIn[i];
306 m_oredChannelIn[i] = 0;
307 if(right.m_oredChannelIn[i]) {
308 m_oredChannelIn[i] = new int [nPPOutCh];
309 for(int iCh=0; iCh<nPPOutCh; iCh++) m_oredChannelIn[i][iCh] = right.m_oredChannelIn[i][iCh];
310 }
311
312 delete [] m_oredConnectorIn[i];
313 m_oredConnectorIn[i] = 0;
314 if(right.m_oredConnectorIn[i]) {
315 m_oredConnectorIn[i] = new int [nPPOutCh];
316 for(int iCh=0; iCh<nPPOutCh; iCh++) m_oredConnectorIn[i][iCh] = right.m_oredConnectorIn[i][iCh];
317 }
318 }
319 }
320 return *this;
321}
322
323int TGCConnectionInPP::getChannelIn(int connectorOut, int chOut)
324{
325 return m_channelIn[connectorOut][chOut];
326}
327
328int TGCConnectionInPP::getConnectorIn(int connectorOut, int chOut)
329{
330 return m_connectorIn[connectorOut][chOut];
331}
332
333TGCPatchPanel* TGCConnectionInPP::getPPIn(int connectorOut, int chOut)
334{
335 if(m_patchPanelIn[connectorOut]!=0)
336 return m_patchPanelIn[connectorOut][chOut];
337 else
338 return 0;
339}
340
341int TGCConnectionInPP::getOredChannelIn(int connectorOut, int chOut)
342{
343 return m_oredChannelIn[connectorOut][chOut];
344}
345
346int TGCConnectionInPP::getOredConnectorIn(int connectorOut, int chOut)
347{
348 return m_oredConnectorIn[connectorOut][chOut];
349}
350
352{
353 if(m_oredPatchPanelIn[connectorOut]!=0)
354 return m_oredPatchPanelIn[connectorOut][chOut];
355 else
356 return 0;
357}
358
360 const std::vector<const TGCPatchPanel*>& oldPatchPanels)
361{
362 // The size of oldPatchPanels should be 3.
363 // oldPatchPanels.at(0) : oldPatchPanel
364 // oldPatchPanels.at(1) : oldPatchPanel->getAdjacentPP(0)
365 // oldPatchPanels.at(2) : oldPatchPanel->getAdjacentPP(1)
366 if(oldPatchPanels.size()!=3) return false;
367
368 for(int i=0; i<NumberOfPPOutputConnector; i++) {
369 int nPPOutCh = m_nCh[i];
370 if(m_patchPanelIn[i]) {
371 for(int iCh=0; iCh<nPPOutCh; iCh++) {
372 // Null pointers are NOT updated.
373 if(m_patchPanelIn[i][iCh]) {
374 if( m_patchPanelIn[i][iCh]==oldPatchPanels.at(0)) {
375 m_patchPanelIn[i][iCh] = newPatchPanel;
376 } else if(m_patchPanelIn[i][iCh]==oldPatchPanels.at(1)) {
377 m_patchPanelIn[i][iCh] = newPatchPanel->getAdjacentPP(0);
378 } else if(m_patchPanelIn[i][iCh]==oldPatchPanels.at(2)) {
379 m_patchPanelIn[i][iCh] = newPatchPanel->getAdjacentPP(1);
380 } else { // This should not happen.
381 return false;
382 }
383 }
384 }
385 }
386
387 if(m_oredPatchPanelIn[i]) {
388 for(int iCh=0; iCh<nPPOutCh; iCh++) {
389 // Null pointers are NOT updated.
390 if(m_oredPatchPanelIn[i][iCh]) {
391 if( m_oredPatchPanelIn[i][iCh]==oldPatchPanels.at(0)) {
392 m_oredPatchPanelIn[i][iCh] = newPatchPanel;
393 } else if(m_oredPatchPanelIn[i][iCh]==oldPatchPanels.at(1)) {
394 m_oredPatchPanelIn[i][iCh] = newPatchPanel->getAdjacentPP(0);
395 } else if(m_oredPatchPanelIn[i][iCh]==oldPatchPanels.at(2)) {
396 m_oredPatchPanelIn[i][iCh] = newPatchPanel->getAdjacentPP(1);
397 } else { // This should not happen.
398 return false;
399 }
400 }
401 }
402 }
403 }
404
405 return true;
406}
407
408} //end of namespace bracket
int * m_oredConnectorIn[NumberOfPPOutputConnector]
int getConnectorIn(int connectorOut, int chOut)
int m_nCh[NumberOfPPOutputConnector]
int * m_oredChannelIn[NumberOfPPOutputConnector]
TGCPatchPanel ** m_patchPanelIn[NumberOfPPOutputConnector]
TGCPatchPanel ** m_oredPatchPanelIn[NumberOfPPOutputConnector]
int * m_channelIn[NumberOfPPOutputConnector]
void readConnectionTable(TGCPatchPanel *PP)
int getOredChannelIn(int connectorOut, int chOut)
int getOredConnectorIn(int connectorOut, int chOut)
TGCPatchPanel * getPPIn(int connectorOut, int chOut)
TGCConnectionInPP & operator=(const TGCConnectionInPP &right)
bool replacePatchPanelPointers(TGCPatchPanel *newPatchPanel, const std::vector< const TGCPatchPanel * > &oldPatchPanels)
TGCPatchPanel * getOredPPIn(int connectorOut, int chOut)
int getChannelIn(int connectorOut, int chOut)
int * m_connectorIn[NumberOfPPOutputConnector]
static std::string getFilename(int type)
TGCPatchPanel * getAdjacentPP(int side)
TGCRegionType getRegion() const
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
std::string label(const std::string &format, int i)
Definition label.h:19
const int NumberOfPPOutputConnector
TFile * file