sspmapmaker_v1.c
Go to the documentation of this file.
1 /***
2  *
3  * Author: Alex Himmmel, Tom Junk
4  *
5  * HORRENDOUS hack -- copy-pasted most contents from dunetpc/dune/Geometry/ProtoDUNEChannelMapAlg.h
6  *
7  */
8 
9 #include <stdio.h>
10 #include <map>
11 #include <iostream>
12 #include <iomanip>
13 
14 typedef unsigned int Index;
15 
16 std::map<Index, Index> fSSP;
17 std::map<Index, Index> fSSPChOne;
18 std::map<Index, Index> fOpDet;
19 std::map<Index, Index> fHWChannel;
20 
23 
24 
25 Index NOpChannels(Index /*NOpDets*/);
26 Index MaxOpChannel(Index /*NOpDets*/);
29 Index OpDetFromOpChannel(Index opChannel);
31 void SSPandCh(Index detNum, Index channel, Index &ssp, Index &sspch);
32 Index OpChannelFromSSP(Index ssp, Index sspch);
33 bool IsValidOpChannel(Index opChannel, Index /*NOpDets*/);
34 
35 void PrintChannelMaps();
36 
37 
38 /* This assumes the first 10 channels of each SSP are wired up with channels and the last two
39  are empty. Assumes channels increase with Y */
40 
42 {
43 
44 
45  // Manually entered based on maps from Chris Macias
46  //
47  // That gives SSP and channel ranges from OpDet. These offline channels correspond
48  // to the APAs listed. Channel numbers increase by 2 going from top to bottom
49  //
50  // USDaS MSDaS DSDaS
51  // 41-59 21-39 1-19
52  //
53  // USRaS MSRaS DSRaS
54  // 40-58 20-38 0-18
55 
56 
57  // DSDaS -- "normal" pattern
58  fSSP[ 1] = 41; fSSPChOne[ 1] = 0;
59  fSSP[ 3] = 41; fSSPChOne[ 3] = 4;
60  fSSP[ 5] = 41; fSSPChOne[ 5] = 8;
61  fSSP[ 7] = 42; fSSPChOne[ 7] = 0;
62  fSSP[ 9] = 42; fSSPChOne[ 9] = 4;
63  fSSP[11] = 42; fSSPChOne[11] = 8;
64  fSSP[13] = 43; fSSPChOne[13] = 0;
65  fSSP[15] = 43; fSSPChOne[15] = 4;
66  fSSP[17] = 43; fSSPChOne[17] = 8;
67  fSSP[19] = 44; fSSPChOne[19] = 0;
68 
69  // MSDaS -- unusual pattern for ARAPUCA
70  fSSP[21] = 61; fSSPChOne[21] = 0;
71  fSSP[23] = 61; fSSPChOne[23] = 4;
72  fSSP[25] = 61; fSSPChOne[25] = 8;
73  fSSP[27] = 62; fSSPChOne[27] = 0;
74  fSSP[29] = 62; fSSPChOne[29] = 4;
75  fSSP[31] = 63; fSSPChOne[31] = 0; // ARAPUCA
76  fSSP[33] = 62; fSSPChOne[33] = 8;
77  fSSP[35] = 64; fSSPChOne[35] = 0;
78  fSSP[37] = 64; fSSPChOne[37] = 4;
79  fSSP[39] = 64; fSSPChOne[39] = 8;
80 
81  // USDaS -- unusual pattern
82  fSSP[41] = 53; fSSPChOne[41] = 0;
83  fSSP[43] = 53; fSSPChOne[43] = 4;
84  fSSP[45] = 53; fSSPChOne[45] = 8;
85  fSSP[47] = 54; fSSPChOne[47] = 0;
86  fSSP[49] = 51; fSSPChOne[49] = 0;
87  fSSP[51] = 54; fSSPChOne[51] = 4;
88  fSSP[53] = 51; fSSPChOne[53] = 4;
89  fSSP[55] = 51; fSSPChOne[55] = 8;
90  fSSP[57] = 54; fSSPChOne[57] = 8;
91  fSSP[59] = 52; fSSPChOne[59] = 0;
92 
93  // DSRaS -- "normal" pattern
94  fSSP[ 0] = 11; fSSPChOne[ 0] = 0;
95  fSSP[ 2] = 11; fSSPChOne[ 2] = 4;
96  fSSP[ 4] = 11; fSSPChOne[ 4] = 8;
97  fSSP[ 6] = 12; fSSPChOne[ 6] = 0;
98  fSSP[ 8] = 12; fSSPChOne[ 8] = 4;
99  fSSP[10] = 12; fSSPChOne[10] = 8;
100  fSSP[12] = 13; fSSPChOne[12] = 0;
101  fSSP[14] = 13; fSSPChOne[14] = 4;
102  fSSP[16] = 13; fSSPChOne[16] = 8;
103  fSSP[18] = 14; fSSPChOne[18] = 0;
104 
105  // MSRaS -- "normal" pattern
106  fSSP[20] = 21; fSSPChOne[20] = 0;
107  fSSP[22] = 21; fSSPChOne[22] = 4;
108  fSSP[24] = 21; fSSPChOne[24] = 8;
109  fSSP[26] = 22; fSSPChOne[26] = 0;
110  fSSP[28] = 22; fSSPChOne[28] = 4;
111  fSSP[30] = 22; fSSPChOne[30] = 8;
112  fSSP[32] = 23; fSSPChOne[32] = 0;
113  fSSP[34] = 23; fSSPChOne[34] = 4;
114  fSSP[36] = 23; fSSPChOne[36] = 8;
115  fSSP[38] = 24; fSSPChOne[38] = 0;
116 
117  // USRaS -- unusual pattern for ARAPUCA
118  fSSP[40] = 31; fSSPChOne[40] = 0;
119  fSSP[42] = 31; fSSPChOne[42] = 4;
120  fSSP[44] = 31; fSSPChOne[44] = 8;
121  fSSP[46] = 34; fSSPChOne[46] = 0; // ARAPUCA
122  fSSP[48] = 32; fSSPChOne[48] = 0;
123  fSSP[50] = 32; fSSPChOne[50] = 4;
124  fSSP[52] = 32; fSSPChOne[52] = 8;
125  fSSP[54] = 33; fSSPChOne[54] = 0;
126  fSSP[56] = 33; fSSPChOne[56] = 4;
127  fSSP[58] = 33; fSSPChOne[58] = 8;
128  // The above enables OpDet + HW channel -> OpChannel
129  //
130  // Fill the maps below to do the reverse by looping through
131  // all possible OpDet and HW Channel combinations
132 
133  int fMaxOpChannel = 0;
134  int fNOpChannels = 0;
135 
136  for (Index opDet = 0; opDet < 60; opDet++) {
137  for (Index hwCh = 0; hwCh < NOpHardwareChannels(opDet); hwCh++) {
138 
139  // Find the channel number for this opDet and hw channel
140  Index opChannel = OpChannel(opDet, hwCh);
141 
142  // Count channels and record the maximum possible channel
143  if (opChannel > fMaxOpChannel) fMaxOpChannel = opChannel;
144  fNOpChannels++;
145 
146  // Fill maps for opChannel -> opDet and hwChannel
147  fOpDet[opChannel] = opDet;
148  fHWChannel[opChannel] = hwCh;
149  }
150  }
151 
152 
153 
154 
155  //PrintChannelMaps();
156 
157 
158  for (Index ionline=0; ionline<fMaxOpChannel; ++ionline)
159  {
160  if (! IsValidOpChannel(ionline, 60) ) {
161  continue;
162  }
163 
164  Index OpDet = OpDetFromOpChannel(ionline);
165  Index hwChannel = HardwareChannelFromOpChannel(ionline);
166  Index ssp, sspch;
167 
168  SSPandCh(OpDet, hwChannel, ssp, sspch);
169 
170  int APA = ssp/10;
171 
172  printf("%5d %5d %5d %5d %5d %5d %5d\n",ionline,APA,ssp,ssp,sspch,OpDet,ionline);
173  }
174 
175 }
176 
177 
178 
179 
180 
181 //----------------------------------------------------------------------------
182 
183 Index NOpChannels(Index /*NOpDets*/) {
184  return fNOpChannels;
185 }
186 
187 //----------------------------------------------------------------------------
188 
189 Index MaxOpChannel(Index /*NOpDets*/) {
190  return fMaxOpChannel;
191 }
192 
193 //----------------------------------------------------------------------------
194 
196 
197  // ARAPUCAs
198  if (opDet == 31 or opDet == 46)
199  return 12;
200  else
201  return 4;
202 }
203 
204 //----------------------------------------------------------------------------
205 
206 void SSPandCh(Index detNum, Index channel, Index &ssp, Index &sspch) {
207  sspch = fSSPChOne.at(detNum) + channel;
208  ssp = fSSP.at(detNum);
209 
210  // Special handling of ARAPUCA in MSDaS which cross between SSP 62 and 63
211  if (sspch > 12)
212  std::cerr << "Invalid address: SSP #" << ssp << ", SSP channel" << sspch << std::endl;;
213 
214 }
215 
216 //----------------------------------------------------------------------------
217 
219  Index ssp, sspch;
220  SSPandCh(detNum, channel, ssp, sspch);
221 
222  return OpChannelFromSSP(ssp, sspch);
223 }
224 
225 //----------------------------------------------------------------------------
226 
228  if (!IsValidOpChannel(opChannel, 60)) {
229  std::cout << "Requesting an OpDet number for an uninstrumented channel, " << opChannel << std::endl;
230  return 99999;
231  }
232  return fOpDet.at(opChannel);
233 }
234 
235 //----------------------------------------------------------------------------
236 
238  if (!IsValidOpChannel(opChannel, 60)) {
239  std::cout << "Requesting an OpDet number for an uninstrumented channel, " << opChannel << std::endl;
240  return 99999;
241  }
242  return fHWChannel.at(opChannel);
243 }
244 
245 
246 //----------------------------------------------------------------------------
247 
249  // Expects SSP #'s of the from NM where N is APA number and M is SSP within the APA
250  // So, IP 504 -> AP # 54
251 
252  // ( ( APA # - 1 ) )*4 + SSP per APA)*12 + SSP channel
253  Index ch = ( (trunc(ssp/10) - 1)*4 + ssp%10 - 1 )*12 + sspch;
254  return ch;
255 
256 }
257 
258 //----------------------------------------------------------------------------
259 
260 bool IsValidOpChannel(Index opChannel, Index /*NOpDets*/)
261 {
262  return fOpDet.count(opChannel);
263 }
264 
265 //----------------------------------------------------------------------------
266 
267 
269 
270 
271  cout << "---------------------------------------------------------------" << endl;
272  cout << "---------------------------------------------------------------" << endl;
273  cout << "---------------------------------------------------------------" << endl;
274  cout << "---------------------------------------------------------------" << endl;
275  cout << "---------------------------------------------------------------" << endl;
276  cout << "---------------------------------------------------------------" << endl;
277  cout << "---------------------------------------------------------------" << endl;
278  cout << endl << endl;
279 
280  std::vector<Index> ssps = { 11, 12, 13, 14,
281  21, 22, 23, 24,
282  31, 32, 33, 34,
283  41, 42, 43, 44,
284  51, 52, 53, 54,
285  61, 62, 63, 64 };
286 
287  cout << endl << "By SSP" << endl;
288  for (Index ssp : ssps) {
289  for (Index sspch = 0; sspch < 12; sspch++) {
290  cout << setw(2) << ssp << " " << setw(2) << sspch << ": " << setw(3) << OpChannelFromSSP(ssp, sspch) << endl;
291  }
292  }
293 
294  cout << endl << "Beam side" << endl;
295  for (Index opDet = 1; opDet < 60; opDet += 2) {
296  cout << setw(2) << opDet << ":";
297  for (Index hwCh = 0; hwCh < NOpHardwareChannels(opDet); hwCh++) {
298  cout << " " << setw(2) << OpChannel(opDet, hwCh);
299  }
300  cout << endl;
301  }
302 
303 
304  cout << endl << "Non-Beam side" << endl;
305  for (Index opDet = 0; opDet < 60; opDet += 2) {
306  cout << setw(2) << opDet << ":";
307  for (Index hwCh = 0; hwCh < NOpHardwareChannels(opDet); hwCh++) {
308  cout << " " << setw(2) << OpChannel(opDet, hwCh);
309  }
310  cout << endl;
311  }
312 
313 
314  cout << endl << "Online -> offline" << endl;
315  for (Index opCh = 0; opCh < MaxOpChannel(60); opCh++) {
316  cout << setw(3) << opCh << ": ";
317  if ( IsValidOpChannel(opCh, 60) ) {
318  cout << setw(2) << OpDetFromOpChannel(opCh) << ", "
319  << setw(2) << HardwareChannelFromOpChannel(opCh) << endl;
320  }
321  else {
322  cout << "empty channel" << endl;
323  }
324  }
325 
326  cout << endl << endl;
327  cout << "---------------------------------------------------------------" << endl;
328  cout << "---------------------------------------------------------------" << endl;
329  cout << "---------------------------------------------------------------" << endl;
330  cout << "---------------------------------------------------------------" << endl;
331  cout << "---------------------------------------------------------------" << endl;
332  cout << "---------------------------------------------------------------" << endl;
333  cout << "---------------------------------------------------------------" << endl;
334 
335 }
Index OpChannel(Index detNum, Index channel)
std::map< Index, Index > fSSP
void sspmapmaker_v1()
uint8_t channel
Definition: CRTFragment.hh:201
unsigned int Index
Index OpDetFromOpChannel(Index opChannel)
std::map< Index, Index > fOpDet
void SSPandCh(Index detNum, Index channel, Index &ssp, Index &sspch)
Index HardwareChannelFromOpChannel(Index opChannel)
bool IsValidOpChannel(Index opChannel, Index)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Index NOpChannels(Index)
Index NOpHardwareChannels(Index opDet)
Index OpChannelFromSSP(Index ssp, Index sspch)
void PrintChannelMaps()
int fNOpChannels
int fMaxOpChannel
Index MaxOpChannel(Index)
std::map< Index, Index > fHWChannel
QTextStream & endl(QTextStream &s)
std::map< Index, Index > fSSPChOne