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