adding TPC Krypton CF to build
[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
18d3ded7 88 static Int_t kGlobalHeaderSize = darcHeader->GetGlobalHeaderLength();
89 static Int_t kDarcHeaderSize = darcHeader->GetDarcHeaderLength();
90 static Int_t kRegHeaderSize = fRegHeader->GetHeaderLength();
939ae4b2 91
92 Int_t index = 0;
18d3ded7 93
94 memcpy(darcHeader->GetHeader(), &buffer[index], (kDarcHeaderSize)*4);
95 index += kDarcHeaderSize;
939ae4b2 96
f4ee80d2 97
98 // darc type vardorh
99 if (darcHeader->GetDarcType() == 4)
2470870a 100 fMaxReg = 1;
101
f4ee80d2 102 // darc type def.
103 if (darcHeader->GetDarcType() == 6)
2470870a 104 fMaxReg = 8;
105
f4ee80d2 106 if(darcHeader->GetEventType() == scalerEvent)
107 if (fWarnings) AliWarning("Wrong event type obtained from the Darc header, take the one of CDH");
108
5b36fe64 109
939ae4b2 110 if(scalerEvent) {
111 // 6 DARC scaler words
112 memcpy(darcHeader->GetDarcScalers(), &buffer[index], darcHeader->GetDarcScalerLength()*4);
113 index += darcHeader->GetDarcScalerLength();
114 }
115
1db7b71c 116 if (buffer[index++] != darcHeader->GetEndOfDarc()) {
1ed3c5c2 117
96a8629f 118 const Char_t* msg = Form("Wrong end of Darc word %x instead of %x\n",
119 buffer[index-1], darcHeader->GetEndOfDarc());
120 if (fWarnings) AliWarning(msg);
121 AddErrorMessage(msg);
1db7b71c 122 fDarcEoWErrors++;
123 }
939ae4b2 124 // 4 words of global board input + Global board output
18d3ded7 125 memcpy(darcHeader->GetGlobalInput(), &buffer[index], (kGlobalHeaderSize)*4);
126 index += kGlobalHeaderSize;
939ae4b2 127
128 if(scalerEvent) {
129 // 10 Global scaler words
130 memcpy(darcHeader->GetGlobalScalers(), &buffer[index], darcHeader->GetGlobalScalerLength()*4);
131 index += darcHeader->GetGlobalScalerLength();
132 }
133
1db7b71c 134 if (buffer[index++] != darcHeader->GetEndOfGlobal()) {
1ed3c5c2 135
96a8629f 136 const Char_t* msg = Form("Wrong end of Global word %x instead of %x\n",
137 buffer[index-1], darcHeader->GetEndOfGlobal());
138 if (fWarnings) AliWarning(msg);
139 AddErrorMessage(msg);
1db7b71c 140 fGlobalEoWErrors++;
141 }
939ae4b2 142 // 8 regional boards
143 for (Int_t iReg = 0; iReg < fMaxReg; iReg++) { //loop over regeonal card
144
145 memcpy(fRegHeader->GetHeader(), &buffer[index], kRegHeaderSize*4);
146 index += kRegHeaderSize;
147
148 fDDLTrigger->AddRegHeader(*fRegHeader);
149 // 11 regional scaler word
150 if(scalerEvent) {
151 memcpy(fRegHeader->GetScalers(), &buffer[index], fRegHeader->GetScalerLength()*4);
152 index += fRegHeader->GetScalerLength();
153 }
154
1db7b71c 155 if (buffer[index++] != fRegHeader->GetEndOfReg()) {
1ed3c5c2 156
96a8629f 157 const Char_t* msg = Form("Wrong end of Regional word %x instead of %x\n",
158 buffer[index-1], fRegHeader->GetEndOfReg());
159 if (fWarnings) AliWarning(msg);
160 AddErrorMessage(msg);
1db7b71c 161 fRegEoWErrors++;
162 }
939ae4b2 163 // 16 local cards per regional board
164 for (Int_t iLoc = 0; iLoc < fMaxLoc; iLoc++) { //loop over local card
165
166 Int_t dataSize = fLocalStruct->GetLength();;
167
168 // 5 word trigger information
169 memcpy(fLocalStruct->GetData(), &buffer[index], dataSize*4);
170 index += dataSize;
171
172 // 45 regional scaler word
173 if(scalerEvent) {
174 memcpy(fLocalStruct->GetScalers(), &buffer[index], fLocalStruct->GetScalerLength()*4);
175 index += fLocalStruct->GetScalerLength();
176 }
177
1db7b71c 178 if (buffer[index++] != fLocalStruct->GetEndOfLocal()) {
1ed3c5c2 179
96a8629f 180 const Char_t* msg = Form("Wrong end of Local word %x instead of %x\n",
181 buffer[index-1], fLocalStruct->GetEndOfLocal());
182
183 if (fWarnings) AliWarning(msg);
184 AddErrorMessage(msg);
1db7b71c 185 fLocalEoWErrors++;
186 }
5a92f8e6 187 // fill only if card notified
188 if (fLocalStruct->GetData(0) == fLocalStruct->GetDisableWord())
189 continue;
190
939ae4b2 191 fDDLTrigger->AddLocStruct(*fLocalStruct, iReg);
192
193 } // local card loop
194
195 } // regional card loop
196
197
198 return kTRUE;
199}
200
201//______________________________________________________
202void AliMUONPayloadTrigger::ResetDDL()
203{
00e86732 204 /// reseting TClonesArray
205 /// after each DDL
206 ///
939ae4b2 207 AliMUONDarcHeader* darcHeader = fDDLTrigger->GetDarcHeader();
208 darcHeader->GetRegHeaderArray()->Delete();
1db7b71c 209 fDarcEoWErrors = 0;
210 fGlobalEoWErrors = 0;
211 fRegEoWErrors = 0;
212 fLocalEoWErrors = 0;
939ae4b2 213}
214
215//______________________________________________________
216void AliMUONPayloadTrigger::SetMaxReg(Int_t reg)
217{
00e86732 218 /// set regional card number
939ae4b2 219 if (reg > 8) reg = 8;
2470870a 220 fMaxReg = reg;
221
222 fNofRegSet = kTRUE;
939ae4b2 223}
224
225//______________________________________________________
226void AliMUONPayloadTrigger::SetMaxLoc(Int_t loc)
227{
00e86732 228 /// set local card number
939ae4b2 229 if (loc > 16) loc = 16;
230 fMaxLoc = loc;
231}
96a8629f 232
233//______________________________________________________
234void AliMUONPayloadTrigger::AddErrorMessage(const Char_t* msg)
235{
236/// adding message to logger
237
238 TString tmp(msg);
239
240 Int_t pos = tmp.First("\n");
241 tmp[pos] = 0;
242
243 fLog->Log(tmp.Data());
244}
245