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 
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<const unsigned long*>( 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  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
142  LogDebug("CamacTBDataFormatter") << "time stamp secs: "<<a;
143 
144  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
145  LogDebug("CamacTBDataFormatter") << "time stamp musecs: " <<a;
146 
147 
148  a = buffer[wordCounter];wordCounter++;
149  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
150  b = (a& 0xffffff);
151  LogDebug("CamacTBDataFormatter") << "LV1A: "<< b;
152  int lv1 = b;
153 
154  a = buffer[wordCounter];wordCounter++;
155  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
156  b = (a& 0xffff0000);
157  b = b >> 16;
158  LogDebug("CamacTBDataFormatter") << "run number: "<< b;
159  int run = b;
160  b = (a& 0xffff);
161  LogDebug("CamacTBDataFormatter") << "spill number: "<< b;
162  int spill = b;
163 
164  a = buffer[wordCounter];wordCounter++;
165  b = (a& 0xffff);
166  LogDebug("CamacTBDataFormatter") << "event number in spill: "<< b;
167 
168  a = buffer[wordCounter];wordCounter++;
169  b = (a& 0xffffff);
170  LogDebug("CamacTBDataFormatter") << "internal event number: "<< b;
171 
172  a = buffer[wordCounter];wordCounter++;
173  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
174  b = (a& 0xffff0000);
175  b = b >> 16;
176  LogDebug("CamacTBDataFormatter") << "vme errors: "<< b;
177  b = (a& 0xffff);
178  LogDebug("CamacTBDataFormatter") << "camac errors: "<< b;
179 
180  a = buffer[wordCounter];wordCounter++;
181  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
182  b = a;
183  LogDebug("CamacTBDataFormatter") << "extended (32 bits) run number: "<< b;
184 
185  // skip 1 reserved words
186  wordCounter +=1;
187 
188  /**********************************
189  // acessing the hodoscope block
190  **********************************/
191 
192  // getting 16 words buffer and checking words statuses
193  unsigned long bufferHodo[16];
194  bool hodoAreGood = true;
195  for (int hodo=0; hodo<16; hodo++)
196  {
197  hodoAreGood = hodoAreGood && checkStatus(buffer[wordCounter], wordCounter);
198 
199  a = buffer[wordCounter];
200  bufferHodo[hodo] = buffer[wordCounter];
201  wordCounter++;
202  b = (a& 0xffffff);
203  LogDebug("CamacTBDataFormatter") << "hodo: " << hodo << "\t: " << b;
204  }
205 
206  hodoRaw.setPlanes(0);
207  // unpacking the hodo data
208  if (hodoAreGood){
209  for (int iplane=0; iplane<nHodoPlanes; iplane++)
210  {
211  int detType = 1; // new mapping for electronics channels
212 
213  for (int fiber=0; fiber<nHodoFibers; fiber++) { hodoHits[iplane][fiber] = 0; }
214 
215  int ch=0;
216 
217  // loop on [4-24bits words] = 1 plane
218  for(int j=0; j<hodoRawLen; j++)
219  {
220  int word= bufferHodo[ j+iplane*hodoRawLen ] &0xffff;
221  for(int i=1; i<0x10000; i<<=1)
222  {
223  if ( word & i )
224  {
225  // map electronics channel to No of fibre
226  hodoHits[iplane][ hodoFiberMap[detType][ch].nfiber - 1]++;
227  }
228  ch ++;
229  }
230  }
231  }
232 
233 
234  // building the hodo infos (returning decoded hodoscope hits information)
235  hodoRaw.setPlanes((unsigned int)nHodoPlanes);
236  for (int ipl = 0; ipl < nHodoPlanes; ipl++)
237  {
238  EcalTBHodoscopePlaneRawHits theHodoPlane;
239  theHodoPlane.setChannels((unsigned int)nHodoFibers);
240  for (int fib = 0; fib < nHodoFibers; fib++){ theHodoPlane.setHit((unsigned int)fib, (bool)hodoHits[ipl][fib]); }
241  hodoRaw.setPlane((unsigned int)ipl, theHodoPlane);
242  }
243  }
244  else
245  {
246  edm::LogWarning("CamacTBDataFormatter") << "hodoscope block has hardware problems or is partly unused at LV1: "
247  << lv1 << " spill: " << spill
248  << "run: " << run
249  << ". Skipping digi.";
250  }
251 
252 
253 
254 
255 
256  /**********************************
257  // acessing the scalers block
258  **********************************/
259 
260  // getting 72 words buffer and checking words statuses
261 
262  scalers_.clear();
263  scalers_.reserve(36);
264 
265  bool scalersAreGood = true;
266  for (int scaler=0; scaler<72; scaler++)
267  {
268  scalersAreGood = scalersAreGood && checkStatus(buffer[wordCounter], wordCounter);
269 
270  a = buffer[wordCounter]; wordCounter++;
271  b = (a& 0xffffff);
272  LogDebug("CamacTBDataFormatter") << "scaler: " << scaler << "\t: " << b;
273 
274  // filling vector container with scalers words
275  if ( (scaler%2)==0 ) scalers_.push_back(b);
276  }
277  if (scalersAreGood){
278  tbEventHeader.setScalers (scalers_);
279  }
280  else
281  {
282  edm::LogWarning("CamacTBDataFormatter") << "scalers block has hardware problems or is partly unused at LV1: "
283  << lv1 << " spill: " << spill
284  << "run: " << run;
285  }
286 
287 
288 
289 
290 
291  /**********************************
292  // acessing the fingers block
293  **********************************/
294 
295  LogDebug("CamacTBDataFormatter") <<"\n";
296  bool fingersAreGood = true;
297  for (int finger=0; finger<2; finger++)
298  {
299  fingersAreGood = fingersAreGood && checkStatus(buffer[wordCounter], wordCounter);
300 
301  a = buffer[wordCounter]; wordCounter++;
302  b = (a& 0xffffff);
303  LogDebug("CamacTBDataFormatter") << "finger: " << finger << "\t: " << b;
304  }
305  if (fingersAreGood){
306  ; }
307  else
308  {
309  edm::LogWarning("CamacTBDataFormatter") << "fingers block has hardware problems or is partly unused at LV1: "
310  << lv1 << " spill: " << spill
311  << "run: " << run;
312  }
313 
314 
315 
316 
317  /**********************************
318  // acessing the multi stop TDC block
319  **********************************/
320 
321  a = buffer[wordCounter]; wordCounter++;
322  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
323  b = (a& 0x000000ff);
324  LogDebug("CamacTBDataFormatter") << "number of words used in multi stop TDC words: "<< b;
325 
326  int numberTDCwords = 16;
327  bool multiStopTDCIsGood = true;
328  for (int tdc=0; tdc< numberTDCwords ; tdc++)
329  {
330  multiStopTDCIsGood = multiStopTDCIsGood && checkStatus(buffer[wordCounter], wordCounter);
331 
332  a = buffer[wordCounter]; wordCounter++;
333  b =a;
334  LogDebug("CamacTBDataFormatter") << "tdc: " << tdc << "\t: " << b;
335  }
336  if ( multiStopTDCIsGood ){
337  ; }
338  else
339  {
340  edm::LogWarning("CamacTBDataFormatter") << "multi stop TDC block has hardware problems or is partly unused at LV1: "
341  << lv1 << " spill: " << spill
342  << "run: " << run;
343  }
344 
345  // skip the unused words in multi stop TDC block
346  wordCounter += (16 - numberTDCwords);
347 
348 
349 
350 
351  /**********************************
352  // acessing table in position bit
353  **********************************/
354  a = buffer[wordCounter]; wordCounter++;
355  b = (a & 0x00000001); //1= table is in position; 0=table is moving
356  bool tableIsMoving;
357  if ( b ){
358  LogDebug("CamacTBDataFormatter") << " table is in position.";
359  tableIsMoving = false;
360  }
361  else
362  {
363  LogDebug("CamacTBDataFormatter") << " table is moving.";
364  tableIsMoving = true;
365  }
366  tbEventHeader.setTableIsMoving( tableIsMoving );
367 
368 
369  wordCounter += 3;
370 
371 
372 
373  /**********************************
374  // acessing ADC block
375  **********************************/
376  // skip 10 reserved words
377  wordCounter += 10;
378  bool ADCIsGood = true;
379  a = buffer[wordCounter]; wordCounter++; // NOT read out
380  b = (a&0x00ffffff);
381  LogDebug("CamacTBDataFormatter") << "ADC word1: " << a << "\t ADC2: " << b << " word is: " << (wordCounter-1);
382 // ADCIsGood = true;
383 // ADCIsGood = ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
384  ADCIsGood = checkStatus(buffer[wordCounter], wordCounter);
385  a = buffer[wordCounter]; wordCounter++; // read out
386  b = (a&0xffffff);
387  LogDebug("CamacTBDataFormatter") << "ADC word2, adc channel 11, ampli S6: " << a << "\t ADC2: " << b;
388  if (ADCIsGood) tbEventHeader.setS6ADC ( b ) ;
389  else tbEventHeader.setS6ADC ( -1 ) ;
390 
391 
392  /**********************************
393  // acessing TDC block
394  **********************************/
395  // skip 6 reserved words
396  wordCounter += 6;
397  ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
398  a = buffer[wordCounter]; wordCounter++;
399  b = (a & 0xfffff);
400  LogDebug("CamacTBDataFormatter") << "TDC word1: " << a << "\t TDC2: " << b;
401  ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
402  a = buffer[wordCounter]; wordCounter++;
403  b = (a & 0xfffff);
404  LogDebug("CamacTBDataFormatter") << "TDC word2: (ext_val_trig - LHC_clock) "
405  << a << "\t (ext_val_trig - LHC_clock): "
406  << b;
407 
408  tdcRawInfo.setSize(1);
409  int sampleNumber =1;
410  EcalTBTDCSample theTdc(sampleNumber, b);
411  tdcRawInfo.setSample(0, theTdc);
412 
413 
414  a = buffer[wordCounter]; wordCounter++;
415  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
416  b = a;
417  LogDebug("CamacTBDataFormatter") << "last word of event: "<< b;
418 
419 
420 }
421 
422 
423 
424 
425 
426 
427 
428 
429 // given a data word with 8 msb as status, checks status
430 
431 bool CamacTBDataFormatter::checkStatus(unsigned long word, int wordNumber){
432 
433 
434  if ( wordNumber < 1 || wordNumber > nWordsPerEvent)
435  {
436  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "checking word number: "
437  << wordNumber << " which is out of allowed range ("
438  << nWordsPerEvent << ")";
439  return false;
440  }
441 
442  bool isOk = true;
443 
444  if (word & 0x80000000) // daq item not used
445  {
446  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "daq item not used at word: "<< wordNumber;
447  statusWords[wordNumber -1] = false;
448  isOk = false;
449  }
450 
451  if (word & 0x40000000) // vme error on data
452  {
453  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "vme error on word: "<< wordNumber;
454  statusWords[wordNumber -1] = false;
455  isOk = false;
456  }
457 
458  if (word & 0x20000000) // vme error on status
459  {
460  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "vme status error at word: "<< wordNumber;
461  statusWords[wordNumber -1] = false;
462  isOk = false;
463  }
464 
465  if (word & 0x10000000) // camac error (no X)
466  {
467  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "camac error (no X) at word: "<< wordNumber;
468  statusWords[wordNumber -1] = false;
469  isOk = false;
470  }
471 
472  if (word & 0x08000000) // camac error (no Q)
473  {
474  edm::LogWarning("CamacTBDataFormatter::checkStatus") << "camac error (no Q) at word: "<< wordNumber;
475  statusWords[wordNumber -1] = false;
476  isOk = false;
477  }
478 
479  // camac error check not done on purpose from Aug 8, to speed up Camac communication. This bit status is now ignored.
480  // if (word & 0x04000000) // no camac check error
481  // {
482  //edm::LogWarning("CamacTBDataFormatter::checkStatus") << "no camac check error at word: "<< wordNumber;
483  //statusWords[wordNumber -1] = false;
484  //isOk = false;
485  // }
486 
487  return isOk;
488 
489 }
#define LogDebug(id)
void setHit(unsigned int i, bool status)
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)
static const struct hodo_fibre_index hodoFiberMap[2][64]
double b
Definition: hdecay.h:120
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
def checkStatus(project, threshold=95.0)
Definition: crabWrap.py:205
void setTableIsMoving(const bool &tableIsMoving)
void setSize(unsigned int size)
Set methods.
void setPlanes(unsigned int size)
Set methods.
void interpretRawData(const FEDRawData &data, EcalTBEventHeader &tbEventHeader, EcalTBHodoscopeRawInfo &hodoRaw, EcalTBTDCRawInfo &tdcRawInfo)