LCOV - code coverage report
Current view: top level - FIT/FITbase - AliFITRawReader.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 113 0.9 %
Date: 2016-06-14 17:26:59 Functions: 1 10 10.0 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /* $Id:  */
      17             : 
      18             : //____________________________________________________________________
      19             : //                                                                          
      20             : // FIT 
      21             : // Class for reading FIT RAW data in TOF data format
      22             : //
      23             : #include "AliFITRawReader.h"
      24             : #include "AliBitPacking.h"
      25             : #include "TBits.h"
      26             : 
      27             : #include <Riostream.h>
      28             : #include "TMath.h"
      29             : #include "TH1F.h"
      30             : #include "AliLog.h"
      31             : 
      32             : using std::cout;
      33             : using std::endl;
      34             : using std::ios_base;
      35           4 : ClassImp(AliFITRawReader)
      36             :   
      37             :   AliFITRawReader::AliFITRawReader (AliRawReader *rawReader)
      38           0 :     :  TTask("FITRawReader","read FIT raw  data"),
      39           0 :        fRawReader(rawReader),
      40           0 :        fData(NULL),
      41           0 :        fPosition(0),
      42           0 :        fBunchID(0),
      43           0 :        fPrintout(kFALSE)
      44             :     
      45           0 : {
      46             :   //
      47             :   // create an object to read FIT raw digits
      48             :   
      49           0 :   fRawReader->Reset();
      50           0 :   fRawReader->Select("FIT"); 
      51           0 :   for ( Int_t k=0; k<1000; k++)   fAllData[k] = -1;
      52             :  
      53           0 : }
      54             : //_____________________________________________________________________________
      55             : AliFITRawReader::~AliFITRawReader ()
      56           0 : {
      57             :   // 
      58           0 : }
      59             : 
      60             : //_____________________________________________________________________________
      61             : 
      62             : Bool_t  AliFITRawReader::Next()
      63             : {
      64             :   // read the next raw digit
      65             :   // returns kFALSE if there is no digit left
      66             : // allData array collect data from all channels in one :
      67             : // allData[0] - allData[79]   CFD channels side C
      68             : // allData[80] - allData[159] CFD channels side A
      69             : // allData[160] -   allData[239]  QT0 channels side C
      70             : // allData[240] -   allData[319]  QT0 channels side A
      71             : // allData[320] -   allData[399]  QT1 channels side C
      72             : // allData[400] -   allData[479]  QT1 channels side A
      73             : 
      74             :   UInt_t word;
      75             :   Int_t time=0,  itdc=0, ichannel=0, uu; 
      76             :   Int_t numberOfWordsInTRM=0, iTRM=0;
      77             :   Int_t tdcTime, koef;
      78             :   Int_t trm_chain_header =  0x00000000;
      79           0 :   Int_t  trm_chain_trailer[2] = { 0x10000000, 0x20000000};
      80             :   UInt_t  filler =  0x70000000;
      81             :   Bool_t correct=kTRUE;
      82             :   Int_t header;
      83             :   
      84           0 :   for ( Int_t k=0; k<1000; k++)   fAllData[k] = -1;
      85             :   
      86             :   
      87           0 :   do {
      88           0 :     if (!fRawReader->ReadNextData(fData)) return kFALSE;
      89           0 :   } while (fRawReader->GetDataSize() == 0);
      90             :   
      91           0 :   fPosition = 0;
      92           0 :   cout.setf( ios_base::hex, ios_base::basefield );
      93           0 :   if(fPrintout)
      94           0 :     cout<<" CDH :: BC ID "<< (fRawReader->GetBCID())<<
      95           0 :       " Event size"<<fRawReader->GetDataSize()<<
      96           0 :       " orbit ID "<<fRawReader->GetOrbitID()<< 
      97           0 :       " event index "<<fRawReader->GetEventIndex()<<
      98           0 :       " event type " <<fRawReader->GetType()<<endl;
      99             :   //DRM header
     100           0 :   for (Int_t i=0; i<6; i++) {
     101           0 :     word = GetNextWord();
     102           0 :     if(fPrintout && i==0) cout<<" DRM header:: event words "<<AliBitPacking::UnpackWord(word,4, 20)<<endl;;
     103           0 :     if (fPrintout && i==4 ) cout<<" L0BC ID "<< AliBitPacking::UnpackWord(word,4, 15)<<endl;
     104           0 :     header = AliBitPacking::UnpackWord(word,28,31);
     105           0 :     if( header !=4 ) 
     106             :       {
     107           0 :         AliWarning(Form(" !!!! wrong  DRM header  %x!!!!", word));
     108           0 :         fRawReader->AddFatalErrorLog(kWrongDRMHeader,Form("w=%x",word));
     109           0 :         break;
     110             :       }
     111             :   }
     112           0 :   for (Int_t ntrm=0; ntrm<4; ntrm++)
     113             :     {
     114             :       //TRMheader  
     115           0 :       word = GetNextWord();
     116           0 :       header = AliBitPacking::UnpackWord(word,28,31);
     117           0 :       if ( header != 4 )
     118             :         {
     119           0 :           AliWarning(Form(" !!!! wrong TRM header  %x!!!!", word));
     120           0 :           fRawReader->AddMajorErrorLog(kWrongTRMHeader,Form("w=%x",word));
     121           0 :           break;
     122             :         }
     123           0 :       numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
     124           0 :       if(fPrintout) {
     125           0 :         cout<<" TRM header :: event words "<<numberOfWordsInTRM;
     126           0 :         cout<<" ACQ bits "<<AliBitPacking::UnpackWord(word,17,18);
     127           0 :         cout<<" L bit "<<AliBitPacking::UnpackWord(word,19,19)<<endl;
     128           0 :       }
     129           0 :       iTRM=AliBitPacking::UnpackWord(word,0,3);
     130           0 :       for( Int_t ichain=0; ichain<2; ichain++)
     131             :         {
     132             :           //chain header
     133           0 :           word = GetNextWord();
     134             :           uu = word & trm_chain_header;
     135           0 :           if(uu != trm_chain_header) 
     136             :             {
     137           0 :               AliWarning(Form(" !!!! wrong CHAIN  0  header %x!!!!", word));
     138           0 :               fRawReader->AddMajorErrorLog(kWrongChain0Header,Form("w=%x",word));
     139           0 :               break;
     140             :             }
     141           0 :           fBunchID=AliBitPacking::UnpackWord(word,4,15);
     142           0 :           if(fPrintout)
     143           0 :             cout<<" chain "<< ichain<<" header:: BunchID  "<<fBunchID<<endl;
     144           0 :           word = GetNextWord();
     145           0 :           tdcTime =  AliBitPacking::UnpackWord(word,31,31);   
     146           0 :           while(tdcTime==1)
     147             :             {
     148             :               correct = kTRUE;
     149           0 :               itdc=AliBitPacking::UnpackWord(word,24,27);
     150           0 :               ichannel=AliBitPacking::UnpackWord(word,21,23);
     151           0 :               time=AliBitPacking::UnpackWord(word,0,20);
     152             :               
     153           0 :               koef = GetChannel(iTRM,itdc,ichain,ichannel);
     154           0 :               if (koef != 0 && fPrintout) 
     155           0 :                 cout<<"RawReader>> "<<"koef "<<koef<<" trm "<<iTRM<<" tdc "<<itdc<<" chain "<<ichain<<                  " channel "<<ichannel<<" time "<<time<<endl;
     156           0 :               if (koef ==-1 ){
     157           0 :                 AliWarning(Form("Incorrect lookup table ! "));
     158           0 :                 fRawReader->AddMajorErrorLog(kIncorrectLUT);
     159             :                 correct=kFALSE;
     160           0 :               }
     161           0 :               if(correct)   fAllData[koef]=time; 
     162           0 :               word = GetNextWord();
     163           0 :                 tdcTime =  AliBitPacking::UnpackWord(word,31,31);   
     164             :             }
     165             :             
     166           0 :           uu = word&trm_chain_trailer[ichain];
     167           0 :           if(uu != trm_chain_trailer[ichain] )
     168             :             {
     169           0 :               AliWarning(Form(" !!!! wrong CHAIN %i trailer %x !!!!", ichain, word));
     170           0 :               fRawReader->AddMajorErrorLog(kWrongChain0Trailer,Form("w=%x",word));
     171           0 :               break;
     172             :             }
     173           0 :           if(fPrintout)
     174           0 :             cout<<" trailer:: event counter "<< AliBitPacking::UnpackWord(word,16,27)<<endl;
     175             :         }
     176             :       
     177           0 :         word = GetNextWord(); //TRM trailer
     178           0 :         header = AliBitPacking::UnpackWord(word,28,31);
     179           0 :         if( header !=5 )
     180             :           {
     181           0 :             AliWarning(Form(" !!!! wrong TRM GLOBAL trailer  %x!!!!", word));
     182           0 :             fRawReader->AddMajorErrorLog(kWrongTRMTrailer,Form("w=%x",word));
     183           0 :             break;
     184             :           }
     185           0 :         if(fPrintout)
     186           0 :           cout<<"  TRM trailer :: event counter "<< AliBitPacking::UnpackWord(word,16,27)<<endl;
     187             :     } //TRM loop
     188           0 :   word = GetNextWord(); //
     189           0 :   if (word == filler )  word = GetNextWord(); 
     190           0 :   header = AliBitPacking::UnpackWord(word,28,31);
     191           0 :   if( header !=5 )
     192             :     {
     193           0 :       AliWarning(Form(" !!!! wrong DRM GLOBAL trailer  %x!!!!", word));
     194             :       // fRawReader->AddFatalErrorLog(kWrongDRMTrailer,Form("w=%x",word));
     195           0 :     }
     196           0 :   if(fPrintout)
     197           0 :     cout<<" DRM trailer ::event counter "<< AliBitPacking::UnpackWord(word,4,15)<<endl;
     198           0 :   cout.setf( ios_base::dec, ios_base::basefield );
     199             :   
     200           0 :   return kTRUE;
     201           0 : }
     202             : //_____________________________________________________________________________
     203             : Int_t AliFITRawReader::GetPosition()
     204             : {
     205             :   // Sets the position in the
     206             :   // input stream
     207           0 :   if (((fRawReader->GetDataSize() * 8) % 32) != 0)
     208           0 :     AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
     209           0 :   return (fRawReader->GetDataSize() * 8) / 32;
     210             : }
     211             : //_____________________________________________________________________________
     212             : UInt_t AliFITRawReader::GetNextWord()
     213             : {
     214             :   // Read the next 32 bit word in backward direction
     215             :   // The input stream access is given by fData and fPosition
     216             :   
     217             :   
     218             :   //   fPosition--;
     219           0 :   Int_t iBit = fPosition * 32;
     220           0 :   Int_t iByte = iBit / 8;
     221             :   
     222             :   UInt_t word = 0;
     223           0 :   word  = fData[iByte+3]<<24;
     224           0 :   word |= fData[iByte+2]<<16;
     225           0 :   word |= fData[iByte+1]<<8;
     226           0 :   word |= fData[iByte];
     227           0 :   fPosition++;
     228             :   
     229           0 :   return word;   
     230             : }
     231             : 
     232             : //_____________________________________________________________________________
     233             : UInt_t AliFITRawReader::GetChannel(Int_t iTRM, Int_t iTDC, Int_t iChain, Int_t ichannel)
     234             : {
     235           0 :   return   iTRM*120 + iChain*60 + iTDC*4 +ichannel;
     236             : }

Generated by: LCOV version 1.11