CMS 3D CMS Logo

CamacTBDataFormatter.cc
Go to the documentation of this file.
1 /*
2  *
3  * \author G. Franzoni
4  *
5  */
6 
7 #include "CamacTBDataFormatter.h"
8 
9 // pro-memo:
10 // "ff" = 1 Byte
11 // 64 bits = 8 Bytes = 16 hex carachters
12 // for now: event is ( 114 words x 32 bits ) = 448 Bytes
13 // size of unsigned long = 4 Bytes. Thus, 1 (32 bit) word = 1 (unsigned long)
14 
16  int nfiber;
17  int ndet;
18 };
19 
20 // nHodoscopes = 2; nFibres = 64
21 const static struct hodo_fibre_index hodoFiberMap[2][64] = {{// Hodo 0
22  // unit 1A
23  {23, 44},
24  {29, 47},
25  {31, 48},
26  {21, 43},
27  {5, 35},
28  {15, 40},
29  {7, 36},
30  {13, 39},
31  {1, 33},
32  {11, 38},
33  {3, 34},
34  {9, 37},
35  {6, 3},
36  {16, 8},
37  {8, 4},
38  {14, 7},
39  // unit 1C
40  {17, 41},
41  {19, 42},
42  {27, 46},
43  {25, 45},
44  {32, 16},
45  {22, 11},
46  {24, 12},
47  {30, 15},
48  {12, 6},
49  {2, 1},
50  {4, 2},
51  {10, 5},
52  {28, 14},
53  {18, 9},
54  {20, 10},
55  {26, 13},
56  // unit 2A
57  {54, 27},
58  {56, 28},
59  {64, 32},
60  {62, 31},
61  {49, 57},
62  {59, 62},
63  {51, 58},
64  {57, 61},
65  {53, 59},
66  {63, 64},
67  {55, 60},
68  {61, 63},
69  {45, 55},
70  {39, 52},
71  {37, 51},
72  {47, 56},
73  // unit 2C
74  {34, 17},
75  {42, 21},
76  {44, 22},
77  {36, 18},
78  {50, 25},
79  {60, 30},
80  {58, 29},
81  {52, 26},
82  {38, 19},
83  {40, 20},
84  {48, 24},
85  {46, 23},
86  {41, 53},
87  {35, 50},
88  {33, 49},
89  {43, 54}},
90  {// Hodo 1
91  // unit 1A
92  {31, 48},
93  {29, 47},
94  {23, 44},
95  {21, 43},
96  {5, 35},
97  {7, 36},
98  {15, 40},
99  {13, 39},
100  {1, 33},
101  {3, 34},
102  {11, 38},
103  {9, 37},
104  {6, 3},
105  {8, 4},
106  {16, 8},
107  {14, 7},
108  // unit 1C
109  {17, 41},
110  {27, 46},
111  {19, 42},
112  {25, 45},
113  {24, 12},
114  {22, 11},
115  {32, 16},
116  {30, 15},
117  {4, 2},
118  {2, 1},
119  {12, 6},
120  {10, 5},
121  {20, 10},
122  {18, 9},
123  {28, 14},
124  {26, 13},
125  // unit 2A
126  {54, 27},
127  {64, 32},
128  {56, 28},
129  {62, 31},
130  {49, 57},
131  {51, 58},
132  {59, 62},
133  {57, 61},
134  {53, 59},
135  {55, 60},
136  {63, 64},
137  {61, 63},
138  {45, 55},
139  {47, 56},
140  {37, 51},
141  {39, 52},
142  // unit 2C
143  {34, 17},
144  {42, 21},
145  {36, 18},
146  {44, 22},
147  {50, 25},
148  {52, 26},
149  {58, 29},
150  {60, 30},
151  {38, 19},
152  {48, 24},
153  {40, 20},
154  {46, 23},
155  {41, 53},
156  {43, 54},
157  {33, 49},
158  {35, 50}}};
159 
161 
163  EcalTBEventHeader& tbEventHeader,
164  EcalTBHodoscopeRawInfo& hodoRaw,
165  EcalTBTDCRawInfo& tdcRawInfo) {
166  const unsigned long* buffer = (reinterpret_cast<const unsigned long*>(fedData.data()));
167  int fedLenght = fedData.size(); // in Bytes
168 
169  // check ultimate fed size and strip off fed-header and -trailer
170  if (fedLenght != (nWordsPerEvent * 4)) {
171  edm::LogError("CamacTBDataFormatter") << "CamacTBData has size " << fedLenght << " Bytes as opposed to expected "
172  << (nWordsPerEvent * 4) << ". Returning.";
173  return;
174  }
175 
176  unsigned long a = 1; // used to extract an 8 Bytes word from fed
177  unsigned long b = 1; // used to manipulate the 8 Bytes word and get what needed
178 
179  // initializing array of statuses
180  for (int wordNumber = 0; wordNumber < nWordsPerEvent; wordNumber++) {
181  statusWords[wordNumber] = true;
182  }
183 
184  // for (int wordNumber=0; wordNumber<nWordsPerEvent; wordNumber++)
185  // { checkStatus( buffer[wordNumber], wordNumber);}
186 
187  // for (int wordNumber=0; wordNumber<nWordsPerEvent; wordNumber++)
188  // {
189  // if (! statusWords[wordNumber])
190  // {
191  // edm::LogError("CamacTBDataFormatter") << "bad status in some of the event words; returning;";
192  // }
193  // }
194 
195  int wordCounter = 0;
196  wordCounter += 4;
197 
198  // read first word
199  a = buffer[wordCounter];
200  wordCounter++;
201  LogDebug("CamacTBDataFormatter") << "\n\nword:\t" << a;
202 
203  b = (a & 0xff000000);
204  b = b >> 24;
205  LogDebug("CamacTBDataFormatter") << "format ver:\t" << b;
206 
207  b = (a & 0xff0000);
208  b = b >> 16;
209  LogDebug("CamacTBDataFormatter") << "major:\t" << b;
210 
211  b = (a & 0xff00);
212  b = b >> 8;
213  LogDebug("CamacTBDataFormatter") << "minor:\t" << b;
214 
215  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
216  LogDebug("CamacTBDataFormatter") << "time stamp secs: " << a;
217 
218  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
219  LogDebug("CamacTBDataFormatter") << "time stamp musecs: " << a;
220 
221  a = buffer[wordCounter];
222  wordCounter++;
223  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
224  b = (a & 0xffffff);
225  LogDebug("CamacTBDataFormatter") << "LV1A: " << b;
226  int lv1 = b;
227 
228  a = buffer[wordCounter];
229  wordCounter++;
230  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
231  b = (a & 0xffff0000);
232  b = b >> 16;
233  LogDebug("CamacTBDataFormatter") << "run number: " << b;
234  int run = b;
235  b = (a & 0xffff);
236  LogDebug("CamacTBDataFormatter") << "spill number: " << b;
237  int spill = b;
238 
239  a = buffer[wordCounter];
240  wordCounter++;
241  b = (a & 0xffff);
242  LogDebug("CamacTBDataFormatter") << "event number in spill: " << b;
243 
244  a = buffer[wordCounter];
245  wordCounter++;
246  b = (a & 0xffffff);
247  LogDebug("CamacTBDataFormatter") << "internal event number: " << b;
248 
249  a = buffer[wordCounter];
250  wordCounter++;
251  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
252  b = (a & 0xffff0000);
253  b = b >> 16;
254  LogDebug("CamacTBDataFormatter") << "vme errors: " << b;
255  b = (a & 0xffff);
256  LogDebug("CamacTBDataFormatter") << "camac errors: " << b;
257 
258  a = buffer[wordCounter];
259  wordCounter++;
260  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
261  b = a;
262  LogDebug("CamacTBDataFormatter") << "extended (32 bits) run number: " << b;
263 
264  // skip 1 reserved words
265  wordCounter += 1;
266 
267  /**********************************
268  // acessing the hodoscope block
269  **********************************/
270 
271  // getting 16 words buffer and checking words statuses
272  unsigned long bufferHodo[16];
273  bool hodoAreGood = true;
274  for (int hodo = 0; hodo < 16; hodo++) {
275  hodoAreGood = hodoAreGood && checkStatus(buffer[wordCounter], wordCounter);
276 
277  a = buffer[wordCounter];
278  bufferHodo[hodo] = buffer[wordCounter];
279  wordCounter++;
280  b = (a & 0xffffff);
281  LogDebug("CamacTBDataFormatter") << "hodo: " << hodo << "\t: " << b;
282  }
283 
284  hodoRaw.setPlanes(0);
285  // unpacking the hodo data
286  if (hodoAreGood) {
287  for (int iplane = 0; iplane < nHodoPlanes; iplane++) {
288  int detType = 1; // new mapping for electronics channels
289 
290  for (int fiber = 0; fiber < nHodoFibers; fiber++) {
291  hodoHits[iplane][fiber] = 0;
292  }
293 
294  int ch = 0;
295 
296  // loop on [4-24bits words] = 1 plane
297  for (int j = 0; j < hodoRawLen; j++) {
298  int word = bufferHodo[j + iplane * hodoRawLen] & 0xffff;
299  for (int i = 1; i < 0x10000; i <<= 1) {
300  if (word & i) {
301  // map electronics channel to No of fibre
302  hodoHits[iplane][hodoFiberMap[detType][ch].nfiber - 1]++;
303  }
304  ch++;
305  }
306  }
307  }
308 
309  // building the hodo infos (returning decoded hodoscope hits information)
310  hodoRaw.setPlanes((unsigned int)nHodoPlanes);
311  for (int ipl = 0; ipl < nHodoPlanes; ipl++) {
312  EcalTBHodoscopePlaneRawHits theHodoPlane;
313  theHodoPlane.setChannels((unsigned int)nHodoFibers);
314  for (int fib = 0; fib < nHodoFibers; fib++) {
315  theHodoPlane.setHit((unsigned int)fib, (bool)hodoHits[ipl][fib]);
316  }
317  hodoRaw.setPlane((unsigned int)ipl, theHodoPlane);
318  }
319  } else {
320  edm::LogWarning("CamacTBDataFormatter")
321  << "hodoscope block has hardware problems or is partly unused at LV1: " << lv1 << " spill: " << spill
322  << "run: " << run << ". Skipping digi.";
323  }
324 
325  /**********************************
326  // acessing the scalers block
327  **********************************/
328 
329  // getting 72 words buffer and checking words statuses
330 
331  scalers_.clear();
332  scalers_.reserve(36);
333 
334  bool scalersAreGood = true;
335  for (int scaler = 0; scaler < 72; scaler++) {
336  scalersAreGood = scalersAreGood && checkStatus(buffer[wordCounter], wordCounter);
337 
338  a = buffer[wordCounter];
339  wordCounter++;
340  b = (a & 0xffffff);
341  LogDebug("CamacTBDataFormatter") << "scaler: " << scaler << "\t: " << b;
342 
343  // filling vector container with scalers words
344  if ((scaler % 2) == 0)
345  scalers_.push_back(b);
346  }
347  if (scalersAreGood) {
348  tbEventHeader.setScalers(scalers_);
349  } else {
350  edm::LogWarning("CamacTBDataFormatter")
351  << "scalers block has hardware problems or is partly unused at LV1: " << lv1 << " spill: " << spill
352  << "run: " << run;
353  }
354 
355  /**********************************
356  // acessing the fingers block
357  **********************************/
358 
359  LogDebug("CamacTBDataFormatter") << "\n";
360  bool fingersAreGood = true;
361  for (int finger = 0; finger < 2; finger++) {
362  fingersAreGood = fingersAreGood && checkStatus(buffer[wordCounter], wordCounter);
363 
364  a = buffer[wordCounter];
365  wordCounter++;
366  b = (a & 0xffffff);
367  LogDebug("CamacTBDataFormatter") << "finger: " << finger << "\t: " << b;
368  }
369  if (fingersAreGood) {
370  ;
371  } else {
372  edm::LogWarning("CamacTBDataFormatter")
373  << "fingers block has hardware problems or is partly unused at LV1: " << lv1 << " spill: " << spill
374  << "run: " << run;
375  }
376 
377  /**********************************
378  // acessing the multi stop TDC block
379  **********************************/
380 
381  a = buffer[wordCounter];
382  wordCounter++;
383  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
384  b = (a & 0x000000ff);
385  LogDebug("CamacTBDataFormatter") << "number of words used in multi stop TDC words: " << b;
386 
387  int numberTDCwords = 16;
388  bool multiStopTDCIsGood = true;
389  for (int tdc = 0; tdc < numberTDCwords; tdc++) {
390  multiStopTDCIsGood = multiStopTDCIsGood && checkStatus(buffer[wordCounter], wordCounter);
391 
392  a = buffer[wordCounter];
393  wordCounter++;
394  b = a;
395  LogDebug("CamacTBDataFormatter") << "tdc: " << tdc << "\t: " << b;
396  }
397  if (multiStopTDCIsGood) {
398  ;
399  } else {
400  edm::LogWarning("CamacTBDataFormatter")
401  << "multi stop TDC block has hardware problems or is partly unused at LV1: " << lv1 << " spill: " << spill
402  << "run: " << run;
403  }
404 
405  // skip the unused words in multi stop TDC block
406  wordCounter += (16 - numberTDCwords);
407 
408  /**********************************
409  // acessing table in position bit
410  **********************************/
411  a = buffer[wordCounter];
412  wordCounter++;
413  b = (a & 0x00000001); //1= table is in position; 0=table is moving
414  bool tableIsMoving;
415  if (b) {
416  LogDebug("CamacTBDataFormatter") << " table is in position.";
417  tableIsMoving = false;
418  } else {
419  LogDebug("CamacTBDataFormatter") << " table is moving.";
420  tableIsMoving = true;
421  }
422  tbEventHeader.setTableIsMoving(tableIsMoving);
423 
424  wordCounter += 3;
425 
426  /**********************************
427  // acessing ADC block
428  **********************************/
429  // skip 10 reserved words
430  wordCounter += 10;
431  bool ADCIsGood = true;
432  a = buffer[wordCounter];
433  wordCounter++; // NOT read out
434  b = (a & 0x00ffffff);
435  LogDebug("CamacTBDataFormatter") << "ADC word1: " << a << "\t ADC2: " << b << " word is: " << (wordCounter - 1);
436  // ADCIsGood = true;
437  // ADCIsGood = ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
438  ADCIsGood = checkStatus(buffer[wordCounter], wordCounter);
439  a = buffer[wordCounter];
440  wordCounter++; // read out
441  b = (a & 0xffffff);
442  LogDebug("CamacTBDataFormatter") << "ADC word2, adc channel 11, ampli S6: " << a << "\t ADC2: " << b;
443  if (ADCIsGood)
444  tbEventHeader.setS6ADC(b);
445  else
446  tbEventHeader.setS6ADC(-1);
447 
448  /**********************************
449  // acessing TDC block
450  **********************************/
451  // skip 6 reserved words
452  wordCounter += 6;
453  ADCIsGood&& checkStatus(buffer[wordCounter], wordCounter);
454  a = buffer[wordCounter];
455  wordCounter++;
456  b = (a & 0xfffff);
457  LogDebug("CamacTBDataFormatter") << "TDC word1: " << a << "\t TDC2: " << b;
458  ADCIsGood&& checkStatus(buffer[wordCounter], wordCounter);
459  a = buffer[wordCounter];
460  wordCounter++;
461  b = (a & 0xfffff);
462  LogDebug("CamacTBDataFormatter") << "TDC word2: (ext_val_trig - LHC_clock) " << a
463  << "\t (ext_val_trig - LHC_clock): " << b;
464 
465  tdcRawInfo.setSize(1);
466  int sampleNumber = 1;
467  EcalTBTDCSample theTdc(sampleNumber, b);
468  tdcRawInfo.setSample(0, theTdc);
469 
470  a = buffer[wordCounter];
471  wordCounter++;
472  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
473  b = a;
474  LogDebug("CamacTBDataFormatter") << "last word of event: " << b;
475 }
476 
477 // given a data word with 8 msb as status, checks status
478 
479 bool CamacTBDataFormatter::checkStatus(unsigned long word, int wordNumber) {
480  if (wordNumber < 1 || wordNumber > nWordsPerEvent) {
481  edm::LogWarning("CamacTBDataFormatter::checkStatus")
482  << "checking word number: " << wordNumber << " which is out of allowed range (" << nWordsPerEvent << ")";
483  return false;
484  }
485 
486  bool isOk = true;
487 
488  if (word & 0x80000000) // daq item not used
489  {
490  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "daq item not used at word: " << wordNumber;
491  statusWords[wordNumber - 1] = false;
492  isOk = false;
493  }
494 
495  if (word & 0x40000000) // vme error on data
496  {
497  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "vme error on word: " << wordNumber;
498  statusWords[wordNumber - 1] = false;
499  isOk = false;
500  }
501 
502  if (word & 0x20000000) // vme error on status
503  {
504  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "vme status error at word: " << wordNumber;
505  statusWords[wordNumber - 1] = false;
506  isOk = false;
507  }
508 
509  if (word & 0x10000000) // camac error (no X)
510  {
511  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "camac error (no X) at word: " << wordNumber;
512  statusWords[wordNumber - 1] = false;
513  isOk = false;
514  }
515 
516  if (word & 0x08000000) // camac error (no Q)
517  {
518  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "camac error (no Q) at word: " << wordNumber;
519  statusWords[wordNumber - 1] = false;
520  isOk = false;
521  }
522 
523  // camac error check not done on purpose from Aug 8, to speed up Camac communication. This bit status is now ignored.
524  // if (word & 0x04000000) // no camac check error
525  // {
526  //edm::LogWarning("CamacTBDataFormatter::checkStatus") << "no camac check error at word: "<< wordNumber;
527  //statusWords[wordNumber -1] = false;
528  //isOk = false;
529  // }
530 
531  return isOk;
532 }
void setHit(unsigned int i, bool status)
std::vector< int > scalers_
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
void setS6ADC(const int &S6ADC)
Log< level::Error, false > LogError
void setPlane(unsigned int i, const EcalTBHodoscopePlaneRawHits &planeHit)
uint64_t word
void setChannels(unsigned int size)
Set methods.
void setScalers(const std::vector< int > &scalers)
bool checkStatus(unsigned long word, int wordNumber)
static const int nHodoFibers
int hodoHits[nHodoPlanes][nHodoFibers]
static const struct hodo_fibre_index hodoFiberMap[2][64]
double b
Definition: hdecay.h:118
static const int nHodoPlanes
void setSample(unsigned int i, const EcalTBTDCSample &sam)
double a
Definition: hdecay.h:119
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
void setTableIsMoving(const bool &tableIsMoving)
Log< level::Warning, false > LogWarning
void setSize(unsigned int size)
Set methods.
static const int hodoRawLen
void setPlanes(unsigned int size)
Set methods.
#define LogDebug(id)
void interpretRawData(const FEDRawData &data, EcalTBEventHeader &tbEventHeader, EcalTBHodoscopeRawInfo &hodoRaw, EcalTBTDCRawInfo &tdcRawInfo)