CMap.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief cmap::CMap class source code
3 /// \author jpaley@fnal.gov
4 /// \date Sept. 2016
5 ////////////////////////////////////////////////////////////////////////
6 #include "CMap/CMap.h"
7 
8 // NOvA includes
9 #include "RawData/RawDigit.h"
10 #include "RecoBase/CellHit.h"
11 
13 
14 // ART includes
16 
17 namespace cmap {
18  namespace dataprov {
19 
20  //----------------------------------------------------------------------
22  {
23  fVerbosity = 0;
24  fCurrentRun = 0;
25  fUseExceptions = false;
26  fExceptionsMap.clear();
27  fStdMap = 0;
28  }
29 
30  //----------------------------------------------------------------------
32  {
33  fVerbosity = 0;
34  fCurrentRun = 0;
35  fUseExceptions = false;
36  fExceptionsMap.clear();
37  fStdMap = map;
38  }
39 
40  //----------------------------------------------------------------------
42  {
43 
44  }
45 
46  //----------------------------------------------------------------------
47  void CMap::AddException(int idet, std::string chan1, std::string chan2)
48  {
49  LOG_INFO("CMap") << "Adding exception " << chan1 << "->" << chan2;
50 
51  int ndashes1=0;
52  int ndashes2=0;
53 
54  for (size_t i=0; i<chan1.length(); ++i) {
55  if (chan1[i] == '-') ndashes1++;
56  }
57  for (size_t i=0; i<chan2.length(); ++i) {
58  if (chan2[i] == '-') ndashes2++;
59  }
60 
61  if ((ndashes1 != ndashes2) || ndashes1==0) {
62  LOG_ERROR("CMap") << "Mismatch in string formats for the two channels! Please use either [diblock]-[dcm]-[feb], [diblock]-[dcm]-[feb]-[pixel], or [plane]-[cell].";
63  return;
64  }
65 
66  int plane, cell;
67  int db, dcm, feb, pixel;
68 
69  if (ndashes1 == 1) {
70  sscanf(chan1.c_str(),"%d-%d",&plane,&cell);
71  daqchannelmap::lchan logChan = this->Map()->encodeLChan(idet,plane,cell);
72  daqchannelmap::dchan daqChan1 = this->Map()->encodeDChan(logChan);
73  sscanf(chan2.c_str(),"%d-%d",&plane,&cell);
74  logChan = this->Map()->encodeLChan(idet,plane,cell);
75  daqchannelmap::dchan daqChan2 = this->Map()->encodeDChan(logChan);
76  this->AddException(daqChan1,daqChan2);
77  }
78  else if (ndashes1==3) {
79  sscanf(chan1.c_str(),"%d-%d-%d-%d",&db,&dcm,&feb,&pixel);
80  daqchannelmap::dchan daqChan1 = this->Map()->encodeDChan(idet,db,dcm,feb,pixel);
81  sscanf(chan2.c_str(),"%d-%d-%d-%d",&db,&dcm,&feb,&pixel);
82  daqchannelmap::dchan daqChan2 = this->Map()->encodeDChan(idet,db,dcm,feb,pixel);
83  this->AddException(daqChan1,daqChan2);
84  }
85  else if (ndashes1==2) { // handle case for an entire FEB
86  sscanf(chan1.c_str(),"%d-%d-%d",&db,&dcm,&feb);
87  daqchannelmap::dchan daqChan1 = this->Map()->encodeDChan(idet,db,dcm,feb,0);
88  sscanf(chan2.c_str(),"%d-%d-%d",&db,&dcm,&feb);
89  daqchannelmap::dchan daqChan2 = this->Map()->encodeDChan(idet,db,dcm,feb,0);
90  for (int i=0; i<32; ++i) {
91  this->AddException(daqChan1+i,daqChan2+i);
92  }
93  }
94  else {
95  LOG_ERROR("CMap") << "Channel string format unsupported. Please use either [diblock]-[dcm]-[feb], [diblock]-[dcm]-[feb]-[pixel], or [plane]-[cell].";
96  return;
97  }
98 
99  }
100 
101  //----------------------------------------------------------------------
103  {
104  daqchannelmap::lchan logChan = this->Map()->encodeLChan(idet,chan1.Plane(),chan1.Cell());
105  daqchannelmap::dchan daqChan1 = this->Map()->encodeDChan(logChan);
106  logChan = this->Map()->encodeLChan(idet,chan2.Plane(),chan2.Cell());
107  daqchannelmap::dchan daqChan2 = this->Map()->encodeDChan(logChan);
108  this->AddException(daqChan1,daqChan2);
109 
110  }
111 
112  //----------------------------------------------------------------------
114  {
115  daqchannelmap::lchan lc = this->Map()->encodeLChan(detId,plane,cell);
116  if (fUseExceptions) {
117  if (fVerbosity)
118  LOG_DEBUG("CMap") << "Exceptions enabled.";
119  daqchannelmap::dchan dchan = this->Map()->encodeDChan(lc);
120  if (fExceptionsMap.find(dchan) != fExceptionsMap.end()) {
121  dchan = fExceptionsMap[dchan];
122  lc = this->Map()->encodeLChan(dchan);
123  }
124  }
125 
126  return lc;
127  }
128 
129  //----------------------------------------------------------------------
131  {
132  daqchannelmap::dchan dc = this->Map()->encodeDChan(lchan);
133  if (fUseExceptions) {
134  if (fVerbosity)
135  LOG_DEBUG("CMap") << "Exceptions enabled.";
136  if (fExceptionsMap.find(dc) != fExceptionsMap.end()) {
137  dc = fExceptionsMap[dc];
138  }
139  }
140 
141  return dc;
142  }
143 
144  //----------------------------------------------------------------------
146  {
147  int block = this->Map()->computeBlock(lchan);
148  if (fUseExceptions) {
149  if (fVerbosity)
150  LOG_DEBUG("CMap") << "Exceptions enabled.";
151  daqchannelmap::dchan dc = this->Map()->encodeDChan(lchan);
152  if (fExceptionsMap.find(dc) != fExceptionsMap.end()) {
153  dc = fExceptionsMap[dc];
154  block = this->Map()->computeBlock(this->Map()->encodeLChan(dc));
155  }
156  }
157  return block;
158  }
159 
160  //----------------------------------------------------------------------
162  {
163  int det = this->Map()->getDetector(dc);
164  if (fUseExceptions) {
165  if (fVerbosity)
166  LOG_DEBUG("CMap") << "Exceptions enabled.";
167  if (fExceptionsMap.find(dc) != fExceptionsMap.end()) {
168  dc = fExceptionsMap[dc];
169  det = this->Map()->getDetector(dc);
170  }
171  }
172  return det;
173  }
174 
175  //----------------------------------------------------------------------
177  {
178  int block = this->Map()->getDiBlock(dc);
179  if (fUseExceptions) {
180  if (fVerbosity)
181  LOG_DEBUG("CMap") << "Exceptions enabled.";
182  if (fExceptionsMap.find(dc) != fExceptionsMap.end()) {
183  dc = fExceptionsMap[dc];
184  block = this->Map()->getDiBlock(dc);
185  }
186  }
187  return block;
188  }
189 
190  //----------------------------------------------------------------------
192  {
193  int dcm = this->Map()->getDCM(dc);
194  if (fUseExceptions) {
195  if (fVerbosity)
196  LOG_DEBUG("CMap") << "Exceptions enabled.";
197  if (fExceptionsMap.find(dc) != fExceptionsMap.end()) {
198  dc = fExceptionsMap[dc];
199  dcm = this->Map()->getDCM(dc);
200  }
201  }
202  return dcm;
203  }
204 
205  //----------------------------------------------------------------------
207  {
208  int feb = this->Map()->getFEB(dc);
209  if (fUseExceptions) {
210  if (fVerbosity)
211  LOG_DEBUG("CMap") << "Exceptions enabled.";
212  if (fExceptionsMap.find(dc) != fExceptionsMap.end()) {
213  dc = fExceptionsMap[dc];
214  feb = this->Map()->getFEB(dc);
215  }
216  }
217  return feb;
218  }
219 
220  //----------------------------------------------------------------------
222  {
223  int pixel = this->Map()->getPixel(dc);
224 
225  if (fUseExceptions) {
226  if (fVerbosity)
227  LOG_DEBUG("CMap") << "Exceptions enabled.";
228  if (fExceptionsMap.find(dc) != fExceptionsMap.end()) {
229  dc = fExceptionsMap[dc];
230  pixel = this->Map()->getPixel(dc);
231  }
232  }
233  return pixel;
234  }
235 
236  //----------------------------------------------------------------------
238  {
239  int view = this->Map()->getView(dc);
240 
241  if (fUseExceptions) {
242  if (fVerbosity)
243  LOG_DEBUG("CMap") << "Exceptions enabled.";
244  if (fExceptionsMap.find(dc) != fExceptionsMap.end()) {
245  dc = fExceptionsMap[dc];
246  view = this->Map()->getView(dc);
247  }
248  }
249  return view;
250  }
251 
252  //----------------------------------------------------------------------
254  {
255  int plane = this->Map()->getPlane(lc);
256  if (fUseExceptions) {
257  if (fVerbosity)
258  LOG_DEBUG("CMap") << "Exceptions enabled.";
259  daqchannelmap::dchan dc = this->Map()->encodeDChan(lc);
260  if (fExceptionsMap.find(dc) != fExceptionsMap.end()) {
261  dc = fExceptionsMap[dc];
262  plane = this->Map()->getPlane(this->Map()->encodeLChan(dc));
263  }
264  }
265  return plane;
266  }
267 
268  //----------------------------------------------------------------------
270  {
271  int cell = this->Map()->getCell(lc);
272  if (fUseExceptions) {
273  if (fVerbosity)
274  LOG_DEBUG("CMap") << "Exceptions enabled.";
275  daqchannelmap::dchan dc = this->Map()->encodeDChan(lc);
276  if (fExceptionsMap.find(dc) != fExceptionsMap.end()) {
277  dc = fExceptionsMap[dc];
278  cell = this->Map()->getCell(this->Map()->encodeLChan(dc));
279  }
280  }
281  return cell;
282  }
283 
284  //----------------------------------------------------------------------
285  unsigned short CMap::GetPlane(const rawdata::RawDigit* dig)
286  {
287  if (!dig) return 30000;
288 
289  daqchannelmap::lchan local_channel = dig->Channel();
290 
291  if (dig->IsRealData() && fUseExceptions) {
292  if (fVerbosity)
293  LOG_DEBUG("CMap") << "Exceptions enabled.";
295  if (fExceptionsMap.find(dchan) != fExceptionsMap.end()) {
296  dchan = fExceptionsMap[dchan];
297  local_channel = this->Map()->encodeLChan(dchan);
298  }
299  }
300 
301  return this->Map()->getPlane(local_channel);
302 
303  }
304 
305  //----------------------------------------------------------------------
306  unsigned short CMap::GetPlane(const rb::CellHit* dig)
307  {
308  if (!dig) return 30000;
309 
310  daqchannelmap::lchan local_channel = dig->Channel();
311 
312  if (dig->IsRealData() && fUseExceptions) {
313  if (fVerbosity)
314  LOG_DEBUG("CMap") << "Exceptions enabled.";
316  if (fExceptionsMap.find(dchan) != fExceptionsMap.end()) {
317  dchan = fExceptionsMap[dchan];
318  local_channel = this->Map()->encodeLChan(dchan);
319  }
320  }
321 
322  return this->Map()->getPlane(local_channel);
323 
324  }
325 
326  //----------------------------------------------------------------------
327  unsigned short CMap::GetCell(const rawdata::RawDigit* dig)
328  {
329  if (!dig) return 30000;
330 
331  // const
332  daqchannelmap::lchan local_channel = dig->Channel();
333 
334  if (dig->IsRealData() && fUseExceptions) {
335  if (fVerbosity)
336  LOG_DEBUG("CMap") << "Exceptions enabled.";
338  if (fExceptionsMap.find(dchan) != fExceptionsMap.end()) {
339  dchan = fExceptionsMap[dchan];
340  local_channel = this->Map()->encodeLChan(dchan);
341  }
342  }
343 
344  return this->Map()->getCell(local_channel);
345  }
346 
347  //----------------------------------------------------------------------
348  unsigned short CMap::GetCell(const rb::CellHit* dig)
349  {
350  if (!dig) return 30000;
351 
352  // const
353  daqchannelmap::lchan local_channel = dig->Channel();
354 
355  if (dig->IsRealData() && fUseExceptions) {
356  if (fVerbosity)
357  LOG_DEBUG("CMap") << "Exceptions enabled.";
359  if (fExceptionsMap.find(dchan) != fExceptionsMap.end()) {
360  dchan = fExceptionsMap[dchan];
361  local_channel = this->Map()->encodeLChan(dchan);
362  }
363  }
364 
365  return this->Map()->getCell(local_channel);
366  }
367 
368  }
369 } // end namespace cmap
370 ////////////////////////////////////////////////////////////////////////
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
daqchannelmap::lchan encodeLChan(int detId, int plane, int cell)
Definition: CMap.cxx:113
int getDetector(uint32_t anychan) const
int getDiBlock(daqchannelmap::dchan)
Definition: CMap.cxx:176
int getPixel(daqchannelmap::dchan)
Definition: CMap.cxx:221
virtual DetView_TYPE getView(dchan daqchan) const =0
Which view (X or Y) does this daq channel readout?
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
std::unordered_map< daqchannelmap::dchan, daqchannelmap::dchan > fExceptionsMap
Definition: CMap.h:85
cell_t getCell(lchan logicalchan) const
Decode the cell number from an lchan.
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
int getDetector(daqchannelmap::dchan)
Definition: CMap.cxx:161
bool fUseExceptions
Definition: CMap.h:84
block
print "ROW IS " print row
Definition: elec2geo.py:31
uint32_t DaqChannel() const
Definition: RawDigit.h:85
int getCell(daqchannelmap::lchan)
Definition: CMap.cxx:269
unsigned short GetPlane(const rawdata::RawDigit *dig)
Definition: CMap.cxx:285
void AddException(int idet, geo::OfflineChan chan1, geo::OfflineChan chan2)
Definition: CMap.cxx:102
unsigned short Plane() const
Definition: OfflineChan.h:31
int getDCM(daqchannelmap::dchan)
Definition: CMap.cxx:191
int computeBlock(daqchannelmap::lchan)
Definition: CMap.cxx:145
pixel_t getPixel(dchan daqchan) const
Decode the pixel id from a dchan.
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
int getFEB(daqchannelmap::dchan)
Definition: CMap.cxx:206
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
unsigned short Cell() const
Definition: OfflineChan.h:32
int getPlane(daqchannelmap::lchan)
Definition: CMap.cxx:253
def lc(target="")
Definition: g4zmq.py:63
A (plane, cell) pair.
Definition: OfflineChan.h:17
uint32_t Channel() const
Definition: RawDigit.h:84
plane_t getPlane(lchan logicalchan) const
Decode the plane number from an lchan.
unsigned short GetCell(const rawdata::RawDigit *dig)
Definition: CMap.cxx:327
daqchannelmap::dchan encodeDChan(daqchannelmap::lchan)
Definition: CMap.cxx:130
cmap::CMap class source code
Definition: CMap.cxx:17
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
int getView(daqchannelmap::dchan)
Definition: CMap.cxx:237
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
#define LOG_INFO(stream)
Definition: Messenger.h:144
virtual block_t computeBlock(lchan logicalchan) const =0
Which block is this lchan in?
uint32_t dchan
< DAQ Channel Map Package
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
#define LOG_ERROR(stream)
Definition: Messenger.h:129
const daqchannelmap::DAQChannelMap * fStdMap
Definition: CMap.h:86
feb_t getFEB(dchan daqchan) const
Decode the feb id from a dchan.
bool IsRealData() const
Definition: RawDigit.h:107