]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPayloadTrigger.cxx
Updated serial number for station 345
[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     fNofRegSet(kFALSE)
57 {
58   ///
59   /// create an object to read MUON raw digits
60   /// Default ctor for monitoring purposes
61   ///
62
63 }
64
65 //___________________________________
66 AliMUONPayloadTrigger::~AliMUONPayloadTrigger()
67 {
68   ///
69   /// clean up
70   ///
71   delete fDDLTrigger;
72   delete fLocalStruct;
73   delete fRegHeader;
74   delete fLog;
75 }
76
77
78 //______________________________________________________
79 Bool_t AliMUONPayloadTrigger::Decode(UInt_t *buffer, Bool_t scalerEvent)
80 {
81   /// decode trigger DDL
82   /// store only notified cards
83
84  // reading DDL for trigger
85
86   AliMUONDarcHeader* darcHeader = fDDLTrigger->GetDarcHeader();
87
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
95   Int_t index = 0;
96
97   memcpy(darcHeader->GetHeader(), &buffer[index], (kDarcHeaderSize)*4); 
98   index += kDarcHeaderSize;
99
100
101   // darc type vadorh
102   if (darcHeader->GetDarcType() == darcHeader->GetDarcVadohrType())
103       fMaxReg = 1;
104     
105   // darc type def.
106   if (darcHeader->GetDarcType() == darcHeader->GetDarcDefaultType())
107       fMaxReg = 8;
108       
109   if(darcHeader->GetEventType() == scalerEvent) 
110       if (fWarnings) AliWarning("Wrong event type obtained from the Darc header, take the one of CDH");
111
112
113   if(scalerEvent) {
114     // 6 DARC scaler words
115     memcpy(darcHeader->GetDarcScalers(), &buffer[index], darcHeader->GetDarcScalerLength()*4);
116     index += darcHeader->GetDarcScalerLength();
117   }
118
119   if (buffer[index++] != darcHeader->GetEndOfDarc()) {
120
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);
125       fDarcEoWErrors++;
126   }
127   // 4 words of global board input + Global board output
128   memcpy(darcHeader->GetGlobalInput(), &buffer[index], (kGlobalHeaderSize)*4); 
129   index += kGlobalHeaderSize; 
130
131   if(scalerEvent) {
132     // 10 Global scaler words
133     memcpy(darcHeader->GetGlobalScalers(), &buffer[index], darcHeader->GetGlobalScalerLength()*4);
134     index += darcHeader->GetGlobalScalerLength();
135   }
136
137   if (buffer[index++] != darcHeader->GetEndOfGlobal()) {
138
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);
143       fGlobalEoWErrors++;
144   }
145   // 8 regional boards
146   for (Int_t iReg = 0; iReg < fMaxReg; iReg++) {           //loop over regeonal card
147
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     }
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
166     if (buffer[index++] != fRegHeader->GetEndOfReg()) {
167
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);
172       fRegEoWErrors++;
173     }
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
189       if (buffer[index++] != fLocalStruct->GetEndOfLocal()) {
190
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);
196         fLocalEoWErrors++;
197       }
198       // fill only if card notified
199       if (fLocalStruct->GetData(0) == fLocalStruct->GetDisableWord())
200           continue;
201
202       fDDLTrigger->AddLocStruct(*fLocalStruct, iReg);
203
204     } // local card loop
205         
206   } // regional card loop
207       
208
209   return kTRUE;
210 }
211
212 //______________________________________________________
213 void AliMUONPayloadTrigger::ResetDDL()
214 {
215   /// reseting TClonesArray
216   /// after each DDL
217   ///
218   AliMUONDarcHeader* darcHeader = fDDLTrigger->GetDarcHeader();
219   darcHeader->GetRegHeaderArray()->Delete();
220   fDarcEoWErrors   = 0;
221   fGlobalEoWErrors = 0;
222   fRegEoWErrors    = 0;
223   fLocalEoWErrors  = 0;
224 }
225
226 //______________________________________________________
227 void AliMUONPayloadTrigger::SetMaxReg(Int_t reg) 
228 {
229   /// set regional card number
230   if (reg > 8) reg = 8;
231    fMaxReg = reg;
232    
233   fNofRegSet = kTRUE;
234 }
235
236 //______________________________________________________
237 void AliMUONPayloadTrigger::SetMaxLoc(Int_t loc) 
238 {
239   /// set local card number
240   if (loc > 16) loc = 16;
241   fMaxLoc = loc;
242 }
243
244 //______________________________________________________
245 void 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