CMS 3D CMS Logo

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

Author
G. Franzoni

Definition at line 23 of file CamacTBDataFormatter.h.

Constructor & Destructor Documentation

◆ CamacTBDataFormatter()

CamacTBDataFormatter::CamacTBDataFormatter ( )

Definition at line 160 of file CamacTBDataFormatter.cc.

References nWordsPerEvent.

◆ ~CamacTBDataFormatter()

virtual CamacTBDataFormatter::~CamacTBDataFormatter ( )
inlinevirtual

Definition at line 26 of file CamacTBDataFormatter.h.

References LogDebug.

26  {
27  LogDebug("EcalTBRawToDigi") << "@SUB=CamacTBDataFormatter"
28  << "\n";
29  };
#define LogDebug(id)

Member Function Documentation

◆ checkStatus()

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

Definition at line 479 of file CamacTBDataFormatter.cc.

References nWordsPerEvent, and statusWords.

Referenced by interpretRawData().

479  {
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 }
uint64_t word
Log< level::Warning, false > LogWarning

◆ interpretRawData()

void CamacTBDataFormatter::interpretRawData ( const FEDRawData data,
EcalTBEventHeader tbEventHeader,
EcalTBHodoscopeRawInfo hodoRaw,
EcalTBTDCRawInfo tdcRawInfo 
)

Definition at line 162 of file CamacTBDataFormatter.cc.

References a, b, edmScanValgrind::buffer, checkStatus(), FEDRawData::data(), FCDTask_cfi::fiber, hodoFiberMap, hodoHits, hodoRawLen, mps_fire::i, dqmiolumiharvest::j, LogDebug, hodo_fibre_index::nfiber, nHodoFibers, nHodoPlanes, nWordsPerEvent, writedatasetfile::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().

165  {
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 }
void setHit(unsigned int i, bool status)
std::vector< int > scalers_
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:120
static const int nHodoPlanes
void setSample(unsigned int i, const EcalTBTDCSample &sam)
double a
Definition: hdecay.h:121
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)

Member Data Documentation

◆ hodoAll

int CamacTBDataFormatter::hodoAll[nHodoPlanes *nHodoFibers]
private

Definition at line 54 of file CamacTBDataFormatter.h.

◆ hodoHits

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

Definition at line 53 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

◆ hodoRawLen

const int CamacTBDataFormatter::hodoRawLen = 4
staticprivate

Definition at line 50 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

◆ nHodoFibers

const int CamacTBDataFormatter::nHodoFibers = 64
staticprivate

Definition at line 47 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

◆ nHodoHits

int CamacTBDataFormatter::nHodoHits[nHodoPlanes]
private

Definition at line 52 of file CamacTBDataFormatter.h.

◆ nHodoPlanes

const int CamacTBDataFormatter::nHodoPlanes = 4
staticprivate

Definition at line 49 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

◆ nHodoscopes

const int CamacTBDataFormatter::nHodoscopes = 2
staticprivate

Definition at line 48 of file CamacTBDataFormatter.h.

◆ nWordsPerEvent

int CamacTBDataFormatter::nWordsPerEvent
private

Definition at line 45 of file CamacTBDataFormatter.h.

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

◆ scalers_

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

Definition at line 57 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

◆ statusWords

bool CamacTBDataFormatter::statusWords[148+4]
private

Definition at line 55 of file CamacTBDataFormatter.h.

Referenced by checkStatus(), and interpretRawData().