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