CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

CamacTBDataFormatter Class Reference

#include <CamacTBDataFormatter.h>

List of all members.

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.

                                            {
  nWordsPerEvent = 148;
}
virtual CamacTBDataFormatter::~CamacTBDataFormatter ( ) [inline, virtual]

Definition at line 33 of file CamacTBDataFormatter.h.

References LogDebug.

{LogDebug("EcalTBRawToDigi") << "@SUB=CamacTBDataFormatter" << "\n"; };

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().

                                                                        {
  

  if ( wordNumber < 1 || wordNumber > nWordsPerEvent)
    { 
      edm::LogWarning("CamacTBDataFormatter::checkStatus") << "checking word number: "
                                                    <<  wordNumber << " which is out of allowed range (" 
                                                    << nWordsPerEvent << ")";
      return false;
    }

  bool isOk = true;

  if  (word & 0x80000000) // daq item not used
    { 
      edm::LogWarning("CamacTBDataFormatter::checkStatus") << "daq item not used at word: "<<  wordNumber;
      statusWords[wordNumber -1] = false;      
      isOk = false;
    }
  
  if (word & 0x40000000) // vme error on data
    { 
      edm::LogWarning("CamacTBDataFormatter::checkStatus") << "vme error on word: "<<  wordNumber;
      statusWords[wordNumber -1] = false;      
      isOk = false;
    }
    
  if (word & 0x20000000) // vme error on status
    { 
      edm::LogWarning("CamacTBDataFormatter::checkStatus") << "vme status error at word: "<<  wordNumber;
      statusWords[wordNumber -1] = false;      
      isOk = false;
    }
    
  if (word & 0x10000000) // camac error (no X)
    { 
      edm::LogWarning("CamacTBDataFormatter::checkStatus") << "camac error (no X) at word: "<<  wordNumber;
      statusWords[wordNumber -1] = false;      
      isOk = false;
    }
    
  if (word & 0x08000000) // camac error (no Q)
    { 
      edm::LogWarning("CamacTBDataFormatter::checkStatus") << "camac error (no Q) at word: "<<  wordNumber;
      statusWords[wordNumber -1] = false;      
      isOk = false;
    }
  
  // camac error check not done on purpose from Aug 8, to speed up Camac communication. This bit status is now ignored.
  //  if (word & 0x04000000) // no camac check error
  //    { 
  //edm::LogWarning("CamacTBDataFormatter::checkStatus") << "no camac check error at word: "<<  wordNumber;
  //statusWords[wordNumber -1] = false;      
  //isOk = false;
  //    }
  
  return isOk;

}
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 EcalDCCTB07UnpackingModule::produce(), and EcalDCCTBUnpackingModule::produce().

{
  

  const unsigned long * buffer = ( reinterpret_cast<unsigned long*>(const_cast<unsigned char*> ( fedData.data())));
  int fedLenght                        = fedData.size(); // in Bytes
  
  // check ultimate fed size and strip off fed-header and -trailer
  if (fedLenght != (nWordsPerEvent *4) )
    {
      edm::LogError("CamacTBDataFormatter") << "CamacTBData has size "  <<  fedLenght
                                       <<" Bytes as opposed to expected " 
                                       << (nWordsPerEvent *4)
                                       << ". Returning.";
      return;
    }

  
  
  unsigned long a=1; // used to extract an 8 Bytes word from fed 
  unsigned long b=1; // used to manipulate the 8 Bytes word and get what needed

  // initializing array of statuses
  for (int wordNumber=0; wordNumber<nWordsPerEvent; wordNumber++)
    { statusWords[wordNumber ] = true;}

  //  for (int wordNumber=0; wordNumber<nWordsPerEvent; wordNumber++)
  //    { checkStatus( buffer[wordNumber],  wordNumber);}
  
  //   for (int wordNumber=0; wordNumber<nWordsPerEvent; wordNumber++)
  //     {
  //       if (! statusWords[wordNumber])
  //    {
  //      edm::LogError("CamacTBDataFormatter") << "bad status in some of the event words; returning;";   
  //    }
  //     }
  
  

  int wordCounter =0;
  wordCounter +=4;


  // read first word
  a = buffer[wordCounter];wordCounter++;
  LogDebug("CamacTBDataFormatter") << "\n\nword:\t" << a;
  
  b = (a& 0xff000000);
  b = b >> 24;
  LogDebug("CamacTBDataFormatter") << "format  ver:\t" << b;

  b = (a& 0xff0000);
  b = b >> 16;
  LogDebug("CamacTBDataFormatter") << "major:\t" << b;

  b = (a& 0xff00);
  b = b >> 8;
  LogDebug("CamacTBDataFormatter") << "minor:\t" << b;

  a = buffer[wordCounter];wordCounter++;
  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
  LogDebug("CamacTBDataFormatter") << "time stamp secs: "<<a;

  a = buffer[wordCounter];wordCounter++;
  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
  LogDebug("CamacTBDataFormatter") << "time stamp musecs: " <<a;


  a = buffer[wordCounter];wordCounter++;
  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
  b = (a& 0xffffff);
  LogDebug("CamacTBDataFormatter") << "LV1A: "<< b;
  int lv1 = b;

  a = buffer[wordCounter];wordCounter++;
  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
  b = (a& 0xffff0000);
  b = b >> 16;
  LogDebug("CamacTBDataFormatter") << "run number: "<< b;
  int run = b;
  b = (a& 0xffff);
  LogDebug("CamacTBDataFormatter") << "spill number: "<< b;
  int spill = b;

  a = buffer[wordCounter];wordCounter++;
  b = (a& 0xffff);
  LogDebug("CamacTBDataFormatter") << "event number in spill: "<< b;

  a = buffer[wordCounter];wordCounter++;
  b = (a& 0xffffff);
  LogDebug("CamacTBDataFormatter") << "internal event number: "<< b;

  a = buffer[wordCounter];wordCounter++;
  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
  b = (a& 0xffff0000);
  b = b >> 16;
  LogDebug("CamacTBDataFormatter") << "vme errors: "<< b;
  b = (a& 0xffff);
  LogDebug("CamacTBDataFormatter") << "camac errors: "<< b;

  a = buffer[wordCounter];wordCounter++;
  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
  b = a;
  LogDebug("CamacTBDataFormatter") << "extended (32 bits) run number: "<< b;

  // skip 1 reserved words
  wordCounter +=1;

  /**********************************
  // acessing the hodoscope block
  **********************************/

  // getting 16 words buffer and checking words statuses
  unsigned long bufferHodo[16]; 
  bool hodoAreGood = true;
  for (int hodo=0; hodo<16; hodo++)
    {
      hodoAreGood = hodoAreGood && checkStatus(buffer[wordCounter], wordCounter);

      a                 = buffer[wordCounter];
      bufferHodo[hodo]  = buffer[wordCounter];
      wordCounter++;
            
      b = (a& 0xffffff);
      LogDebug("CamacTBDataFormatter") << "hodo: " << hodo << "\t: " << b;
    }

  hodoRaw.setPlanes(0);
  // unpacking the hodo data
  if (hodoAreGood){
  for (int iplane=0; iplane<nHodoPlanes; iplane++) 
    {         
      int detType = 1;       // new mapping for electronics channels  
               
      for (int fiber=0; fiber<nHodoFibers; fiber++) { hodoHits[iplane][fiber] = 0; }            
               
      int ch=0;
      
      // loop on [4-24bits words] = 1 plane 
      for(int j=0; j<hodoRawLen; j++) 
        {
          int word=  bufferHodo[  j+iplane*hodoRawLen  ]  &0xffff;
          for(int i=1; i<0x10000; i<<=1) 
            {
              if ( word & i ) 
                {
                  // map electronics channel to No of fibre
                  hodoHits[iplane][ hodoFiberMap[detType][ch].nfiber - 1]++;
                }
              ch ++;
            }
        } 
    }

  
  // building the hodo infos (returning decoded hodoscope hits information)
  hodoRaw.setPlanes((unsigned int)nHodoPlanes);
  for (int ipl = 0; ipl < nHodoPlanes; ipl++) 
    {             
      EcalTBHodoscopePlaneRawHits theHodoPlane;
      theHodoPlane.setChannels((unsigned int)nHodoFibers);
      for (int fib = 0; fib < nHodoFibers; fib++){ theHodoPlane.setHit((unsigned int)fib, (bool)hodoHits[ipl][fib]); }
      hodoRaw.setPlane((unsigned int)ipl, theHodoPlane);
    }
  }
  else
    {
      edm::LogWarning("CamacTBDataFormatter") << "hodoscope block has hardware problems or is partly unused at LV1: "
                                         << lv1 << " spill: " << spill 
                                         << "run: " << run 
                                         << ". Skipping digi.";
    }
  
  



  /**********************************
  // acessing the scalers block
  **********************************/

  // getting 72 words buffer and checking words statuses

  scalers_.clear();
  scalers_.reserve(36);
  
  bool scalersAreGood = true;
  for (int scaler=0; scaler<72; scaler++)
    {
      scalersAreGood = scalersAreGood && checkStatus(buffer[wordCounter], wordCounter);

      a = buffer[wordCounter];      wordCounter++;
      b = (a& 0xffffff);
      LogDebug("CamacTBDataFormatter") << "scaler: " << scaler << "\t: " << b;

      // filling vector container with scalers words
      if ( (scaler%2)==0 ) scalers_.push_back(b);
    }
  if (scalersAreGood){
    tbEventHeader.setScalers (scalers_);  
  }
  else
    {
      edm::LogWarning("CamacTBDataFormatter") << "scalers block has hardware problems  or is partly unused at LV1: "
                                         << lv1 << " spill: " << spill 
                                         << "run: " << run;
    }
  




  /**********************************
  // acessing the fingers block
  **********************************/

  LogDebug("CamacTBDataFormatter") <<"\n";
  bool fingersAreGood = true;
  for (int finger=0; finger<2; finger++)
    {
      fingersAreGood = fingersAreGood && checkStatus(buffer[wordCounter], wordCounter);

      a = buffer[wordCounter];      wordCounter++;
      b = (a& 0xffffff);
      LogDebug("CamacTBDataFormatter") << "finger: " << finger << "\t: " << b;
    }
  if (fingersAreGood){
    ;  }
  else
    {
      edm::LogWarning("CamacTBDataFormatter") << "fingers block has hardware problems  or is partly unused at LV1: "
                                         << lv1 << " spill: " << spill 
                                         << "run: " << run;
    }
  



  /**********************************
  // acessing the multi stop TDC block
  **********************************/

  a = buffer[wordCounter];      wordCounter++;
  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
  b = (a& 0x000000ff);
  LogDebug("CamacTBDataFormatter") << "number of words used in multi stop TDC words: "<< b;
  
  int numberTDCwords = b;
  numberTDCwords = 16;
  bool multiStopTDCIsGood = true;
  for (int tdc=0; tdc< numberTDCwords ; tdc++)
    {
      multiStopTDCIsGood =  multiStopTDCIsGood && checkStatus(buffer[wordCounter], wordCounter);

      a = buffer[wordCounter];      wordCounter++;
      b =a;
      LogDebug("CamacTBDataFormatter") << "tdc: " << tdc << "\t: " << b;
    }
  if ( multiStopTDCIsGood ){
    ;  }
  else
    {
      edm::LogWarning("CamacTBDataFormatter") << "multi stop TDC block has hardware problems or is partly unused at LV1: "
                                         << lv1 << " spill: " << spill 
                                         << "run: " << run;
    }
  
  // skip the unused words in multi stop TDC block
  wordCounter += (16 - numberTDCwords);

  

  
  /**********************************
  // acessing table in position bit
  **********************************/
  a = buffer[wordCounter];      wordCounter++;
  b = (a & 0x00000001);  //1= table is in position; 0=table is moving
  bool tableIsMoving;
  if ( b ){
    LogDebug("CamacTBDataFormatter") << " table is in position.";
    tableIsMoving = false;
  }
  else
    {
    LogDebug("CamacTBDataFormatter") << " table is moving.";
    tableIsMoving = true;
    }
  tbEventHeader.setTableIsMoving( tableIsMoving );


  wordCounter += 3;

  
  
  /**********************************
   // acessing ADC block
   **********************************/
  // skip 10 reserved words
  wordCounter += 10;
  bool ADCIsGood = true;
//  ADCIsGood =  ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
  ADCIsGood = checkStatus(buffer[wordCounter], wordCounter);
  a = buffer[wordCounter];      wordCounter++;  // NOT read out
  b = (a&0x00ffffff);
  LogDebug("CamacTBDataFormatter") << "ADC word1: " << a << "\t ADC2: " << b << " word is: " << (wordCounter-1);
//  ADCIsGood = true;
//  ADCIsGood = ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
  ADCIsGood = checkStatus(buffer[wordCounter], wordCounter);
  a = buffer[wordCounter];      wordCounter++;  // read out
  b = (a&0xffffff);
  LogDebug("CamacTBDataFormatter") << "ADC word2, adc channel 11, ampli S6: " << a << "\t ADC2: " << b;
  if (ADCIsGood) tbEventHeader.setS6ADC ( b ) ;
  else tbEventHeader.setS6ADC ( -1 ) ;

  
  /**********************************
   // acessing TDC block
   **********************************/
  // skip 6 reserved words
  wordCounter += 6;
  ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
  a = buffer[wordCounter];      wordCounter++;
  b = (a & 0xfffff);
  LogDebug("CamacTBDataFormatter") << "TDC word1: " << a << "\t TDC2: " << b;
  ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
  a = buffer[wordCounter];      wordCounter++;
  b = (a & 0xfffff);
  LogDebug("CamacTBDataFormatter") << "TDC word2: (ext_val_trig - LHC_clock) " 
                                   << a << "\t (ext_val_trig - LHC_clock): "
                                   << b;
  
  tdcRawInfo.setSize(1);
  int sampleNumber =1;
  EcalTBTDCSample theTdc(sampleNumber, b);
  tdcRawInfo.setSample(0, theTdc);


  a = buffer[wordCounter];      wordCounter++;
  LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
  b = a;
  LogDebug("CamacTBDataFormatter") << "last word of event: "<< b;


}

Member Data Documentation

Definition at line 60 of file CamacTBDataFormatter.h.

Definition at line 59 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

const int CamacTBDataFormatter::hodoRawLen = 4 [static, private]

Definition at line 56 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

const int CamacTBDataFormatter::nHodoFibers = 64 [static, private]

Definition at line 53 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

Definition at line 58 of file CamacTBDataFormatter.h.

const int CamacTBDataFormatter::nHodoPlanes = 4 [static, private]

Definition at line 55 of file CamacTBDataFormatter.h.

Referenced by interpretRawData().

const int CamacTBDataFormatter::nHodoscopes = 2 [static, private]

Definition at line 54 of file CamacTBDataFormatter.h.

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().