]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliCTPRawStream.cxx
Compilation on Windoiws/Cygwin
[u/mrichter/AliRoot.git] / STEER / AliCTPRawStream.cxx
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 class provides access to CTP DDL raw data.
19 ///
20 /// The raw data format is taken form the trigger TDR.
21 /// The meaning of the trigger class and cluster masks
22 /// are given in the trigger description file (in /data)
23 /// and in the AliCentralTrigger class.
24 ///
25 ///////////////////////////////////////////////////////////////////////////////
26
27 #include "AliCTPRawStream.h"
28 #include "AliRawReader.h"
29 #include "AliLog.h"
30 #include "AliDAQ.h"
31 #include "AliTriggerIR.h"
32
33 ClassImp(AliCTPRawStream)
34
35 //_____________________________________________________________________________
36 AliCTPRawStream::AliCTPRawStream(AliRawReader* rawReader) :
37   fIRArray("AliTriggerIR",3),
38   fOrbit(0),
39   fBC(0),
40   fL0TriggerInputs(0),
41   fL1TriggerInputs(0),
42   fL2TriggerInputs(0),
43   fClassMask(0),
44   fClusterMask(0),
45   fRawReader(rawReader)
46 {
47   // create an object to read CTP raw data
48   //
49   // select the raw data corresponding to
50   // the CTP detector id
51   fRawReader->Reset();
52   AliDebug(1,Form("Selecting raw data for detector %d",AliDAQ::DetectorID("TRG")));
53   fRawReader->Select("TRG");
54 }
55
56 //_____________________________________________________________________________
57 AliCTPRawStream::AliCTPRawStream(const AliCTPRawStream& stream) :
58   TObject(stream),
59   fIRArray("AliTriggerIR",3),
60   fOrbit(0),
61   fBC(0),
62   fL0TriggerInputs(0),
63   fL1TriggerInputs(0),
64   fL2TriggerInputs(0),
65   fClassMask(0),
66   fClusterMask(0),
67   fRawReader(NULL)
68 {
69   // Copy constructor
70   AliFatal("Copy constructor not implemented");
71 }
72
73 //_____________________________________________________________________________
74 AliCTPRawStream& AliCTPRawStream::operator = (const AliCTPRawStream& 
75                                               /* stream */)
76 {
77   AliFatal("Assignment operator not implemented");
78   return *this;
79 }
80
81 //_____________________________________________________________________________
82 AliCTPRawStream::~AliCTPRawStream()
83 {
84   // destructor
85   fIRArray.Delete();
86 }
87
88 //_____________________________________________________________________________
89 void AliCTPRawStream::Reset()
90 {
91   // reset raw stream params
92   fIRArray.Clear();
93
94   fClassMask = fClusterMask = 0;
95
96   if (fRawReader) fRawReader->Reset();
97 }
98
99 //_____________________________________________________________________________
100 Bool_t AliCTPRawStream::Next()
101 {
102   // read the whole CTP raw data stream
103   // return kFALSE in case of error
104
105   UChar_t *data = NULL;
106
107   // CTP raw data does not contain CDH
108   fRawReader->RequireHeader(kFALSE);
109
110   if (!fRawReader->ReadNextData(data)) {
111     fRawReader->RequireHeader(kTRUE);
112     return kFALSE;
113   }
114
115   if ((fRawReader->GetDataSize()) < 32 ||
116       ((fRawReader->GetDataSize() % 4) != 0)) {
117     AliError(Form("Wrong CTP raw data size: %d",fRawReader->GetDataSize()));
118     fRawReader->RequireHeader(kTRUE);
119     return kFALSE;
120   }
121
122   fBC = data[0];
123   fBC |= (data[1] & 0xF) << 8;
124
125   fOrbit = data[4] << 12;
126   fOrbit |= (data[5] & 0xF) << 20;
127   fOrbit |= data[8];
128   fOrbit |= (data[9] & 0xF) << 8;
129
130   fClusterMask = data[12] >> 2;
131
132   fClassMask =  ((ULong64_t)data[12] & 0x3) << 48;
133
134   fClassMask |= (ULong64_t)data[16] << 36;
135   fClassMask |= ((ULong64_t)data[17] & 0xF) << 44;
136
137   fClassMask |= (ULong64_t)data[20] << 24;
138   fClassMask |= ((ULong64_t)data[21] & 0xF) << 32;
139
140   fClassMask |= (ULong64_t)data[24] << 12;
141   fClassMask |= ((ULong64_t)data[25] & 0xF) << 20;
142
143   fClassMask |= (ULong64_t)data[28];
144   fClassMask |= ((ULong64_t)data[29] & 0xF) << 8;
145
146   if (fRawReader->GetDataSize() == 32) {
147     AliDebug(1,"No trigger input and interaction records found");
148     fRawReader->RequireHeader(kTRUE);
149     return kTRUE;
150   }
151
152   // Read detector trigger inputs
153   if (fRawReader->GetDataSize() < 52) {
154     AliError(Form("Wrong CTP raw data size: %d",fRawReader->GetDataSize()));
155     fRawReader->RequireHeader(kTRUE);
156     return kFALSE;
157   }
158
159   fL0TriggerInputs = data[32] << 12;
160   fL0TriggerInputs |= (data[33] & 0xF) << 20;
161   fL0TriggerInputs |= data[36];
162   fL0TriggerInputs |= (data[37] & 0xF) << 8;
163
164   fL1TriggerInputs = data[40] << 12;
165   fL1TriggerInputs |= (data[41] & 0xF) << 20;
166   fL1TriggerInputs |= data[44];
167   fL1TriggerInputs |= (data[45] & 0xF) << 8;
168
169   fL2TriggerInputs = data[48] << 12;
170   fL2TriggerInputs |= (data[49] & 0xF) << 20;
171
172   if (fRawReader->GetDataSize() == 52) {
173     AliDebug(1,"No interaction records found");
174     fRawReader->RequireHeader(kTRUE);
175     return kFALSE;
176   }
177
178   // Read IRs
179   Int_t iword = 52;
180   UChar_t level = 0;
181   UInt_t *irdata = NULL;
182   UInt_t irsize = 0;
183   UInt_t orbit = 0;
184   Bool_t incomplete = kFALSE, transerr = kFALSE;
185   while (iword < fRawReader->GetDataSize()) {
186     if (data[iword+1] & 0x80) {
187       UChar_t flag = ((data[iword+1] >> 4) & 0x3);
188       if (flag == 0) {
189         if (irdata) {
190           new (fIRArray[fIRArray.GetEntriesFast()])
191             AliTriggerIR(orbit,irsize,irdata,incomplete,transerr);
192           irdata = NULL; irsize = 0;
193         }
194         level = 1;
195         orbit = data[iword] << 12;
196         orbit |= (data[iword+1] & 0xF) << 20;
197         transerr = ((data[iword+1] >> 6) & 0x1);
198         iword += 4;
199         continue;
200       }
201       else if (flag == 3) {
202         if (level == 1) {
203           level = 2;
204           orbit |= data[iword];
205           orbit |= ((data[iword+1] & 0xF) << 8);
206           iword += 4;
207           continue;
208         }
209       }
210       UShort_t bc = data[iword];
211       bc |= ((data[iword] & 0xF) << 8);
212       if (bc == 0xFFF) {
213         incomplete = kTRUE;
214       }
215       else {
216         if (level == 2) {
217           level = 3;
218           irdata = (UInt_t *)&data[iword];
219           irsize = 0;
220         }
221         if (level == 3) {
222           irsize++;
223         }
224       }
225     }
226     else
227       AliWarning(Form("Invalid interaction record (%d %d)",iword,fRawReader->GetDataSize()));
228
229     iword += 4;
230   }
231
232   if (irdata) {
233     new (fIRArray[fIRArray.GetEntriesFast()])
234       AliTriggerIR(orbit,irsize,irdata,incomplete,transerr);
235     irdata = NULL; irsize = 0;
236   }
237
238   // Restore the raw-reader state!!
239   fRawReader->RequireHeader(kTRUE);
240
241   return kTRUE;
242 }
243