]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPayloadTrigger.cxx
Initialisation.
[u/mrichter/AliRoot.git] / MUON / AliMUONPayloadTrigger.cxx
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 // $Id$
17
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONPayloadTrigger
20 /// Class Payload
21 ///
22 /// Decodes rawdata from buffer and stores in TClonesArray.
23 /// 
24 /// First version implement for Trigger
25 ///
26 /// \author Christian Finck
27 //-----------------------------------------------------------------------------
28
29 #include "AliMUONPayloadTrigger.h"
30
31 #include "AliMUONDarcHeader.h"
32 #include "AliMUONRegHeader.h"
33 #include "AliMUONLocalStruct.h"
34 #include "AliMUONDDLTrigger.h"
35 #include "AliMUONLogger.h"
36
37 #include "AliLog.h"
38
39 /// \cond CLASSIMP
40 ClassImp(AliMUONPayloadTrigger)
41 /// \endcond
42
43 AliMUONPayloadTrigger::AliMUONPayloadTrigger()
44   : TObject(),
45     fMaxReg(8),
46     fMaxLoc(16),
47     fDDLTrigger(new AliMUONDDLTrigger()),
48     fRegHeader(new AliMUONRegHeader()), 
49     fLocalStruct(new AliMUONLocalStruct()),
50     fLog(new AliMUONLogger(1000)),
51     fDarcEoWErrors(0),
52     fGlobalEoWErrors(0),
53     fRegEoWErrors(0),
54     fLocalEoWErrors(0),
55     fWarnings(kTRUE)
56 {
57   ///
58   /// create an object to read MUON raw digits
59   /// Default ctor for monitoring purposes
60   ///
61
62 }
63
64 //___________________________________
65 AliMUONPayloadTrigger::~AliMUONPayloadTrigger()
66 {
67   ///
68   /// clean up
69   ///
70   delete fDDLTrigger;
71   delete fLocalStruct;
72   delete fRegHeader;
73   delete fLog;
74 }
75
76
77 //______________________________________________________
78 Bool_t AliMUONPayloadTrigger::Decode(UInt_t *buffer)
79 {
80   /// decode trigger DDL
81   /// store only notified cards
82
83  // reading DDL for trigger
84
85   AliMUONDarcHeader* darcHeader = fDDLTrigger->GetDarcHeader();
86
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;
92   
93   Int_t index = 0;
94
95   memcpy(darcHeader->GetHeader(), &buffer[index], (kDarcHeaderSize)*4); 
96   index += kDarcHeaderSize;
97
98   if(darcHeader->GetEventType() == 0) {
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
109   if (buffer[index++] != darcHeader->GetEndOfDarc()) {
110
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);
115       fDarcEoWErrors++;
116   }
117   // 4 words of global board input + Global board output
118   memcpy(darcHeader->GetGlobalInput(), &buffer[index], (kGlobalHeaderSize)*4); 
119   index += kGlobalHeaderSize; 
120
121   if(scalerEvent) {
122     // 10 Global scaler words
123     memcpy(darcHeader->GetGlobalScalers(), &buffer[index], darcHeader->GetGlobalScalerLength()*4);
124     index += darcHeader->GetGlobalScalerLength();
125   }
126
127   if (buffer[index++] != darcHeader->GetEndOfGlobal()) {
128
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);
133       fGlobalEoWErrors++;
134   }
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
148     if (buffer[index++] != fRegHeader->GetEndOfReg()) {
149
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);
154       fRegEoWErrors++;
155     }
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
171       if (buffer[index++] != fLocalStruct->GetEndOfLocal()) {
172
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);
178         fLocalEoWErrors++;
179       }
180       // fill only if card notified
181       if (fLocalStruct->GetData(0) == fLocalStruct->GetDisableWord())
182           continue;
183
184       fDDLTrigger->AddLocStruct(*fLocalStruct, iReg);
185
186     } // local card loop
187         
188   } // regional card loop
189       
190
191   return kTRUE;
192 }
193
194 //______________________________________________________
195 void AliMUONPayloadTrigger::ResetDDL()
196 {
197   /// reseting TClonesArray
198   /// after each DDL
199   ///
200   AliMUONDarcHeader* darcHeader = fDDLTrigger->GetDarcHeader();
201   darcHeader->GetRegHeaderArray()->Delete();
202   fDarcEoWErrors   = 0;
203   fGlobalEoWErrors = 0;
204   fRegEoWErrors    = 0;
205   fLocalEoWErrors  = 0;
206 }
207
208 //______________________________________________________
209 void AliMUONPayloadTrigger::SetMaxReg(Int_t reg) 
210 {
211   /// set regional card number
212   if (reg > 8) reg = 8;
213   fMaxReg = reg;
214 }
215
216 //______________________________________________________
217 void AliMUONPayloadTrigger::SetMaxLoc(Int_t loc) 
218 {
219   /// set local card number
220   if (loc > 16) loc = 16;
221   fMaxLoc = loc;
222 }
223
224 //______________________________________________________
225 void 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