CMS 3D CMS Logo

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