LCOV - code coverage report
Current view: top level - ACORDE/ACORDEbase - AliACORDERawStream.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 32 59 54.2 %
Date: 2016-06-14 17:26:59 Functions: 8 14 57.1 %

          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             : ///////////////////////////////////////////////////////////////////////////////
      17             : //                                                                           //
      18             : //  Reads ACORDE DDL raw data from raw data stream                           //
      19             : //                                                                           //
      20             : ///////////////////////////////////////////////////////////////////////////////
      21             : 
      22             : #include "AliACORDERawStream.h"
      23             : #include "AliRawReader.h"
      24             : #include "AliLog.h"
      25             : #include "AliDAQ.h"
      26             : #include "AliRawReaderRoot.h"
      27             : 
      28          12 : ClassImp(AliACORDERawStream)
      29             : 
      30             : //_____________________________________________________________________________
      31           4 : AliACORDERawStream::AliACORDERawStream(AliRawReader* rawReader) :
      32           4 :   fRawReader(rawReader),
      33           4 :   fPosition(-1),
      34           4 :   fData(NULL),
      35           4 :   fDataSize(0)
      36          20 : {
      37             :   //
      38             :   // Create an object to read ACORDE raw data
      39             :   //
      40             :   // Created:      04 Feb 2008  Mario Sitta
      41             :   //
      42             : 
      43           4 :   fWord[0] = fWord[1] = fWord[2] = fWord[3] = 0;
      44             : 
      45             :   // Select the raw data corresponding to the ACORDE detector id
      46             : //  fRawReader->Reset();
      47          20 :   AliDebug(1,Form("Selecting raw data for detector %d",AliDAQ::DetectorID("ACORDE")));
      48           4 :   fRawReader->Select("ACORDE");
      49             : 
      50           8 : }
      51             : 
      52             : //_____________________________________________________________________________
      53             : AliACORDERawStream::AliACORDERawStream(const AliACORDERawStream &r) :
      54           0 :   TObject(),
      55           0 :   fRawReader(r.fRawReader),
      56           0 :   fPosition(-1),
      57           0 :   fData(NULL),
      58           0 :   fDataSize(0)
      59           0 : {
      60             :   // Simple copy constructor
      61           0 :   ((AliACORDERawStream &) r).Copy(*this);
      62           0 : }
      63             : 
      64             : //_____________________________________________________________________________
      65             : AliACORDERawStream::~AliACORDERawStream()
      66           8 : {
      67             :   // Default destructor
      68          12 : }
      69             : 
      70             : //_____________________________________________________________________________
      71             : AliACORDERawStream &AliACORDERawStream::operator=(const AliACORDERawStream &r)
      72             : {
      73             :   // Simple operator=
      74           0 :   if (this != &r)  ((AliACORDERawStream &) r).Copy(*this);
      75           0 :   return *this;
      76             : }
      77             : 
      78             : //_____________________________________________________________________________
      79             : void AliACORDERawStream::Reset()
      80             : {
      81             :   //
      82             :   // Reset the raw stream parameters
      83             :   //
      84             :   // Input:
      85             :   //
      86             :   // Output:
      87             :   //
      88             :   // Created:      04 Feb 2008  Mario Sitta
      89             :   //
      90             : 
      91           0 :   fPosition = -1;
      92           0 :   fData = NULL;
      93             : 
      94           0 :   if (fRawReader) fRawReader->Reset();
      95           0 : }
      96             : 
      97             : //_____________________________________________________________________________
      98             : Bool_t AliACORDERawStream::Next()
      99             : {
     100             :   //
     101             :   // Read next digit from the ACORDE raw data stream;
     102             :   // return kFALSE in case of error or no digits left
     103             :   //
     104             :   // Input:
     105             :   //
     106             :   // Output:
     107             :   //
     108             :   // Created:      04 Feb 2008  Mario Sitta
     109             :   //
     110             : 
     111           8 :   if (fPosition >= 0) return kFALSE;
     112             : 
     113           4 :   if (!fRawReader->ReadNextData(fData)) return kFALSE;
     114           4 :   if (fRawReader->GetDataSize() == 0) return kFALSE;
     115             : 
     116           4 :   fDataSize = fRawReader->GetDataSize();
     117           4 :   if (fDataSize != 16) {
     118           0 :     fRawReader->AddFatalErrorLog(kRawDataSizeErr,Form("size %d != 16",fDataSize));
     119           0 :     AliWarning(Form("Wrong ACORDE raw data size: %d, expected 16 bytes!",fDataSize));
     120           0 :     return kFALSE;
     121             :   }
     122             : 
     123           4 :   fPosition = 0;
     124             : 
     125          40 :   for (Int_t i=0; i<4; i++)
     126          16 :     fWord[i] = GetNextWord();
     127             : 
     128           4 :   return kTRUE;
     129           4 : }
     130             : 
     131             : //_____________________________________________________________________________
     132             : UInt_t AliACORDERawStream::GetWord(Int_t index) const
     133             : {
     134             :   //
     135             :   // Returns the ``index'' word from ACORDE raw data.
     136             :   //
     137             :   // Input:
     138             :   //         index : the index of the requested word
     139             :   // Output:
     140             :   //         word  : the 32 bit ``index'' word
     141             :   //
     142             :   // Created:      12 Feb 2008  Mario Sitta
     143             :   //
     144             : 
     145         480 :   if (index < 0 || index > 3) {
     146           0 :     AliWarning(Form("Wrong word index %d, returning 0",index));
     147           0 :     return 0;
     148             :   } else {
     149         240 :     return fWord[index];
     150             :   }
     151             :   
     152         240 : }
     153             : 
     154             : //_____________________________________________________________________________
     155             : UInt_t AliACORDERawStream::GetNextWord()
     156             : {
     157             :   //
     158             :   // Returns the next 32 bit word inside the raw data payload.
     159             :   // The method is supposed to be endian (platform) independent.
     160             :   //
     161             :   // Input:
     162             :   //
     163             :   // Output:
     164             :   //         word : a 32 bit word containing the data
     165             :   //
     166             :   // Created:      04 Feb 2008  Mario Sitta
     167             :   //
     168             : 
     169          48 :   if (!fData || fPosition < 0)
     170           0 :     AliFatal("Raw data payload buffer is not yet initialized !");
     171             : 
     172             :   UInt_t word = 0;
     173          16 :   word |= fData[fPosition++];
     174          16 :   word |= fData[fPosition++] << 8;
     175          16 :   word |= fData[fPosition++] << 16;
     176          16 :   word |= fData[fPosition++] << 24;
     177             : 
     178          16 :   return word;
     179             : }
     180             : 
     181             : //_____________________________________________________________________________
     182             : 
     183             : Int_t AliACORDERawStream::GetNEvents(char* fileName) 
     184             : {
     185             :         // Returns the Total Number of Events recorded by ACORDE 
     186             :         // Note: it may be a better way to do it !!
     187             :         // Input: fileName to Analyze
     188             :         // Output: Number of Total Events (fNEvents) in fileName
     189             :         // Created: 25 March 2008
     190             :         // Author: Mario Rodriguez Cahuantzi <mrodrigu@mail.cern.ch>
     191             :         
     192           0 :         AliRawReader* rCount = new AliRawReaderRoot(fileName);
     193             :         Int_t DyM=0;
     194             :         Int_t fNEvents=0;
     195           0 :         while(DyM==0)
     196             :         {
     197           0 :         if (!rCount->NextEvent()) DyM=1;
     198           0 :         else fNEvents++;
     199             :         }
     200           0 :         delete rCount;
     201           0 :         return fNEvents;
     202           0 : }
     203             : 
     204             : //____________________________________________________________________________

Generated by: LCOV version 1.11