ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  Reads ACORDE DDL raw data from raw data stream                           //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include "AliACORDERawStream.h"
#include "AliRawReader.h"
#include "AliLog.h"
#include "AliDAQ.h"
#include "AliRawReaderRoot.h"

ClassImp(AliACORDERawStream)

//_____________________________________________________________________________
AliACORDERawStream::AliACORDERawStream(AliRawReader* rawReader) :
  fRawReader(rawReader),
  fPosition(-1),
  fData(NULL),
  fDataSize(0)
{
  //
  // Create an object to read ACORDE raw data
  //
  // Created:      04 Feb 2008  Mario Sitta
  //

  fWord[0] = fWord[1] = fWord[2] = fWord[3] = 0;

  // Select the raw data corresponding to the ACORDE detector id
//  fRawReader->Reset();
  AliDebug(1,Form("Selecting raw data for detector %d",AliDAQ::DetectorID("ACORDE")));
  fRawReader->Select("ACORDE");

}

//_____________________________________________________________________________
AliACORDERawStream::AliACORDERawStream(const AliACORDERawStream &r) :
  TObject(),
  fRawReader(r.fRawReader),
  fPosition(-1),
  fData(NULL),
  fDataSize(0)
{
  // Simple copy constructor
  ((AliACORDERawStream &) r).Copy(*this);
}

//_____________________________________________________________________________
AliACORDERawStream::~AliACORDERawStream()
{
  // Default destructor
}

//_____________________________________________________________________________
AliACORDERawStream &AliACORDERawStream::operator=(const AliACORDERawStream &r)
{
  // Simple operator=
  if (this != &r)  ((AliACORDERawStream &) r).Copy(*this);
  return *this;
}

//_____________________________________________________________________________
void AliACORDERawStream::Reset()
{
  //
  // Reset the raw stream parameters
  //
  // Input:
  //
  // Output:
  //
  // Created:      04 Feb 2008  Mario Sitta
  //

  fPosition = -1;
  fData = NULL;

  if (fRawReader) fRawReader->Reset();
}

//_____________________________________________________________________________
Bool_t AliACORDERawStream::Next()
{
  //
  // Read next digit from the ACORDE raw data stream;
  // return kFALSE in case of error or no digits left
  //
  // Input:
  //
  // Output:
  //
  // Created:      04 Feb 2008  Mario Sitta
  //

  if (fPosition >= 0) return kFALSE;

  if (!fRawReader->ReadNextData(fData)) return kFALSE;
  if (fRawReader->GetDataSize() == 0) return kFALSE;

  fDataSize = fRawReader->GetDataSize();
  if (fDataSize != 16) {
    fRawReader->AddFatalErrorLog(kRawDataSizeErr,Form("size %d != 16",fDataSize));
    AliWarning(Form("Wrong ACORDE raw data size: %d, expected 16 bytes!",fDataSize));
    return kFALSE;
  }

  fPosition = 0;

  for (Int_t i=0; i<4; i++)
    fWord[i] = GetNextWord();

  return kTRUE;
}

//_____________________________________________________________________________
UInt_t AliACORDERawStream::GetWord(Int_t index) const
{
  //
  // Returns the ``index'' word from ACORDE raw data.
  //
  // Input:
  //         index : the index of the requested word
  // Output:
  //         word  : the 32 bit ``index'' word
  //
  // Created:      12 Feb 2008  Mario Sitta
  //

  if (index < 0 || index > 3) {
    AliWarning(Form("Wrong word index %d, returning 0",index));
    return 0;
  } else {
    return fWord[index];
  }
  
}

//_____________________________________________________________________________
UInt_t AliACORDERawStream::GetNextWord()
{
  //
  // Returns the next 32 bit word inside the raw data payload.
  // The method is supposed to be endian (platform) independent.
  //
  // Input:
  //
  // Output:
  //         word : a 32 bit word containing the data
  //
  // Created:      04 Feb 2008  Mario Sitta
  //

  if (!fData || fPosition < 0)
    AliFatal("Raw data payload buffer is not yet initialized !");

  UInt_t word = 0;
  word |= fData[fPosition++];
  word |= fData[fPosition++] << 8;
  word |= fData[fPosition++] << 16;
  word |= fData[fPosition++] << 24;

  return word;
}

//_____________________________________________________________________________

Int_t AliACORDERawStream::GetNEvents(char* fileName) 
{
	// Returns the Total Number of Events recorded by ACORDE 
	// Note: it may be a better way to do it !!
	// Input: fileName to Analyze
	// Output: Number of Total Events (fNEvents) in fileName
	// Created: 25 March 2008
	// Author: Mario Rodriguez Cahuantzi <mrodrigu@mail.cern.ch>
	
	AliRawReader* rCount = new AliRawReaderRoot(fileName);
	Int_t DyM=0;
	Int_t fNEvents=0;
	while(DyM==0)
  	{
  	if (!rCount->NextEvent()) DyM=1;
	else fNEvents++;
  	}
	delete rCount;
	return fNEvents;
}

//____________________________________________________________________________
 AliACORDERawStream.cxx:1
 AliACORDERawStream.cxx:2
 AliACORDERawStream.cxx:3
 AliACORDERawStream.cxx:4
 AliACORDERawStream.cxx:5
 AliACORDERawStream.cxx:6
 AliACORDERawStream.cxx:7
 AliACORDERawStream.cxx:8
 AliACORDERawStream.cxx:9
 AliACORDERawStream.cxx:10
 AliACORDERawStream.cxx:11
 AliACORDERawStream.cxx:12
 AliACORDERawStream.cxx:13
 AliACORDERawStream.cxx:14
 AliACORDERawStream.cxx:15
 AliACORDERawStream.cxx:16
 AliACORDERawStream.cxx:17
 AliACORDERawStream.cxx:18
 AliACORDERawStream.cxx:19
 AliACORDERawStream.cxx:20
 AliACORDERawStream.cxx:21
 AliACORDERawStream.cxx:22
 AliACORDERawStream.cxx:23
 AliACORDERawStream.cxx:24
 AliACORDERawStream.cxx:25
 AliACORDERawStream.cxx:26
 AliACORDERawStream.cxx:27
 AliACORDERawStream.cxx:28
 AliACORDERawStream.cxx:29
 AliACORDERawStream.cxx:30
 AliACORDERawStream.cxx:31
 AliACORDERawStream.cxx:32
 AliACORDERawStream.cxx:33
 AliACORDERawStream.cxx:34
 AliACORDERawStream.cxx:35
 AliACORDERawStream.cxx:36
 AliACORDERawStream.cxx:37
 AliACORDERawStream.cxx:38
 AliACORDERawStream.cxx:39
 AliACORDERawStream.cxx:40
 AliACORDERawStream.cxx:41
 AliACORDERawStream.cxx:42
 AliACORDERawStream.cxx:43
 AliACORDERawStream.cxx:44
 AliACORDERawStream.cxx:45
 AliACORDERawStream.cxx:46
 AliACORDERawStream.cxx:47
 AliACORDERawStream.cxx:48
 AliACORDERawStream.cxx:49
 AliACORDERawStream.cxx:50
 AliACORDERawStream.cxx:51
 AliACORDERawStream.cxx:52
 AliACORDERawStream.cxx:53
 AliACORDERawStream.cxx:54
 AliACORDERawStream.cxx:55
 AliACORDERawStream.cxx:56
 AliACORDERawStream.cxx:57
 AliACORDERawStream.cxx:58
 AliACORDERawStream.cxx:59
 AliACORDERawStream.cxx:60
 AliACORDERawStream.cxx:61
 AliACORDERawStream.cxx:62
 AliACORDERawStream.cxx:63
 AliACORDERawStream.cxx:64
 AliACORDERawStream.cxx:65
 AliACORDERawStream.cxx:66
 AliACORDERawStream.cxx:67
 AliACORDERawStream.cxx:68
 AliACORDERawStream.cxx:69
 AliACORDERawStream.cxx:70
 AliACORDERawStream.cxx:71
 AliACORDERawStream.cxx:72
 AliACORDERawStream.cxx:73
 AliACORDERawStream.cxx:74
 AliACORDERawStream.cxx:75
 AliACORDERawStream.cxx:76
 AliACORDERawStream.cxx:77
 AliACORDERawStream.cxx:78
 AliACORDERawStream.cxx:79
 AliACORDERawStream.cxx:80
 AliACORDERawStream.cxx:81
 AliACORDERawStream.cxx:82
 AliACORDERawStream.cxx:83
 AliACORDERawStream.cxx:84
 AliACORDERawStream.cxx:85
 AliACORDERawStream.cxx:86
 AliACORDERawStream.cxx:87
 AliACORDERawStream.cxx:88
 AliACORDERawStream.cxx:89
 AliACORDERawStream.cxx:90
 AliACORDERawStream.cxx:91
 AliACORDERawStream.cxx:92
 AliACORDERawStream.cxx:93
 AliACORDERawStream.cxx:94
 AliACORDERawStream.cxx:95
 AliACORDERawStream.cxx:96
 AliACORDERawStream.cxx:97
 AliACORDERawStream.cxx:98
 AliACORDERawStream.cxx:99
 AliACORDERawStream.cxx:100
 AliACORDERawStream.cxx:101
 AliACORDERawStream.cxx:102
 AliACORDERawStream.cxx:103
 AliACORDERawStream.cxx:104
 AliACORDERawStream.cxx:105
 AliACORDERawStream.cxx:106
 AliACORDERawStream.cxx:107
 AliACORDERawStream.cxx:108
 AliACORDERawStream.cxx:109
 AliACORDERawStream.cxx:110
 AliACORDERawStream.cxx:111
 AliACORDERawStream.cxx:112
 AliACORDERawStream.cxx:113
 AliACORDERawStream.cxx:114
 AliACORDERawStream.cxx:115
 AliACORDERawStream.cxx:116
 AliACORDERawStream.cxx:117
 AliACORDERawStream.cxx:118
 AliACORDERawStream.cxx:119
 AliACORDERawStream.cxx:120
 AliACORDERawStream.cxx:121
 AliACORDERawStream.cxx:122
 AliACORDERawStream.cxx:123
 AliACORDERawStream.cxx:124
 AliACORDERawStream.cxx:125
 AliACORDERawStream.cxx:126
 AliACORDERawStream.cxx:127
 AliACORDERawStream.cxx:128
 AliACORDERawStream.cxx:129
 AliACORDERawStream.cxx:130
 AliACORDERawStream.cxx:131
 AliACORDERawStream.cxx:132
 AliACORDERawStream.cxx:133
 AliACORDERawStream.cxx:134
 AliACORDERawStream.cxx:135
 AliACORDERawStream.cxx:136
 AliACORDERawStream.cxx:137
 AliACORDERawStream.cxx:138
 AliACORDERawStream.cxx:139
 AliACORDERawStream.cxx:140
 AliACORDERawStream.cxx:141
 AliACORDERawStream.cxx:142
 AliACORDERawStream.cxx:143
 AliACORDERawStream.cxx:144
 AliACORDERawStream.cxx:145
 AliACORDERawStream.cxx:146
 AliACORDERawStream.cxx:147
 AliACORDERawStream.cxx:148
 AliACORDERawStream.cxx:149
 AliACORDERawStream.cxx:150
 AliACORDERawStream.cxx:151
 AliACORDERawStream.cxx:152
 AliACORDERawStream.cxx:153
 AliACORDERawStream.cxx:154
 AliACORDERawStream.cxx:155
 AliACORDERawStream.cxx:156
 AliACORDERawStream.cxx:157
 AliACORDERawStream.cxx:158
 AliACORDERawStream.cxx:159
 AliACORDERawStream.cxx:160
 AliACORDERawStream.cxx:161
 AliACORDERawStream.cxx:162
 AliACORDERawStream.cxx:163
 AliACORDERawStream.cxx:164
 AliACORDERawStream.cxx:165
 AliACORDERawStream.cxx:166
 AliACORDERawStream.cxx:167
 AliACORDERawStream.cxx:168
 AliACORDERawStream.cxx:169
 AliACORDERawStream.cxx:170
 AliACORDERawStream.cxx:171
 AliACORDERawStream.cxx:172
 AliACORDERawStream.cxx:173
 AliACORDERawStream.cxx:174
 AliACORDERawStream.cxx:175
 AliACORDERawStream.cxx:176
 AliACORDERawStream.cxx:177
 AliACORDERawStream.cxx:178
 AliACORDERawStream.cxx:179
 AliACORDERawStream.cxx:180
 AliACORDERawStream.cxx:181
 AliACORDERawStream.cxx:182
 AliACORDERawStream.cxx:183
 AliACORDERawStream.cxx:184
 AliACORDERawStream.cxx:185
 AliACORDERawStream.cxx:186
 AliACORDERawStream.cxx:187
 AliACORDERawStream.cxx:188
 AliACORDERawStream.cxx:189
 AliACORDERawStream.cxx:190
 AliACORDERawStream.cxx:191
 AliACORDERawStream.cxx:192
 AliACORDERawStream.cxx:193
 AliACORDERawStream.cxx:194
 AliACORDERawStream.cxx:195
 AliACORDERawStream.cxx:196
 AliACORDERawStream.cxx:197
 AliACORDERawStream.cxx:198
 AliACORDERawStream.cxx:199
 AliACORDERawStream.cxx:200
 AliACORDERawStream.cxx:201
 AliACORDERawStream.cxx:202
 AliACORDERawStream.cxx:203
 AliACORDERawStream.cxx:204