]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPayloadTracker.cxx
caae37d142097cfb023e8a1848e771b1dd052037
[u/mrichter/AliRoot.git] / MUON / AliMUONPayloadTracker.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
17 ///////////////////////////////////////////////////////////////////////////////
18 ///
19 /// Class Payload
20 ///
21 /// Decodes rawdata from buffer and stores in TClonesArray.
22 /// 
23 /// First version implement for Tracker
24 ///
25 ///////////////////////////////////////////////////////////////////////////////
26
27 #include "AliMUONPayloadTracker.h"
28
29 #include "AliRawReader.h"
30 #include "AliRawDataHeader.h"
31 #include "AliLog.h"
32
33 #include "AliMUONDspHeader.h"
34 #include "AliMUONBlockHeader.h"
35 #include "AliMUONBusStruct.h"
36 #include "AliMUONDDLTracker.h"
37
38 ClassImp(AliMUONPayloadTracker)
39
40 AliMUONPayloadTracker::AliMUONPayloadTracker()
41   : TObject(),
42     fMaxBlock(2),
43     fMaxDsp(5),
44     fMaxBus(5)
45 {
46   //
47   // create an object to decode MUON payload
48   //
49
50   fDDLTracker      = new AliMUONDDLTracker();
51   fBusStruct       = new AliMUONBusStruct();
52   fBlockHeader     = new AliMUONBlockHeader();
53   fDspHeader       = new AliMUONDspHeader();
54 }
55
56 //_________________________________________________________________
57 AliMUONPayloadTracker::AliMUONPayloadTracker(const AliMUONPayloadTracker& stream) :
58   TObject(stream)
59
60   //
61   // copy ctor
62   //
63   AliFatal("copy constructor not implemented");
64 }
65
66 //______________________________________________________________________
67 AliMUONPayloadTracker& AliMUONPayloadTracker::operator = (const AliMUONPayloadTracker& 
68                                               /* stream */)
69 {
70   // 
71   // assignment operator
72   //
73   AliFatal("assignment operator not implemented");
74   return *this;
75 }
76
77
78 //___________________________________
79 AliMUONPayloadTracker::~AliMUONPayloadTracker()
80 {
81   //
82   // clean up
83   //
84   delete fDDLTracker;
85   delete fBusStruct;
86   delete fBlockHeader;
87   delete fDspHeader;
88 }
89
90 //______________________________________________________
91 Bool_t AliMUONPayloadTracker::Decode(UInt_t* buffer, Int_t totalDDLSize)
92 {
93
94   // Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most 
95   // and each of DSP has at most 5 buspatches.
96   // The different structures, Block (CRT), DSP (FRT) and Buspatch,
97   // are identified by a key word 0xFC0000FC, 0xF000000F and 0xB000000B respectively.
98   // (fBusPatchManager no more needed !)
99
100
101   //Read Header Size of DDL,Block,DSP and BusPatch
102   static Int_t kBlockHeaderSize    = fBlockHeader->GetHeaderLength();
103   static Int_t kDspHeaderSize      = fDspHeader->GetHeaderLength();
104   static Int_t kBusPatchHeaderSize = fBusStruct->GetHeaderLength();
105
106   // size structures
107   Int_t totalBlockSize;
108   Int_t totalDspSize;
109   Int_t totalBusPatchSize;
110   Int_t dataSize; 
111   Int_t bufSize;
112
113   // indexes
114   Int_t indexBlk;
115   Int_t indexDsp;
116   Int_t indexBusPatch;
117   Int_t index = 0;
118   Int_t iBlock = 0;
119
120   // CROCUS CRT
121   while (buffer[index] == fBlockHeader->GetDefaultDataKey()) {
122
123     if (iBlock > fMaxBlock) break;
124      
125     // copy within padding words
126     memcpy(fBlockHeader->GetHeader(),&buffer[index], (kBlockHeaderSize)*4);
127
128     totalBlockSize = fBlockHeader->GetTotalLength();
129
130     indexBlk = index;
131     index += kBlockHeaderSize;
132
133     // copy in TClonesArray
134     fDDLTracker->AddBlkHeader(*fBlockHeader);
135
136     // Crocus FRT
137     Int_t iDsp = 0;
138     while (buffer[index] == fDspHeader->GetDefaultDataKey()) {
139
140       if (iDsp > fMaxDsp) break; // if ever...
141                 
142       memcpy(fDspHeader->GetHeader(),&buffer[index], kDspHeaderSize*4);
143
144       totalDspSize = fDspHeader->GetTotalLength();
145       indexDsp = index;
146       index += kDspHeaderSize;
147
148       if (fDspHeader->GetPaddingWord() != fDspHeader->GetDefaultPaddingWord()) {
149         // copy the field of Padding word into ErrorWord field
150         fDspHeader->SetErrorWord(fDspHeader->GetPaddingWord());
151         index--;
152       }
153
154       // copy in TClonesArray
155       fDDLTracker->AddDspHeader(*fDspHeader, iBlock);
156
157       // buspatch structure
158       Int_t iBusPatch = 0;
159       while (buffer[index] == fBusStruct->GetDefaultDataKey()) {
160
161         if (iBusPatch > fMaxBus) break; // if ever
162         
163         //copy buffer into header structure
164         memcpy(fBusStruct->GetHeader(), &buffer[index], kBusPatchHeaderSize*4);
165
166         totalBusPatchSize = fBusStruct->GetTotalLength();
167         indexBusPatch     = index;
168                 
169         //Check Buspatch header, not empty events
170         if(totalBusPatchSize > kBusPatchHeaderSize) {    
171
172           index   += kBusPatchHeaderSize;
173           dataSize = fBusStruct->GetLength();
174           bufSize  = fBusStruct->GetBufSize();
175
176           if(dataSize > 0) { // check data present
177             if (dataSize > bufSize) // check buffer size
178               fBusStruct->SetAlloc(dataSize);
179          
180             //copy buffer into data structure
181             memcpy(fBusStruct->GetData(), &buffer[index], dataSize*4);
182             fBusStruct->SetBlockId(iBlock); // could be usefull in future applications ?
183             fBusStruct->SetDspId(iDsp);
184
185             // copy in TClonesArray
186             fDDLTracker->AddBusPatch(*fBusStruct, iBlock, iDsp);
187
188           } // dataSize test
189
190         } // testing buspatch
191
192         index = indexBusPatch + totalBusPatchSize;
193         if (index >= totalDDLSize) {// check the end of DDL
194           index = totalDDLSize - 1; // point to the last element of buffer
195           break;
196         }
197         iBusPatch++;
198       }  // buspatch loop
199                 
200       index = indexDsp + totalDspSize;
201       if (index >= totalDDLSize) {
202         index = totalDDLSize - 1;
203         break;
204       }
205       iDsp++;
206     }  // dsp loop
207
208     index = indexBlk + totalBlockSize;
209     if (index >= totalDDLSize) {
210       index = totalDDLSize - 1;
211       break;
212     }
213     iBlock++;
214   }  // block loop
215
216   return kTRUE;
217 }
218
219 //______________________________________________________
220 void AliMUONPayloadTracker::ResetDDL()
221 {
222   // reseting TClonesArray
223   // after each DDL
224   //
225   fDDLTracker->GetBlkHeaderArray()->Delete();
226 }
227
228 //______________________________________________________
229 void AliMUONPayloadTracker::SetMaxBlock(Int_t blk) 
230 {
231   // set regional card number
232   if (blk > 2) blk = 2;
233   fMaxBlock = blk;
234 }