LCOV - code coverage report
Current view: top level - HLT/RCU - AliHLTAltroEncoder.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 367 0.3 %
Date: 2016-06-14 17:26:59 Functions: 1 21 4.8 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : //**************************************************************************
       4             : //* This file is property of and copyright by the ALICE HLT Project        * 
       5             : //* ALICE Experiment at CERN, All rights reserved.                         *
       6             : //*                                                                        *
       7             : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
       8             : //*                  for The ALICE HLT Project.                            *
       9             : //*                                                                        *
      10             : //* Permission to use, copy, modify and distribute this software and its   *
      11             : //* documentation strictly for non-commercial purposes is hereby granted   *
      12             : //* without fee, provided that the above copyright notice appears in all   *
      13             : //* copies and that both the copyright notice and this permission notice   *
      14             : //* appear in the supporting documentation. The authors make no claims     *
      15             : //* about the suitability of this software for any purpose. It is          *
      16             : //* provided "as is" without express or implied warranty.                  *
      17             : //**************************************************************************
      18             : 
      19             : /** @file   AliHLTAltroEncoder.cxx
      20             :     @author Matthias Richter
      21             :     @date   
      22             :     @brief  Encoder class for 10/40bit Altro Data format
      23             : */
      24             : 
      25             : #include <cassert>
      26             : #include <cerrno>
      27             : #include "AliHLTAltroEncoder.h"
      28             : #include "TArrayC.h"
      29             : 
      30             : /** ROOT macro for the implementation of ROOT specific class methods */
      31           6 : ClassImp(AliHLTAltroEncoder)
      32             : 
      33           0 : AliHLTAltroEncoder::AliHLTAltroEncoder()
      34             :   :
      35           0 :   fpBuffer(NULL),
      36           0 :   fBufferSize(0),
      37           0 :   fPrevTimebin(AliHLTUInt16MAX),
      38           0 :   fBunchLength(0),
      39           0 :   fChannelStart(0),
      40           0 :   fChannel(AliHLTUInt16MAX),
      41           0 :   fChannels(),
      42           0 :   fOffset(0),
      43           0 :   f10bitWords(0),
      44           0 :   fOrder(kUnknownOrder),
      45           0 :   fpCDH(NULL),
      46           0 :   fCDHSize(0),
      47           0 :   fpRCUTrailer(NULL),
      48           0 :   f32BitFormat(kFALSE),
      49           0 :   fPointerToCurrentAltroHeader(NULL),
      50           0 :   fPointerToCurrentBunchWord(NULL),
      51           0 :   fWordLocationOfBunchCount(0),
      52           0 :   fNumberOfAltroHeadersInPayload(0),
      53           0 :   fFillWord(kFALSE),
      54           0 :   fDDLid(0),
      55           0 :   fSlice(0),
      56           0 :   fPartition(0)
      57           0 : {
      58             :   // see header file for class documentation
      59             :   // or
      60             :   // refer to README to build package
      61             :   // or
      62             :   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
      63           0 : }
      64             : 
      65           0 : AliHLTAltroEncoder::AliHLTAltroEncoder(AliHLTUInt8_t* pBuffer, int iSize)
      66             :   :
      67           0 :   fpBuffer(pBuffer),
      68           0 :   fBufferSize(iSize),
      69           0 :   fPrevTimebin(AliHLTUInt16MAX),
      70           0 :   fBunchLength(0),
      71           0 :   fChannelStart(0),
      72           0 :   fChannel(AliHLTUInt16MAX),
      73           0 :   fChannels(),
      74           0 :   fOffset(0),
      75           0 :   f10bitWords(0),
      76           0 :   fOrder(kUnknownOrder),
      77           0 :   fpCDH(NULL),
      78           0 :   fCDHSize(0),
      79           0 :   fpRCUTrailer(NULL),
      80           0 :   f32BitFormat(kFALSE),
      81           0 :   fPointerToCurrentAltroHeader(NULL),
      82           0 :   fPointerToCurrentBunchWord(NULL),
      83           0 :   fWordLocationOfBunchCount(0),
      84           0 :   fNumberOfAltroHeadersInPayload(0),
      85           0 :   fFillWord(kFALSE),
      86           0 :   fDDLid(0),
      87           0 :   fSlice(0),
      88           0 :   fPartition(0)
      89           0 : {
      90             :   // see header file for class documentation
      91           0 : }
      92             : 
      93             : AliHLTAltroEncoder::~AliHLTAltroEncoder()
      94           0 : {
      95             :   // see header file for class documentation
      96           0 :   if (fpCDH) delete fpCDH;
      97           0 :   fpCDH=NULL;
      98             : 
      99           0 :   if (fpRCUTrailer) delete fpRCUTrailer;
     100           0 :   fpRCUTrailer=NULL;
     101           0 : }
     102             : 
     103             : int AliHLTAltroEncoder::SetBuffer(AliHLTUInt8_t* pBuffer, int iSize)
     104             : {
     105             :   // see header file for class documentation
     106           0 :   fpBuffer=pBuffer;
     107           0 :   fBufferSize=iSize;
     108             : 
     109           0 :   return 0;
     110             : }
     111             : 
     112             : int AliHLTAltroEncoder::AddSignal(AliHLTUInt16_t signal, AliHLTUInt16_t timebin)
     113             : {
     114             :   // see header file for class documentation
     115             :   int iResult=0;
     116           0 :   if (fPrevTimebin!=AliHLTUInt16MAX) {
     117           0 :     if (fPrevTimebin==timebin){
     118           0 :       HLTWarning("timebin missmatch, two subsequent signals with identical time added, ignoring signal %d at time %d", signal, timebin);
     119           0 :       return -EINVAL;
     120             :     }
     121             :     //assert(fPrevTimebin!=timebin);
     122           0 :     if (fOrder==kUnknownOrder) {
     123           0 :       if (fPrevTimebin+1==timebin) fOrder=kAscending;
     124           0 :       else if (fPrevTimebin==timebin+1) fOrder=kDescending;
     125             :     }
     126           0 :     if ((fOrder!=kAscending || fPrevTimebin+1!=timebin) &&
     127           0 :         (fOrder!=kDescending || fPrevTimebin!=timebin+1)) {
     128             :       // Finalize bunch and start new one
     129           0 :       iResult=SetBunch();
     130           0 :     }
     131             :   }
     132             : 
     133           0 :   if (iResult>=0 && (iResult=Add10BitValue(signal))>=0) {
     134           0 :     fBunchLength++;
     135           0 :   }
     136             :   //  HLTDebug("fOffset: %d  (fOffset-32)*4: %d  f10bitWords*5 %d", fOffset,(fOffset-32)*4,f10bitWords*5);
     137           0 :   assert((fOffset-(fpCDH?fpCDH->GetSize():0)*4)<=f10bitWords*5);//32 is here size of CDH 8 32bit words
     138           0 :   fPrevTimebin=timebin;
     139           0 :   return iResult;
     140           0 : }
     141             : 
     142             : int AliHLTAltroEncoder::SetChannel(AliHLTUInt16_t hwaddress)
     143             : {
     144             :   // see header file for class documentation
     145             :   int iResult=0;
     146           0 :   if(f32BitFormat == kTRUE){
     147           0 :     if(fPointerToCurrentAltroHeader==NULL){
     148           0 :       return -1; //Add correct error
     149             :     }
     150             : 
     151             : 
     152           0 :     SetBunch();//finalize the last bunch
     153             : 
     154           0 :     f10bitWords-=2;//remove the two words that was reserved for the next bunch
     155             :     
     156             :     // set all bits in the altro header to 0
     157           0 :     for(Int_t i=0;i<4;i++){
     158           0 :       fPointerToCurrentAltroHeader[i]=0;
     159             :     }
     160             :     //set the HW address to bit 0-15
     161           0 :     fPointerToCurrentAltroHeader[0]=hwaddress&0xff;      // copy the first 8 bits
     162           0 :     fPointerToCurrentAltroHeader[1]=(hwaddress>>8)&0xff; // copy the last 8 bits
     163             :     
     164             :     // set number of 10 bit words to bit 16-28
     165           0 :     AliHLTUInt16_t length= f10bitWords - fChannelStart;
     166           0 :     fPointerToCurrentAltroHeader[2]= length&0xff;     // copy the first 8 bits
     167           0 :     fPointerToCurrentAltroHeader[3]= (length>>8)&0xf; // copy the last 4 bits
     168             : 
     169             :  
     170             :     //fill up with fillwords
     171           0 :     while((f10bitWords%3) != 0){
     172           0 :       fFillWord=kTRUE;
     173           0 :       Add10BitValue(0);
     174             :     }
     175           0 :     fFillWord= kFALSE;
     176             : 
     177             :     // Set the error bit to 0 (bit 29) and the bit 30 and 31 to 10(mark that this is the altro header)
     178             :     // These three bits are already zero, so in effect it is only bit 31 which is set to 1
     179           0 :     fPointerToCurrentAltroHeader[3] |= 0x40; // (0x80 = 1 0 0 0 0 0 0 0)
     180           0 :     fChannelStart=f10bitWords;
     181           0 :     fNumberOfAltroHeadersInPayload++;
     182             :   }
     183             :   else{
     184             :     int added10BitWords=0;
     185           0 :     if (!fpBuffer) return -ENODEV;
     186           0 :     if (fOffset+5>=fBufferSize-(fpRCUTrailer?fpRCUTrailer->GetSize():0)) {
     187           0 :       HLTWarning("buffer too small too finalize channel: %d of %d byte(s) already used", fOffset, fBufferSize);
     188           0 :       return -ENOSPC;
     189             :     }
     190             :     
     191           0 :     if (iResult>=0 && 
     192           0 :         (iResult=SetBunch())>=0) {
     193           0 :       AliHLTUInt16_t length=f10bitWords-fChannelStart;
     194           0 :       if ((iResult=Pad40Bit())<0) return iResult;
     195             :       // 2 words for the SetBunch (end time and length) and the
     196             :       // padded words to fill 40bit word
     197           0 :       added10BitWords=iResult+2;
     198           0 :       assert((length+iResult)%4==0);
     199             :       //HLTInfo("%d %x", hwaddress, hwaddress);
     200           0 :       fpBuffer[fOffset++]=hwaddress&0xff;
     201           0 :       fpBuffer[fOffset++]=0xa0 | ((hwaddress>>8)&0xf);
     202           0 :       fpBuffer[fOffset++]=length&0xff;
     203           0 :       fpBuffer[fOffset++]=0xa8 | ((length>>8)&0x3);
     204           0 :       fpBuffer[fOffset++]=0xaa;
     205           0 :       f10bitWords+=4;
     206           0 :       fChannelStart=f10bitWords;
     207           0 :       fChannels.push_back(hwaddress);
     208           0 :       fPrevTimebin=AliHLTUInt16MAX;
     209           0 :     }
     210           0 :     if (iResult<0) return iResult;
     211             :     
     212           0 :     return added10BitWords;
     213             :   }
     214           0 :   return 0;
     215           0 : }
     216             : 
     217             : int AliHLTAltroEncoder::AddChannelSignal(AliHLTUInt16_t signal, AliHLTUInt16_t timebin, AliHLTUInt16_t hwaddress)
     218             : {
     219             :   // see header file for class documentation
     220             :   int iResult=0;
     221             :   int added10BitWords=0;
     222           0 :   if (fChannel==AliHLTUInt16MAX) {
     223           0 :     fChannel=hwaddress;
     224           0 :   } else if (fChannel!=hwaddress) {
     225           0 :     iResult=SetChannel(fChannel);
     226             :     added10BitWords=iResult;
     227           0 :     fChannel=hwaddress;
     228           0 :   }
     229             : 
     230           0 :   if (iResult>=0) {
     231           0 :     if ((iResult=AddSignal(signal, timebin))>=0)
     232           0 :       added10BitWords++;
     233             :   }
     234             : 
     235           0 :   if (iResult<0) return iResult;
     236           0 :   return added10BitWords;
     237           0 : }
     238             : 
     239             : int AliHLTAltroEncoder::GetTotal40bitWords()
     240             : {
     241             :   // see header file for class documentation
     242           0 :   if (fChannelStart!=f10bitWords) {
     243           0 :     HLTWarning("unterminated channel found, check calling sequence");
     244             :   }
     245           0 :   assert(fChannelStart%4==0);
     246             : 
     247           0 :   return fChannelStart;
     248             : }
     249             : 
     250             : int AliHLTAltroEncoder::SetBunch()
     251             : {
     252             :   // see header file for class documentation
     253             :   int iResult=0;
     254             : 
     255             :   // return if the bunch has already been set
     256           0 :   if (fBunchLength==0) return 0;
     257             : 
     258             :   // fill time bin and bunch length
     259           0 :   if(f32BitFormat == kTRUE){
     260           0 :     if(fWordLocationOfBunchCount==3){
     261             :       //means we have to put the n10bitWords into word 3 
     262             :       //of the 32 bit word and the timebin value into word 2
     263           0 :       fBunchLength+=2;//takes the n10bitwords and the timebin value into account
     264             : 
     265             :       //insert the first 4 bits of the 10 bit word into the end of 8bit word 3.
     266           0 :       fPointerToCurrentBunchWord[2] |= (fBunchLength<<4)&0xf0;
     267             :       
     268             :       //insert the last 6 bits of the 10 bit word into the beginning of 8bitword 4
     269           0 :       fPointerToCurrentBunchWord[3] |= (fBunchLength>>4)&0x3f;
     270             :       
     271             :       //set the timebin value
     272             :       //insert the first 6 bits of the 10bitword into the end of 8bit word 2
     273           0 :       fPointerToCurrentBunchWord[1] |= ((fPrevTimebin+fBunchLength-3)<<2)&0xfc;
     274             :       //insert the last 4 bits of the 10bitWord into the beginning of 8bit word 3
     275           0 :       fPointerToCurrentBunchWord[2] |= ((fPrevTimebin+fBunchLength-3)>>6)&0xf;
     276             :       // set the bunch word pointer and which word the n10bitwords are in
     277           0 :       fPointerToCurrentBunchWord = &fpBuffer[fOffset];
     278           0 :       fWordLocationOfBunchCount = 3-f10bitWords%3;
     279           0 :       if(fWordLocationOfBunchCount<3){
     280           0 :         fOffset+=4;
     281           0 :         fpBuffer[fOffset]=0;
     282           0 :         fpBuffer[fOffset+1]=0;
     283           0 :         fpBuffer[fOffset+2]=0;
     284           0 :         fpBuffer[fOffset+3]=0;
     285           0 :       }
     286           0 :       f10bitWords+=2;// makes room for the n10bitwords and the timebin
     287           0 :       fBunchLength=0;
     288           0 :     }
     289           0 :     else if(fWordLocationOfBunchCount==2){
     290             :       //means we have to put the n10bitWords into word 2 of the 32 bit word
     291             :       //and the timebin value into word 1
     292             : 
     293           0 :       fBunchLength+=2;//takes the n10bitwords and the timebin value into account
     294             : 
     295             :       //insert the first 6 bits of the 10 bit word into the end of 8bit word 2.
     296           0 :       fPointerToCurrentBunchWord[1] |= (fBunchLength<<2)&0xfc;
     297             :       
     298             :       //insert the last 4 bits of the 10 bit word into the beginning of 8bitword 3
     299           0 :       fPointerToCurrentBunchWord[2] |= (fBunchLength>>6)&0xf;
     300             :       
     301             :       //set the timebin value
     302             :       //insert the first 8 bits of the 10bitword into the end of 8bit word 1
     303           0 :       fPointerToCurrentBunchWord[0] |= (fPrevTimebin+fBunchLength-3)&0xff;
     304             :       //insert the last 2 bits of the 10bitWord into the beginning of 8bit word 2
     305           0 :       fPointerToCurrentBunchWord[1] |= ((fPrevTimebin+fBunchLength-3)>>8)&0x3;
     306             :       // set the bunch word pointer and which word the n10bitwords are in
     307           0 :       fPointerToCurrentBunchWord = &fpBuffer[fOffset];
     308           0 :       fWordLocationOfBunchCount = 3-f10bitWords%3;
     309           0 :       if(fWordLocationOfBunchCount<3){
     310           0 :         fOffset+=4;
     311           0 :         fpBuffer[fOffset]=0;
     312           0 :         fpBuffer[fOffset+1]=0;
     313           0 :         fpBuffer[fOffset+2]=0;
     314           0 :         fpBuffer[fOffset+3]=0;
     315           0 :       }
     316           0 :       f10bitWords+=2;// makes room for the n10bitwords and the timebin
     317           0 :       fBunchLength=0;
     318           0 :     }
     319           0 :     else if(fWordLocationOfBunchCount==1){
     320             :       //means we have to put the n10bitWords into word 1 of the 32 bit word
     321             :       //and the timebin value into word 3 of the next 32 bit word
     322             : 
     323           0 :       fBunchLength+=2;//takes the n10bitwords and the timebin value into account
     324             : 
     325             :       //insert the first 8 bits of the 10 bit word into the beginning of 8bit word 1.
     326           0 :       fPointerToCurrentBunchWord[0] |= fBunchLength&0xff;
     327             :       
     328             :       //insert the last 2 bits of the 10 bit word into the beginning of 8bitword 2
     329           0 :       fPointerToCurrentBunchWord[1] |= (fBunchLength>>8)&0x3;
     330             :       
     331             :       //set the timebin value
     332             :       //insert the first 4 bits of the 10bitword into the end of 8bit word 7
     333           0 :       fPointerToCurrentBunchWord[6] |= ((fPrevTimebin+fBunchLength-3)<<4)&0xf0;
     334             :       //insert the last 6 bits of the 10bitWord into the beginning of 8bit word 8
     335           0 :       fPointerToCurrentBunchWord[7] |= ((fPrevTimebin+fBunchLength-3)>>4)&0x3f;
     336             :       // set the bunch word pointer and which word the n10bitwords are in
     337           0 :       fPointerToCurrentBunchWord = &fpBuffer[fOffset];
     338           0 :       fWordLocationOfBunchCount = 3-f10bitWords%3;
     339           0 :       if(fWordLocationOfBunchCount<3){
     340           0 :         fOffset+=4;
     341           0 :         fpBuffer[fOffset]=0;
     342           0 :         fpBuffer[fOffset+1]=0;
     343           0 :         fpBuffer[fOffset+2]=0;
     344           0 :         fpBuffer[fOffset+3]=0;
     345           0 :       }
     346           0 :       f10bitWords+=2;// makes room for the n10bitwords and the timebin
     347           0 :       fBunchLength=0;
     348           0 :     }
     349             :     
     350             :   }
     351             :   else{
     352           0 :     if ((iResult=Add10BitValue(fPrevTimebin))>=0) {
     353           0 :       iResult=Add10BitValue(fBunchLength+2);
     354           0 :       fBunchLength=0;
     355             :       iResult=2;
     356           0 :     }
     357             :   }
     358             :   //  fPrevTimebin=AliHLTUInt16MAX;// resets the timebin number
     359           0 :   return iResult;
     360           0 : }
     361             : 
     362             : int AliHLTAltroEncoder::Add10BitValue(AliHLTUInt16_t value)
     363             : {
     364             :   // see header file for class documentation
     365             :   int iResult=0;
     366           0 :   if (!fpBuffer) return -ENODEV;
     367           0 :   if (fOffset+2>=fBufferSize-(fpRCUTrailer?fpRCUTrailer->GetSize():0)) {
     368           0 :     HLTWarning("buffer too small too add 10bit word: %d of %d byte(s) already used", fOffset, fBufferSize);
     369           0 :     return -ENOSPC;
     370             :   }
     371             : 
     372           0 :   if(value>1023){
     373           0 :     HLTError("10 bit value cannot be larger than 1023, something is wrong.");
     374           0 :     return -1; //TODO find better error
     375             :   }
     376             : 
     377           0 :   if(f32BitFormat == kFALSE){
     378           0 :     int bit=(f10bitWords%4)*10;
     379           0 :     int shift=bit%8;
     380           0 :     unsigned short maskLow=~((0xff<<shift)>>8);
     381             :     //unsigned short maskHigh=~((0xff<<((bit+10)%8))>>8);
     382           0 :     if (bit==0) fpBuffer[fOffset]=0;
     383           0 :     fpBuffer[fOffset++]|=maskLow&(value<<shift);
     384           0 :     fpBuffer[fOffset]=(value&0x3ff)>>(8-shift);
     385           0 :     f10bitWords++;
     386           0 :     if (f10bitWords%4==0) fOffset++;
     387             :     return iResult;
     388             :   }
     389             :   else{
     390           0 :     if(f10bitWords == fChannelStart){ //means that there is a new channel(or the first)
     391           0 :       fPointerToCurrentAltroHeader = &fpBuffer[fOffset]; // set a pointer to the beginning of the altro header
     392             : 
     393           0 :       fOffset+=4; //Makes space for the altro header in front of the altrodata (1 32 bit word)
     394             :       
     395           0 :       fpBuffer[fOffset]=0;
     396           0 :       fpBuffer[fOffset+1]=0;
     397           0 :       fpBuffer[fOffset+2]=0;
     398           0 :       fpBuffer[fOffset+3]=0;
     399             :       
     400             :       //set the pointer to the bunch currently being filled
     401             :       //it is always in the 3d 10 bit word when a new channel has started.
     402           0 :       fPointerToCurrentBunchWord = &fpBuffer[fOffset];
     403           0 :       fWordLocationOfBunchCount=3;
     404             :       //make room for the n10BitWords, and the timebin value
     405             :       //      fOffset+=2;
     406           0 :       f10bitWords+=2;
     407           0 :     }
     408             : 
     409           0 :     int bit=20-(f10bitWords%3)*10;
     410             : 
     411           0 :     if(bit ==20){//means we should fill the third word
     412             :       //set bits 25-32 to 0, this also takes care of setting the marker (00) at the end.
     413           0 :       fpBuffer[fOffset+3] = 0;
     414             :       //copy the last 6 bits of the signal into the first 6 bits of 8BitWord 3
     415           0 :       fpBuffer[fOffset+3] |= (value>>4)&0x3f;
     416             :       //set bits 17-24 to 0
     417           0 :       fpBuffer[fOffset+2]=0;
     418             :       //copy the first 4 bits of the signal into the last 4 bits of 8BitWord 2
     419           0 :       fpBuffer[fOffset+2] |= (value<<4)&0xf0;
     420           0 :       f10bitWords++;
     421           0 :     }
     422           0 :     else if(bit == 10){//means we should fill the middle (2nd) word
     423             :       //copy the last 4 bits of the signal into the first 4 bits of 8BitWord 2
     424           0 :       fpBuffer[fOffset+2] |= (value>>6)&0xf;
     425             :       //set bits 8-16 to 0
     426           0 :       fpBuffer[fOffset+1]=0;
     427             :       //copy the first 6 bits of the signal into the last 6 bits of 8BitWord 1
     428           0 :       fpBuffer[fOffset+1] |= (value<<2)&0xfc;
     429           0 :       f10bitWords++;
     430           0 :     }
     431           0 :     else if(bit == 0){
     432             :       //set bits 0-7 to 0
     433           0 :       fpBuffer[fOffset]=0;
     434             :       //copy the last 2 bits of the signal into the first 2 bits of 8BitWord 1
     435           0 :       fpBuffer[fOffset+1] |= (value>>8)&0x3;
     436             :       //copy the first 8 bits of the signal into the first 8 bits of 8BitWord 0
     437           0 :       fpBuffer[fOffset] |= value&0xff;
     438           0 :       f10bitWords++;
     439           0 :       if(fFillWord == kFALSE){
     440           0 :         fOffset += 4; // only increase when the last word is added
     441           0 :         fpBuffer[fOffset]=0;
     442           0 :         fpBuffer[fOffset+1]=0;
     443           0 :         fpBuffer[fOffset+2]=0;
     444           0 :         fpBuffer[fOffset+3]=0;
     445           0 :       }
     446             :     }
     447             :   }
     448           0 :   return f10bitWords;
     449           0 : }
     450             : 
     451             : int AliHLTAltroEncoder::Pad40Bit()
     452             : {
     453             :   // see header file for class documentation
     454             :   int iResult=0;
     455             :   int added10BitWords=0;
     456           0 :   while (iResult>=0 && f10bitWords%4!=0) {
     457           0 :     if ((iResult=Add10BitValue(0x2aa))>=0) {
     458           0 :       added10BitWords++;
     459           0 :     }
     460             :   }
     461           0 :   if (iResult<0) return iResult;
     462           0 :   return added10BitWords;
     463           0 : }
     464             : 
     465             : int AliHLTAltroEncoder::SetCDH(AliHLTUInt8_t* pCDH,int size)
     466             : {
     467             :   // see header file for class documentation
     468             :   int iResult=0;
     469           0 :   if (fOffset>0) {
     470           0 :     HLTError("CDH can only be set prior to data");
     471             :     iResult=-EFAULT;
     472           0 :   }
     473           0 :   if (size>0 && pCDH){
     474           0 :     if (fpCDH == NULL){
     475           0 :       fpCDH = new TArrayC(0);
     476           0 :     }
     477           0 :     if (fpCDH){
     478           0 :       fpCDH->Set(0);
     479           0 :       fpCDH->Set(size, (const char*)pCDH);
     480           0 :       fOffset=size;
     481           0 :       fCDHSize=size;
     482           0 :     } else {
     483             :       iResult=-ENOMEM;
     484             :     }
     485             :   } else {
     486             :     iResult=-EINVAL;
     487             :   }
     488           0 :   return iResult;
     489           0 : }
     490             : 
     491             : int AliHLTAltroEncoder::SetRCUTrailer(AliHLTUInt8_t* pRCUTrailer,int size)
     492             : {
     493             :   // see header file for class documentation
     494             :   int iResult=0;
     495           0 :   if (size>0 && pRCUTrailer){
     496           0 :     if (fpRCUTrailer == NULL){
     497           0 :       fpRCUTrailer = new TArrayC(0);
     498           0 :     }
     499           0 :     if (fpRCUTrailer){
     500           0 :       fpRCUTrailer->Set(0);
     501           0 :       fpRCUTrailer->Set(size, (const char*)pRCUTrailer);
     502           0 :     } else {
     503             :       iResult=-ENOMEM;
     504             :     }
     505             :   } else {
     506             :     iResult=-EINVAL;
     507             :   }
     508           0 :   return iResult;
     509           0 : }
     510             : 
     511             : int AliHLTAltroEncoder::SetLength()
     512             : {
     513             :   // see header file for class documentation
     514             :   int iResult=0;
     515           0 :   if (fChannel!=AliHLTUInt16MAX && (iResult=SetChannel(fChannel))<0) {
     516           0 :     HLTError("error finalizing channel");
     517           0 :     return iResult;
     518             :   }
     519             : 
     520           0 :   if (fpRCUTrailer && fOffset+fpRCUTrailer->GetSize()<fBufferSize) {
     521             :     // copy the trailer
     522           0 :     AliHLTUInt32_t* pTgt=reinterpret_cast<AliHLTUInt32_t*>(fpBuffer+fOffset);
     523           0 :     memcpy(pTgt, fpRCUTrailer->GetArray(), fpRCUTrailer->GetSize());
     524             :     // set number of 10bit words
     525           0 :     *pTgt=GetTotal40bitWords();
     526           0 :     fOffset+=fpRCUTrailer->GetSize();
     527           0 :   }
     528           0 :   if (fpCDH && fOffset>fpCDH->GetSize()) {
     529           0 :     memcpy(fpBuffer, fpCDH->GetArray(), fpCDH->GetSize());
     530           0 :     AliHLTUInt32_t* pCdhSize=reinterpret_cast<AliHLTUInt32_t*>(fpBuffer);
     531           0 :     *pCdhSize=fOffset;//set the first word in the header to be the fOffset(number of bytes added)  
     532             :     HLTDebug("Size set in the header: %d",*pCdhSize);
     533           0 :   }
     534           0 :   if(f32BitFormat == kTRUE){
     535             :     //set all bits to 1 in the first 32 bit of the cdh
     536             :     
     537             :     //word 0
     538           0 :     fpBuffer[0] |= 0xff;
     539           0 :     fpBuffer[1] |= 0xff;
     540           0 :     fpBuffer[2] |= 0xff;
     541           0 :     fpBuffer[3] |= 0xff;
     542             :     
     543             :     //word 3
     544           0 :     fpBuffer[14] =0;
     545           0 :     fpBuffer[14] |= 0x2;
     546             : 
     547           0 :   }
     548           0 :   return fOffset;
     549           0 : }
     550             : 
     551             : void AliHLTAltroEncoder::Revert40BitWords(Int_t /*CDHSize*/, Int_t /*trailerSize*/)
     552             : {
     553             :   // see headerfile for class documentation
     554           0 :   HLTWarning("Revert40BitWords function no longer has any function, please remove this function call from your analysis");
     555           0 : }
     556             : 
     557             : void AliHLTAltroEncoder::PrintDebug()
     558             : {
     559           0 :   int n32bitWords = fOffset/4;
     560             :   int word8Counter = 0;
     561             :   Bool_t isAnAltroHeader=kFALSE;
     562             :   Bool_t isData=kFALSE;
     563             :   Bool_t isCDH=kFALSE;
     564             :   Bool_t isTrailer=kFALSE;
     565             :   
     566           0 :   for(Int_t n32bit=0;n32bit<n32bitWords;n32bit++){
     567             :     isAnAltroHeader=kFALSE;
     568             :     isData=kFALSE;
     569             :     isCDH=kFALSE;
     570             :     isTrailer=kFALSE;
     571           0 :     for(Int_t w=0;w<4;w++){
     572           0 :       Int_t wordPosition = 4-word8Counter%4;
     573           0 :       AliHLTUInt8_t word = fpBuffer[n32bit*4+wordPosition-1];
     574             :       
     575           0 :       if(n32bit < fCDHSize/4){
     576             :         isCDH = kTRUE;
     577           0 :       }
     578           0 :       else if(wordPosition==4 && (word & 0x80)==0 && (word & 0x40)!=0){//means we have a altroheader 
     579             :         isAnAltroHeader=kTRUE;
     580           0 :       }
     581           0 :       else if(wordPosition==4 && (word & 0x80)==0 && (word & 0x40)==0){//means we have data
     582             :         isData=kTRUE;
     583           0 :       }
     584           0 :       else if(wordPosition==4 && (word & 0x80) !=0 && (word & 0x40)==0){//means we have trailer
     585             :         isTrailer=kTRUE;
     586           0 :       }
     587           0 :       else if(wordPosition==4 && (word & 0x80) !=0 && (word & 0x40) !=0){//means we have trailer (last trailer word)
     588             :         isTrailer=kTRUE;
     589           0 :       }
     590           0 :       for(int n=7; n>=0; n--){
     591           0 :         if(isAnAltroHeader == kTRUE){
     592           0 :           if((wordPosition == 4 && n==5) || (wordPosition == 4 && n==4) /*|| wordPosition == 4 && n==0*/){
     593           0 :             printf("\t");
     594           0 :           }
     595           0 :           if(wordPosition == 2 && n==7){
     596           0 :             printf("\t");
     597           0 :           }
     598             :         }
     599           0 :         else if(isData == kTRUE){
     600           0 :           if(wordPosition == 4 && n==5){
     601           0 :             printf("\t");
     602           0 :           }
     603           0 :           if(wordPosition == 3 && n==3){
     604           0 :             printf("\t");
     605           0 :           }
     606           0 :           if(wordPosition == 2 && n==1){
     607           0 :             printf("\t");
     608           0 :           }
     609             :         }
     610           0 :         else if(isTrailer == kTRUE){
     611           0 :           if(wordPosition == 4 && n==5){
     612           0 :             printf("\t");
     613           0 :           }
     614             :         }
     615             :         //print the byte values
     616           0 :         if((((word>>n)<<7)&0x80) != 0){
     617           0 :           printf("1");
     618           0 :         }
     619             :         else{
     620           0 :           printf("0");
     621             :         }
     622             :       }
     623           0 :       word8Counter++;
     624             :     }
     625           0 :     if(isCDH == kTRUE){
     626           0 :       printf("\t CDH %d\n",n32bit);
     627           0 :     }
     628           0 :     else if(isAnAltroHeader == kTRUE){
     629           0 :       printf("\t AltroHeader \n");
     630           0 :     }
     631           0 :     else if(isData == kTRUE){
     632           0 :       printf("\t Data \n");
     633           0 :     }
     634           0 :     else if(isTrailer == kTRUE){
     635           0 :       printf("\t Trailer \n");
     636           0 :     }
     637             :   }
     638           0 : }
     639             : 

Generated by: LCOV version 1.11