VZERO reconstruction starting from raw-data input. New AliVZERORawStream class for...
[u/mrichter/AliRoot.git] / VZERO / AliVZERORawStream.cxx
CommitLineData
2eb38194 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/// This is a class for reading the VZERO DDL raw data
19/// The format of the raw data corresponds to the one
20/// implemented in AliVZEROBuffer class.
21///
22///////////////////////////////////////////////////////////////////////////////
23
24#include "AliVZERORawStream.h"
25#include "AliRawReader.h"
26#include "AliLog.h"
27#include "AliDAQ.h"
28
29ClassImp(AliVZERORawStream)
30
31//_____________________________________________________________________________
32AliVZERORawStream::AliVZERORawStream(AliRawReader* rawReader) :
33 fCell(-1),
34 fADC(-1),
35 fTime(-1),
36 fPosition(-1),
37 fRawReader(rawReader),
38 fData(NULL)
39{
40 // create an object to read VZERO raw data
41 //
42 // select the raw data corresponding to
43 // the VZERO detector id
44 fRawReader->Reset();
45 AliDebug(1,Form("Selecting raw data for detector %d",AliDAQ::DetectorID("VZERO")));
46 fRawReader->Select("VZERO");
47}
48
49//_____________________________________________________________________________
50AliVZERORawStream::~AliVZERORawStream()
51{
52 // destructor
53}
54
55//_____________________________________________________________________________
56void AliVZERORawStream::Reset()
57{
58 // reset raw stream params
59
60 fCell = fADC = fTime = fPosition = -1;
61
62 if (fRawReader) fRawReader->Reset();
63}
64
65//_____________________________________________________________________________
66Bool_t AliVZERORawStream::Next()
67{
68 // read next digit from the VZERO raw data stream
69 // return kFALSE in case of error or no digits left
70
71 if (fPosition < 0) {
72 if (!fRawReader->ReadNextData(fData)) return kFALSE;
73 if (fRawReader->GetDataSize()%3 != 0) {
74 fRawReader->AddFatalErrorLog(kRawDataSizeErr,Form("size %d != n*12",fRawReader->GetDataSize()));
75 AliWarning(Form("Wrong VZERO raw data size: %d, expected n*12 bytes!",fRawReader->GetDataSize()));
76 return kFALSE;
77 }
78 fPosition = 0;
79 }
80
81 if (fPosition >= fRawReader->GetDataSize()) return kFALSE;
82
83 fCell = GetNextWord();
84 fADC = GetNextWord();
85 fTime = GetNextWord();
86
87 return kTRUE;
88}
89
90//_____________________________________________________________________________
91Int_t AliVZERORawStream::GetNextWord()
92{
93 // This method returns the next 32 bit word
94 // inside the raw data payload.
95 // The method is supposed to be endian (platform)
96 // independent.
97 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
98
99 Int_t word = 0;
100 word |= fData[fPosition++];
101 word |= fData[fPosition++] << 8;
102 word |= fData[fPosition++] << 16;
103 word |= fData[fPosition++] << 24;
104
105 return word;
106}