]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPayloadTrigger.cxx
bug fixed
[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),
2470870a 55 fWarnings(kTRUE),
56 fNofRegSet(kFALSE)
939ae4b2 57{
00e86732 58 ///
59 /// create an object to read MUON raw digits
60 /// Default ctor for monitoring purposes
61 ///
939ae4b2 62
939ae4b2 63}
64
65//___________________________________
66AliMUONPayloadTrigger::~AliMUONPayloadTrigger()
67{
00e86732 68 ///
69 /// clean up
70 ///
939ae4b2 71 delete fDDLTrigger;
72 delete fLocalStruct;
73 delete fRegHeader;
96a8629f 74 delete fLog;
939ae4b2 75}
76
77
78//______________________________________________________
f4ee80d2 79Bool_t AliMUONPayloadTrigger::Decode(UInt_t *buffer, Bool_t scalerEvent)
939ae4b2 80{
00e86732 81 /// decode trigger DDL
5a92f8e6 82 /// store only notified cards
939ae4b2 83
84 // reading DDL for trigger
85
86 AliMUONDarcHeader* darcHeader = fDDLTrigger->GetDarcHeader();
87
9d14fb2e 88 static Int_t kGlobalHeaderSize = darcHeader->GetGlobalHeaderLength();
89 static Int_t kDarcHeaderSize = darcHeader->GetDarcHeaderLength();
90 static Int_t kRegHeaderSize = fRegHeader->GetHeaderLength();
91 static Int_t kRegEmptySize = fRegHeader->GetHeaderLength()+1 + 16*(fLocalStruct->GetLength()+1);
92 static Int_t kRegEmptyScalerSize = fRegHeader->GetHeaderLength() + fRegHeader->GetScalerLength() + 1 +
93 16*(fLocalStruct->GetLength() + fLocalStruct->GetScalerLength() + 1);
94
939ae4b2 95 Int_t index = 0;
18d3ded7 96
97 memcpy(darcHeader->GetHeader(), &buffer[index], (kDarcHeaderSize)*4);
98 index += kDarcHeaderSize;
939ae4b2 99
f4ee80d2 100
9d14fb2e 101 // darc type vadorh
102 if (darcHeader->GetDarcType() == darcHeader->GetDarcVadohrType())
2470870a 103 fMaxReg = 1;
104
f4ee80d2 105 // darc type def.
9d14fb2e 106 if (darcHeader->GetDarcType() == darcHeader->GetDarcDefaultType())
2470870a 107 fMaxReg = 8;
108
f4ee80d2 109 if(darcHeader->GetEventType() == scalerEvent)
110 if (fWarnings) AliWarning("Wrong event type obtained from the Darc header, take the one of CDH");
111
5b36fe64 112
939ae4b2 113 if(scalerEvent) {
114 // 6 DARC scaler words
115 memcpy(darcHeader->GetDarcScalers(), &buffer[index], darcHeader->GetDarcScalerLength()*4);
116 index += darcHeader->GetDarcScalerLength();
117 }
118
1db7b71c 119 if (buffer[index++] != darcHeader->GetEndOfDarc()) {
1ed3c5c2 120
96a8629f 121 const Char_t* msg = Form("Wrong end of Darc word %x instead of %x\n",
122 buffer[index-1], darcHeader->GetEndOfDarc());
123 if (fWarnings) AliWarning(msg);
124 AddErrorMessage(msg);
1db7b71c 125 fDarcEoWErrors++;
126 }
939ae4b2 127 // 4 words of global board input + Global board output
18d3ded7 128 memcpy(darcHeader->GetGlobalInput(), &buffer[index], (kGlobalHeaderSize)*4);
129 index += kGlobalHeaderSize;
939ae4b2 130
131 if(scalerEvent) {
132 // 10 Global scaler words
133 memcpy(darcHeader->GetGlobalScalers(), &buffer[index], darcHeader->GetGlobalScalerLength()*4);
134 index += darcHeader->GetGlobalScalerLength();
135 }
136
1db7b71c 137 if (buffer[index++] != darcHeader->GetEndOfGlobal()) {
1ed3c5c2 138
96a8629f 139 const Char_t* msg = Form("Wrong end of Global word %x instead of %x\n",
140 buffer[index-1], darcHeader->GetEndOfGlobal());
141 if (fWarnings) AliWarning(msg);
142 AddErrorMessage(msg);
1db7b71c 143 fGlobalEoWErrors++;
144 }
939ae4b2 145 // 8 regional boards
146 for (Int_t iReg = 0; iReg < fMaxReg; iReg++) { //loop over regeonal card
147
9d14fb2e 148 // skip empty regaional board (not connected or with error reading)
149 if (buffer[index] == fRegHeader->GetErrorWord()) {
150 if (scalerEvent)
151 index += kRegEmptyScalerSize;
152 else
153 index += kRegEmptySize;
154 continue;
155 }
939ae4b2 156 memcpy(fRegHeader->GetHeader(), &buffer[index], kRegHeaderSize*4);
157 index += kRegHeaderSize;
158
159 fDDLTrigger->AddRegHeader(*fRegHeader);
160 // 11 regional scaler word
161 if(scalerEvent) {
162 memcpy(fRegHeader->GetScalers(), &buffer[index], fRegHeader->GetScalerLength()*4);
163 index += fRegHeader->GetScalerLength();
164 }
165
1db7b71c 166 if (buffer[index++] != fRegHeader->GetEndOfReg()) {
1ed3c5c2 167
96a8629f 168 const Char_t* msg = Form("Wrong end of Regional word %x instead of %x\n",
169 buffer[index-1], fRegHeader->GetEndOfReg());
170 if (fWarnings) AliWarning(msg);
171 AddErrorMessage(msg);
1db7b71c 172 fRegEoWErrors++;
173 }
939ae4b2 174 // 16 local cards per regional board
175 for (Int_t iLoc = 0; iLoc < fMaxLoc; iLoc++) { //loop over local card
176
177 Int_t dataSize = fLocalStruct->GetLength();;
178
179 // 5 word trigger information
180 memcpy(fLocalStruct->GetData(), &buffer[index], dataSize*4);
181 index += dataSize;
182
183 // 45 regional scaler word
184 if(scalerEvent) {
185 memcpy(fLocalStruct->GetScalers(), &buffer[index], fLocalStruct->GetScalerLength()*4);
186 index += fLocalStruct->GetScalerLength();
187 }
188
1db7b71c 189 if (buffer[index++] != fLocalStruct->GetEndOfLocal()) {
1ed3c5c2 190
96a8629f 191 const Char_t* msg = Form("Wrong end of Local word %x instead of %x\n",
192 buffer[index-1], fLocalStruct->GetEndOfLocal());
193
194 if (fWarnings) AliWarning(msg);
195 AddErrorMessage(msg);
1db7b71c 196 fLocalEoWErrors++;
197 }
5a92f8e6 198 // fill only if card notified
199 if (fLocalStruct->GetData(0) == fLocalStruct->GetDisableWord())
200 continue;
201
939ae4b2 202 fDDLTrigger->AddLocStruct(*fLocalStruct, iReg);
203
204 } // local card loop
205
206 } // regional card loop
207
208
209 return kTRUE;
210}
211
212//______________________________________________________
213void AliMUONPayloadTrigger::ResetDDL()
214{
00e86732 215 /// reseting TClonesArray
216 /// after each DDL
217 ///
939ae4b2 218 AliMUONDarcHeader* darcHeader = fDDLTrigger->GetDarcHeader();
219 darcHeader->GetRegHeaderArray()->Delete();
1db7b71c 220 fDarcEoWErrors = 0;
221 fGlobalEoWErrors = 0;
222 fRegEoWErrors = 0;
223 fLocalEoWErrors = 0;
939ae4b2 224}
225
226//______________________________________________________
227void AliMUONPayloadTrigger::SetMaxReg(Int_t reg)
228{
00e86732 229 /// set regional card number
939ae4b2 230 if (reg > 8) reg = 8;
2470870a 231 fMaxReg = reg;
232
233 fNofRegSet = kTRUE;
939ae4b2 234}
235
236//______________________________________________________
237void AliMUONPayloadTrigger::SetMaxLoc(Int_t loc)
238{
00e86732 239 /// set local card number
939ae4b2 240 if (loc > 16) loc = 16;
241 fMaxLoc = loc;
242}
96a8629f 243
244//______________________________________________________
245void AliMUONPayloadTrigger::AddErrorMessage(const Char_t* msg)
246{
247/// adding message to logger
248
249 TString tmp(msg);
250
251 Int_t pos = tmp.First("\n");
252 tmp[pos] = 0;
253
254 fLog->Log(tmp.Data());
255}
256