minor coverity defect: added protection for self-assignment
[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()) {
64dc94d4 150 fDDLTrigger->AddRegHeader(*fRegHeader);
9d14fb2e 151 if (scalerEvent)
152 index += kRegEmptyScalerSize;
153 else
154 index += kRegEmptySize;
155 continue;
156 }
939ae4b2 157 memcpy(fRegHeader->GetHeader(), &buffer[index], kRegHeaderSize*4);
158 index += kRegHeaderSize;
159
160 fDDLTrigger->AddRegHeader(*fRegHeader);
161 // 11 regional scaler word
162 if(scalerEvent) {
163 memcpy(fRegHeader->GetScalers(), &buffer[index], fRegHeader->GetScalerLength()*4);
164 index += fRegHeader->GetScalerLength();
165 }
166
1db7b71c 167 if (buffer[index++] != fRegHeader->GetEndOfReg()) {
1ed3c5c2 168
96a8629f 169 const Char_t* msg = Form("Wrong end of Regional word %x instead of %x\n",
170 buffer[index-1], fRegHeader->GetEndOfReg());
171 if (fWarnings) AliWarning(msg);
172 AddErrorMessage(msg);
1db7b71c 173 fRegEoWErrors++;
174 }
939ae4b2 175 // 16 local cards per regional board
176 for (Int_t iLoc = 0; iLoc < fMaxLoc; iLoc++) { //loop over local card
177
178 Int_t dataSize = fLocalStruct->GetLength();;
179
180 // 5 word trigger information
181 memcpy(fLocalStruct->GetData(), &buffer[index], dataSize*4);
182 index += dataSize;
183
184 // 45 regional scaler word
185 if(scalerEvent) {
186 memcpy(fLocalStruct->GetScalers(), &buffer[index], fLocalStruct->GetScalerLength()*4);
187 index += fLocalStruct->GetScalerLength();
188 }
189
1db7b71c 190 if (buffer[index++] != fLocalStruct->GetEndOfLocal()) {
1ed3c5c2 191
96a8629f 192 const Char_t* msg = Form("Wrong end of Local word %x instead of %x\n",
193 buffer[index-1], fLocalStruct->GetEndOfLocal());
194
195 if (fWarnings) AliWarning(msg);
196 AddErrorMessage(msg);
1db7b71c 197 fLocalEoWErrors++;
198 }
5a92f8e6 199 // fill only if card notified
200 if (fLocalStruct->GetData(0) == fLocalStruct->GetDisableWord())
201 continue;
202
939ae4b2 203 fDDLTrigger->AddLocStruct(*fLocalStruct, iReg);
204
205 } // local card loop
206
207 } // regional card loop
208
209
210 return kTRUE;
211}
212
213//______________________________________________________
214void AliMUONPayloadTrigger::ResetDDL()
215{
00e86732 216 /// reseting TClonesArray
217 /// after each DDL
218 ///
939ae4b2 219 AliMUONDarcHeader* darcHeader = fDDLTrigger->GetDarcHeader();
220 darcHeader->GetRegHeaderArray()->Delete();
1db7b71c 221 fDarcEoWErrors = 0;
222 fGlobalEoWErrors = 0;
223 fRegEoWErrors = 0;
224 fLocalEoWErrors = 0;
939ae4b2 225}
226
227//______________________________________________________
228void AliMUONPayloadTrigger::SetMaxReg(Int_t reg)
229{
00e86732 230 /// set regional card number
939ae4b2 231 if (reg > 8) reg = 8;
2470870a 232 fMaxReg = reg;
233
234 fNofRegSet = kTRUE;
939ae4b2 235}
236
237//______________________________________________________
238void AliMUONPayloadTrigger::SetMaxLoc(Int_t loc)
239{
00e86732 240 /// set local card number
939ae4b2 241 if (loc > 16) loc = 16;
242 fMaxLoc = loc;
243}
96a8629f 244
245//______________________________________________________
246void AliMUONPayloadTrigger::AddErrorMessage(const Char_t* msg)
247{
248/// adding message to logger
249
250 TString tmp(msg);
251
252 Int_t pos = tmp.First("\n");
253 tmp[pos] = 0;
254
255 fLog->Log(tmp.Data());
256}
257