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