Fixed a bug when retrieving info from Darc word
[u/mrichter/AliRoot.git] / MUON / AliMUONPayloadTrigger.cxx
CommitLineData
939ae4b2 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
3d1463c8 16// $Id$
939ae4b2 17
3d1463c8 18//-----------------------------------------------------------------------------
00e86732 19/// \class AliMUONPayloadTrigger
939ae4b2 20/// Class Payload
21///
22/// Decodes rawdata from buffer and stores in TClonesArray.
23///
24/// First version implement for Trigger
25///
00e86732 26/// \author Christian Finck
3d1463c8 27//-----------------------------------------------------------------------------
939ae4b2 28
29#include "AliMUONPayloadTrigger.h"
30
939ae4b2 31#include "AliMUONDarcHeader.h"
32#include "AliMUONRegHeader.h"
33#include "AliMUONLocalStruct.h"
34#include "AliMUONDDLTrigger.h"
96a8629f 35#include "AliMUONLogger.h"
939ae4b2 36
1ed3c5c2 37#include "AliLog.h"
38
00e86732 39/// \cond CLASSIMP
939ae4b2 40ClassImp(AliMUONPayloadTrigger)
00e86732 41/// \endcond
939ae4b2 42
43AliMUONPayloadTrigger::AliMUONPayloadTrigger()
44 : TObject(),
45 fMaxReg(8),
9f5dcca3 46 fMaxLoc(16),
47 fDDLTrigger(new AliMUONDDLTrigger()),
48 fRegHeader(new AliMUONRegHeader()),
1db7b71c 49 fLocalStruct(new AliMUONLocalStruct()),
96a8629f 50 fLog(new AliMUONLogger(1000)),
1db7b71c 51 fDarcEoWErrors(0),
52 fGlobalEoWErrors(0),
53 fRegEoWErrors(0),
96a8629f 54 fLocalEoWErrors(0),
55 fWarnings(kTRUE)
939ae4b2 56{
00e86732 57 ///
58 /// create an object to read MUON raw digits
59 /// Default ctor for monitoring purposes
60 ///
939ae4b2 61
939ae4b2 62}
63
64//___________________________________
65AliMUONPayloadTrigger::~AliMUONPayloadTrigger()
66{
00e86732 67 ///
68 /// clean up
69 ///
939ae4b2 70 delete fDDLTrigger;
71 delete fLocalStruct;
72 delete fRegHeader;
96a8629f 73 delete fLog;
939ae4b2 74}
75
76
77//______________________________________________________
78Bool_t AliMUONPayloadTrigger::Decode(UInt_t *buffer)
79{
00e86732 80 /// decode trigger DDL
5a92f8e6 81 /// store only notified cards
939ae4b2 82
83 // reading DDL for trigger
84
85 AliMUONDarcHeader* darcHeader = fDDLTrigger->GetDarcHeader();
86
18d3ded7 87 static Int_t kGlobalHeaderSize = darcHeader->GetGlobalHeaderLength();
88 static Int_t kDarcHeaderSize = darcHeader->GetDarcHeaderLength();
89 static Int_t kRegHeaderSize = fRegHeader->GetHeaderLength();
90
91 Bool_t scalerEvent = kFALSE;
939ae4b2 92
93 Int_t index = 0;
18d3ded7 94
95 memcpy(darcHeader->GetHeader(), &buffer[index], (kDarcHeaderSize)*4);
96 index += kDarcHeaderSize;
939ae4b2 97
d622a0ec 98 if(darcHeader->GetEventType() == 0) {
939ae4b2 99 scalerEvent = kTRUE;
100 } else
101 scalerEvent = kFALSE;
102
103 if(scalerEvent) {
104 // 6 DARC scaler words
105 memcpy(darcHeader->GetDarcScalers(), &buffer[index], darcHeader->GetDarcScalerLength()*4);
106 index += darcHeader->GetDarcScalerLength();
107 }
108
1db7b71c 109 if (buffer[index++] != darcHeader->GetEndOfDarc()) {
1ed3c5c2 110
96a8629f 111 const Char_t* msg = Form("Wrong end of Darc word %x instead of %x\n",
112 buffer[index-1], darcHeader->GetEndOfDarc());
113 if (fWarnings) AliWarning(msg);
114 AddErrorMessage(msg);
1db7b71c 115 fDarcEoWErrors++;
116 }
939ae4b2 117 // 4 words of global board input + Global board output
18d3ded7 118 memcpy(darcHeader->GetGlobalInput(), &buffer[index], (kGlobalHeaderSize)*4);
119 index += kGlobalHeaderSize;
939ae4b2 120
121 if(scalerEvent) {
122 // 10 Global scaler words
123 memcpy(darcHeader->GetGlobalScalers(), &buffer[index], darcHeader->GetGlobalScalerLength()*4);
124 index += darcHeader->GetGlobalScalerLength();
125 }
126
1db7b71c 127 if (buffer[index++] != darcHeader->GetEndOfGlobal()) {
1ed3c5c2 128
96a8629f 129 const Char_t* msg = Form("Wrong end of Global word %x instead of %x\n",
130 buffer[index-1], darcHeader->GetEndOfGlobal());
131 if (fWarnings) AliWarning(msg);
132 AddErrorMessage(msg);
1db7b71c 133 fGlobalEoWErrors++;
134 }
939ae4b2 135 // 8 regional boards
136 for (Int_t iReg = 0; iReg < fMaxReg; iReg++) { //loop over regeonal card
137
138 memcpy(fRegHeader->GetHeader(), &buffer[index], kRegHeaderSize*4);
139 index += kRegHeaderSize;
140
141 fDDLTrigger->AddRegHeader(*fRegHeader);
142 // 11 regional scaler word
143 if(scalerEvent) {
144 memcpy(fRegHeader->GetScalers(), &buffer[index], fRegHeader->GetScalerLength()*4);
145 index += fRegHeader->GetScalerLength();
146 }
147
1db7b71c 148 if (buffer[index++] != fRegHeader->GetEndOfReg()) {
1ed3c5c2 149
96a8629f 150 const Char_t* msg = Form("Wrong end of Regional word %x instead of %x\n",
151 buffer[index-1], fRegHeader->GetEndOfReg());
152 if (fWarnings) AliWarning(msg);
153 AddErrorMessage(msg);
1db7b71c 154 fRegEoWErrors++;
155 }
939ae4b2 156 // 16 local cards per regional board
157 for (Int_t iLoc = 0; iLoc < fMaxLoc; iLoc++) { //loop over local card
158
159 Int_t dataSize = fLocalStruct->GetLength();;
160
161 // 5 word trigger information
162 memcpy(fLocalStruct->GetData(), &buffer[index], dataSize*4);
163 index += dataSize;
164
165 // 45 regional scaler word
166 if(scalerEvent) {
167 memcpy(fLocalStruct->GetScalers(), &buffer[index], fLocalStruct->GetScalerLength()*4);
168 index += fLocalStruct->GetScalerLength();
169 }
170
1db7b71c 171 if (buffer[index++] != fLocalStruct->GetEndOfLocal()) {
1ed3c5c2 172
96a8629f 173 const Char_t* msg = Form("Wrong end of Local word %x instead of %x\n",
174 buffer[index-1], fLocalStruct->GetEndOfLocal());
175
176 if (fWarnings) AliWarning(msg);
177 AddErrorMessage(msg);
1db7b71c 178 fLocalEoWErrors++;
179 }
5a92f8e6 180 // fill only if card notified
181 if (fLocalStruct->GetData(0) == fLocalStruct->GetDisableWord())
182 continue;
183
939ae4b2 184 fDDLTrigger->AddLocStruct(*fLocalStruct, iReg);
185
186 } // local card loop
187
188 } // regional card loop
189
190
191 return kTRUE;
192}
193
194//______________________________________________________
195void AliMUONPayloadTrigger::ResetDDL()
196{
00e86732 197 /// reseting TClonesArray
198 /// after each DDL
199 ///
939ae4b2 200 AliMUONDarcHeader* darcHeader = fDDLTrigger->GetDarcHeader();
201 darcHeader->GetRegHeaderArray()->Delete();
1db7b71c 202 fDarcEoWErrors = 0;
203 fGlobalEoWErrors = 0;
204 fRegEoWErrors = 0;
205 fLocalEoWErrors = 0;
939ae4b2 206}
207
208//______________________________________________________
209void AliMUONPayloadTrigger::SetMaxReg(Int_t reg)
210{
00e86732 211 /// set regional card number
939ae4b2 212 if (reg > 8) reg = 8;
213 fMaxReg = reg;
214}
215
216//______________________________________________________
217void AliMUONPayloadTrigger::SetMaxLoc(Int_t loc)
218{
00e86732 219 /// set local card number
939ae4b2 220 if (loc > 16) loc = 16;
221 fMaxLoc = loc;
222}
96a8629f 223
224//______________________________________________________
225void AliMUONPayloadTrigger::AddErrorMessage(const Char_t* msg)
226{
227/// adding message to logger
228
229 TString tmp(msg);
230
231 Int_t pos = tmp.First("\n");
232 tmp[pos] = 0;
233
234 fLog->Log(tmp.Data());
235}
236