CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
CamacTBDataFormatter Class Reference

#include <CamacTBDataFormatter.h>

Public Member Functions

 CamacTBDataFormatter ()
 
void interpretRawData (const FEDRawData &data, EcalTBEventHeader &tbEventHeader, EcalTBHodoscopeRawInfo &hodoRaw, EcalTBTDCRawInfo &tdcRawInfo)
 
virtual ~CamacTBDataFormatter ()
 

Private Member Functions

bool checkStatus (unsigned long word, int wordNumber)
 

Private Attributes

int hodoAll [nHodoPlanes *nHodoFibers]
 
int hodoHits [nHodoPlanes][nHodoFibers]
 
int nHodoHits [nHodoPlanes]
 
int nWordsPerEvent
 
std::vector< int > scalers_
 
bool statusWords [148+4]
 

Static Private Attributes

static const int hodoRawLen = 4
 
static const int nHodoFibers = 64
 
static const int nHodoPlanes = 4
 
static const int nHodoscopes = 2
 

Detailed Description

Id:
CamacTBDataFormatter.h,v 1.7 2010/10/12 13:11:35 eulisse Exp
Author
G. Franzoni

Definition at line 28 of file CamacTBDataFormatter.h.

Constructor & Destructor Documentation

CamacTBDataFormatter::CamacTBDataFormatter ( )

Definition at line 73 of file CamacTBDataFormatter.cc.

References nWordsPerEvent.

73  {
74  nWordsPerEvent = 148;
75 }
virtual CamacTBDataFormatter::~CamacTBDataFormatter ( )
inlinevirtual

Definition at line 33 of file CamacTBDataFormatter.h.

References LogDebug.

33 {LogDebug("EcalTBRawToDigi") << "@SUB=CamacTBDataFormatter" << "\n"; };
#define LogDebug(id)

Member Function Documentation

bool CamacTBDataFormatter::checkStatus ( unsigned long  word,
int  wordNumber 
)
private

Definition at line 437 of file CamacTBDataFormatter.cc.

References nWordsPerEvent, and statusWords.

Referenced by interpretRawData().

437  {
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 }
void CamacTBDataFormatter::interpretRawData ( const FEDRawData data,
EcalTBEventHeader tbEventHeader,
EcalTBHodoscopeRawInfo hodoRaw,
EcalTBTDCRawInfo tdcRawInfo 
)

Definition at line 79 of file CamacTBDataFormatter.cc.

References a, b, checkStatus(), FEDRawData::data(), hodoHits, hodoRawLen, i, j, LogDebug, hodo_fibre_index::nfiber, nHodoFibers, nHodoPlanes, nWordsPerEvent, DTTTrigCorrFirst::run, scalers_, EcalTBHodoscopePlaneRawHits::setChannels(), EcalTBHodoscopePlaneRawHits::setHit(), EcalTBHodoscopeRawInfo::setPlane(), EcalTBHodoscopeRawInfo::setPlanes(), EcalTBEventHeader::setS6ADC(), EcalTBTDCRawInfo::setSample(), EcalTBEventHeader::setScalers(), EcalTBTDCRawInfo::setSize(), EcalTBEventHeader::setTableIsMoving(), FEDRawData::size(), and statusWords.

Referenced by EcalDCCTBUnpackingModule::produce(), and EcalDCCTB07UnpackingModule::produce().

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 }
#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)
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
void setTableIsMoving(const bool &tableIsMoving)
void setSize(unsigned int size)
Set methods.
static const int hodoRawLen
void setPlanes(unsigned int size)
Set methods.

Member Data Documentation

int CamacTBDataFormatter::hodoAll[nHodoPlanes *nHodoFibers]
private

Definition at line 60 of file CamacTBDataFormatter.h.

int CamacTBDataFormatter::hodoHits[nHodoPlanes][nHodoFibers]
private

Definition at line 59 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

const int CamacTBDataFormatter::hodoRawLen = 4
staticprivate

Definition at line 56 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

const int CamacTBDataFormatter::nHodoFibers = 64
staticprivate

Definition at line 53 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

int CamacTBDataFormatter::nHodoHits[nHodoPlanes]
private

Definition at line 58 of file CamacTBDataFormatter.h.

const int CamacTBDataFormatter::nHodoPlanes = 4
staticprivate

Definition at line 55 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

const int CamacTBDataFormatter::nHodoscopes = 2
staticprivate

Definition at line 54 of file CamacTBDataFormatter.h.

int CamacTBDataFormatter::nWordsPerEvent
private

Definition at line 51 of file CamacTBDataFormatter.h.

Referenced by CamacTBDataFormatter(), checkStatus(), and interpretRawData().

std::vector<int> CamacTBDataFormatter::scalers_
private

Definition at line 63 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

bool CamacTBDataFormatter::statusWords[148+4]
private

Definition at line 61 of file CamacTBDataFormatter.h.

Referenced by checkStatus(), and interpretRawData().