ATLAS Offline Software
TGCHitPattern.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <iostream>
7 #include <cstdlib>
8 #include <cstring>
9 
10 namespace LVL1TGCTrigger {
11 
13  :m_pattern(0),m_length(-1)
14 {
15 }
16 
18 {
19  if(m_pattern!=0) delete [] m_pattern;
20  m_pattern = 0;
21  m_length =-1;
22 }
23 
25  :m_pattern(0), m_length(len)
26 {
27  if ( m_length > 0 ) {
28  m_pattern = new bool [len];
29  for(int i=0; i<m_length; i+=1) m_pattern[i] = false;
30  } else {
31  m_length = -1;
32  }
33 }
34 
36  :m_pattern(0),m_length(-1)
37 {
38  m_length = right.m_length;
39  if ( m_length > 0 ) {
40  m_pattern = new bool [m_length];
41  for(int i=0; i<m_length; i+=1 ) {
42  m_pattern[i] = right.m_pattern[i];
43  }
44  }
45 }
46 
48 {
49  if (this != &right) {
50  if ( m_pattern != 0 ) delete [] m_pattern;
51  m_pattern = 0;
52 
53  m_length = right.m_length;
54  if ( m_length > 0 ) {
55  m_pattern = new bool [m_length];
56  for(int i=0; i<m_length; i+=1 ) {
57  m_pattern[i] = right.m_pattern[i];
58  }
59  }
60  }
61  return *this;
62 }
63 
64 bool TGCHitPattern::getChannel(int iChannel) const
65 {
66  if(iChannel < m_length){
67  return m_pattern[iChannel];
68  }else{
69  std::cerr << "internal error TGCHitPattern::getChannel()" << std::endl;
70  return 0;
71  }
72 }
73 
74 void TGCHitPattern::setLength(int lengthIn)
75 {
76  m_length = lengthIn;
77 
78  if ( m_length > 0 ) {
79  if ( m_pattern != 0) delete [] m_pattern;
80  m_pattern = new bool [m_length];
81  }
82 }
83 
84 
85 void TGCHitPattern::setChannel(int iChannel, bool hit)
86 {
87  m_pattern[iChannel] = hit;
88 }
89 
91  int size = strlen(pat);
92  if(size == m_length){
93  for(int i = 0; i < size; i++){
94  if(pat[i]-'0'){
95  setChannel(i, true);
96  }
97  }
98  } else {
99 #ifdef TGCCOUT
100  std::cout << "TGCHitPattern::setChannel() error : size is different" << std::endl;
101 #endif
102  }
103 }
104 
106 {
107  int i;
108  for( i=0; i<m_length; i+=1) m_pattern[i] = false;
109 }
110 
111 void TGCHitPattern::print(int unit) const
112 {
113  int i;
114  for( i=0; i<m_length; i+=1){
115  if(i%unit==0) std::cout<<"\n_";
116  if(m_pattern[i])
117  std::cout << 1;
118  else
119  std::cout << 0;
120  }
121  std::cout << std::endl;
122 }
123 
124 void TGCHitPattern::print() const
125 {
126 
127 #ifdef BITPATTERN
128  std::cout << " [" << m_length << "bit] ";
129 #endif
130 #ifdef BITPATTERN
131  for( int i=0; i<m_length; i+=1)
132  std::cout << m_pattern[i] <<std::endl;
133 #endif
134 #ifdef TGCCOUT
135  for( int i=0; i<m_length; i+=1)
136  if(m_pattern[i]) std::cout<<' '<<i;
137  std::cout << std::endl;
138 #endif
139 }
140 
142 {
143 #ifdef TGCCOUT
144  for( int i=0; i<m_length; i+=1){
145  std::cout << m_pattern[i];
146  }
147 #endif
148 }
149 
150 void TGCHitPattern::printb(std::ofstream* ofs) const
151 {
152  int i;
153  for( i=0; i<m_length; i+=1){
154  *ofs << m_pattern[i];
155  }
156 }
157 
159 {
160  bool* ptmp;
161  ptmp = 0;
162  ptmp = new bool [hp->getLength() + m_length];
163  int i;
164  for(i=0; i<m_length ; i++){
165  ptmp[i] = m_pattern[i];
166  }
167  for(i=m_length; i<(hp->getLength() + m_length); i++){
168  ptmp[i] = hp->getChannel(i-m_length);
169  }
170  if(m_pattern)delete [] m_pattern;
171  m_pattern = ptmp;
172  m_length = hp->getLength() + m_length;
173 }
174 
176 {
177  for(int i= m_length -1; i >= 0; i--){
178  if( (dec >> i) & 1 )
179  m_pattern[m_length-1-i] = 1;
180  else
181  m_pattern[m_length-1-i] = 0;
182  }
183 }
184 
185 
186 // new method for hit visualization (KH 19/01/01)
187 #ifdef TGCCOUT
188 void TGCHitPattern::visual(int Cycle, int Width , int Tag ) const
189 {
190  int i,j;
191  if (Tag == 1) {
192  std::cout << "| ";
193  for(i=0; i<Cycle; i++) {
194  for (j=0; j<Width; j++) std::cout << "=";
195  }
196  std::cout << " |\n| ";
197  for(i=0; i<Cycle; i++) {
198  for (j=0; j<Width; j++) {
199  if ((j == 0) && (i%10 == 0)) std::cout << i/10;
200  else std::cout << " ";
201  }
202  }
203 
204  std::cout << " |\n| ";
205  for(i=0; i<Cycle; i++) {
206  for (j=0; j<Width; j++) {
207  if (j == 0) std::cout << i%10;
208  else std::cout << " ";
209  }
210  }
211 
212  std::cout << " |\n| ";
213  for(i=0; i<Cycle; i++) {
214  for (j=0; j<Width; j++) std::cout << "-";
215  }
216 
217  std::cout << " |\n";
218  }
219  else {
220  std::cout << "| ";
221  for(i=0; i<m_length; i++) {
222  if ((i>0) && (i%Cycle==0)) std::cout<<" |\n| ";
223  for (j=0; j<Width; j++) {
224  if(m_pattern[i]) std::cout << "*";
225  else std::cout << ".";
226  }
227  }
228  std::cout << " |\n";
229  }
230 }
231 #else
232 void TGCHitPattern::visual(int , int , int ) const
233 {
234  // do nothing
235 }
236 #endif
237 
238 // new method to set hit patterns (KH 08/05/01)
239 void TGCHitPattern::setPattern(bool* newpattern)
240 {
241  if(m_pattern)delete [] m_pattern;
242  m_pattern = newpattern;
243 }
244 
245 
246 
247 } //end of namespace bracket
athena_checkUpload.Tag
string Tag
Definition: athena_checkUpload.py:189
LVL1TGCTrigger::TGCHitPattern::getLength
int getLength() const
Definition: TGCHitPattern.h:49
LVL1TGCTrigger::TGCHitPattern::printb
void printb() const
Definition: TGCHitPattern.cxx:141
TGCHitPattern.h
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
LVL1TGCTrigger::TGCHitPattern::setLength
void setLength(int length)
Definition: TGCHitPattern.cxx:74
lumiFormat.i
int i
Definition: lumiFormat.py:85
LVL1TGCTrigger::TGCHitPattern::print
void print() const
Definition: TGCHitPattern.cxx:124
LVL1TGCTrigger::TGCHitPattern::push_back
void push_back(TGCHitPattern *hp)
Definition: TGCHitPattern.cxx:158
LVL1TGCTrigger::TGCHitPattern::getChannel
bool getChannel(int iChannel) const
Definition: TGCHitPattern.cxx:64
LVL1TGCTrigger::TGCHitPattern::clear
void clear()
Definition: TGCHitPattern.cxx:105
LVL1TGCTrigger
Definition: LVL1TGCTrigger.cxx:47
LVL1TGCTrigger::TGCHitPattern
Definition: TGCHitPattern.h:11
dso-stats.pat
pat
Definition: dso-stats.py:39
LVL1TGCTrigger::TGCHitPattern::setChannel
void setChannel(int iChannel, bool pattern)
Definition: TGCHitPattern.cxx:85
LVL1TGCTrigger::TGCHitPattern::dec2bin
void dec2bin(int dec)
Definition: TGCHitPattern.cxx:175
LVL1TGCTrigger::TGCHitPattern::m_length
int m_length
Definition: TGCHitPattern.h:45
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:21
LVL1TGCTrigger::TGCHitPattern::operator=
TGCHitPattern & operator=(const TGCHitPattern &right)
Definition: TGCHitPattern.cxx:47
LVL1TGCTrigger::TGCHitPattern::TGCHitPattern
TGCHitPattern()
Definition: TGCHitPattern.cxx:12
LVL1TGCTrigger::TGCHitPattern::~TGCHitPattern
~TGCHitPattern()
Definition: TGCHitPattern.cxx:17
LVL1TGCTrigger::TGCHitPattern::visual
void visual(int Cycle, int Width, int Tag) const
Definition: TGCHitPattern.cxx:232
LVL1TGCTrigger::TGCHitPattern::setPattern
void setPattern(bool *newpattern)
Definition: TGCHitPattern.cxx:239
LVL1TGCTrigger::TGCHitPattern::m_pattern
bool * m_pattern
Definition: TGCHitPattern.h:44