]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRawData.cxx
New classes for rawdata generation (Christian)
[u/mrichter/AliRoot.git] / MUON / AliMUONRawData.cxx
CommitLineData
f6762c71 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// MUON Raw Data generator in ALICE-MUON
19//
20// This class v-1:
21// * generates raw data for MUON tracker only (for the moment)
22// * a simple mapping is used (see below)
23// * the bus patch id is calculated but not stored properly in the raw data
24// this has to be changed
25// one DDL per 1/2 chamber is created for both cathode.
26//
27////////////////////////////////////
28
29#include "AliMUONRawData.h"
30#include "AliMUONDigit.h"
31#include "AliMUONConstants.h"
32#include "AliMUONData.h"
33#include "AliMUONDDLTracker.h"
34#include "AliRun.h"
35#include "AliRunLoader.h"
36#include "AliLoader.h"
37#include "AliBitPacking.h"
38
39const Int_t AliMUONRawData::fgkDefaultPrintLevel = 0;
40
41ClassImp(AliMUONRawData) // Class implementation in ROOT context
42
43//__________________________________________________________________________
44AliMUONRawData::AliMUONRawData(AliLoader* loader)
45 : TObject()
46{
47 // Standard Constructor
48
49 fDebug = 0;
50 fNCh = 0;
51 fNTrackingCh = 0;
52 fNTriggerCh = 0;
53 fMUONData = 0;
54
55 fPrintLevel = fgkDefaultPrintLevel;
56
57 // initialize loader's
58 fLoader = loader;
59
60 // initialize container
61 fMUONData = new AliMUONData(fLoader,"MUON","MUON");
62}
63
64//__________________________________________________________________________
65AliMUONRawData::AliMUONRawData()
66 : TObject(),
67 fNCh(0),
68 fNTrackingCh(0),
69 fNTriggerCh(0),
70 fMUONData(0),
71 fPrintLevel(fgkDefaultPrintLevel),
72 fDebug(0),
73 fLoader(0)
74{
75 // Default Constructor
76}
77
78//_______________________________________________________________________
79AliMUONRawData::AliMUONRawData (const AliMUONRawData& rhs)
80 : TObject(rhs)
81{
82// Protected copy constructor
83
84 Fatal("AliMUONRawData", "Not implemented.");
85}
86
87//_______________________________________________________________________
88AliMUONRawData &
89AliMUONRawData::operator=(const AliMUONRawData& rhs)
90{
91// Protected assignement operator
92
93 if (this == &rhs) return *this;
94
95 Fatal("operator=", "Not implemented.");
96
97 return *this;
98}
99
100//__________________________________________________________________________
101AliMUONRawData::~AliMUONRawData(void)
102{
103 if (fMUONData)
104 delete fMUONData;
105 return;
106}
107//____________________________________________________________________
108Int_t AliMUONRawData::WriteRawData()
109{
110 // convert digits of the current event to raw data
111
112
113 Int_t DDLId;
114 Char_t name[20];
115
116 fLoader->LoadDigits("READ");
117 fMUONData->SetTreeAddress("D");
118 // printf("je suis dans WriteRawData\n");
119
120 for (Int_t ich = 0; ich < AliMUONConstants::NTrackingCh(); ich++) {
121
122 // open files
123 DDLId = ich * 2 + 1;
124 sprintf(name, "MUON_%d.ddl",DDLId);
125 fFile1 = fopen(name,"w");
126
127 DDLId = (ich * 2 + 1) + 1;
128 sprintf(name, "MUON_%d.ddl",DDLId);
129 fFile2 = fopen(name,"w");
130
131 WriteDDL(ich);
132
133 // reset and close
134 fclose(fFile1);
135 fclose(fFile2);
136 fMUONData->ResetDigits();
137 }
138
139 return kTRUE;
140}
141//____________________________________________________________________
142Int_t AliMUONRawData::WriteDDL(Int_t iCh)
143{
144
145 TClonesArray* muonDigits = 0;
146
147 // DDL event one per half chamber
148 AliMUONDDLTracker* eventDDL1;
149 AliMUONDDLTracker* eventDDL2;
150
151 // data format
152 Char_t parity = 0x4;
153 UShort_t manuId;
154 UChar_t channelId;
155 UShort_t charge;
156 Int_t busPatchId;
157
158 UInt_t word;
159 Int_t nWord;
160 Int_t dummy;
161
162 Int_t offsetX = 0; // offet row
163 Int_t offsetY = 0; // offset columns
164 Int_t offsetCath = 0; //offset from one cathod to the other
165 Int_t maxChannel = 0; // maximum nb of channel in 1/2 chamber
166 Int_t id;
167
168 Int_t nDigits;
169 AliMUONDigit* digit;
170
171
172 eventDDL1 = new AliMUONDDLTracker();
173 eventDDL2 = new AliMUONDDLTracker();
174
175 for (Int_t iCath = 0; iCath < 2; iCath++) {
176
177 if (fPrintLevel)
178 printf("WriteDDL chamber %d and cathode %d\n", iCh+1, iCath);
179
180 fMUONData->ResetDigits();
181 fMUONData->GetCathode(iCath);
182 muonDigits = fMUONData->Digits(iCh);
183
184 nDigits = muonDigits->GetEntriesFast();
185 if (fPrintLevel)
186 printf("ndigits = %d\n",nDigits);
187
188 // open DDL file, on per 1/2 chamber
189
190 for (Int_t idig = 0; idig < nDigits; idig++) {
191
192 digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
193
194 switch (iCh+1) {
195 case 1:
196 case 2:
197 case 3:
198 case 4:
199 offsetX = 512;
200 offsetY = 256;
201 offsetCath = 65536;
202 maxChannel = (offsetY * offsetX + 2* offsetY + offsetCath);
203 break;
204 case 5:
205 case 6:
206 case 7:
207 case 8:
208 case 9:
209 case 10:
210 offsetX = 1024;
211 offsetY = 0;
212 offsetCath = 65536;
213 maxChannel = (256 * offsetX + offsetX + offsetCath);
214 break;
215 }
216 // dummy mapping
217 // manu Id directly from a matrix 8*8, same segmentation for B and NB
218 // 50 buspatches for 1/2 chamber
219
220 id = (digit->PadX() * offsetX + digit->PadY() + offsetY +
221 offsetCath*iCath);
222 busPatchId = id/50;
223
224 Int_t inBusId = (id - maxChannel/50 * busPatchId);// id channel in buspatch
225 Int_t manuPerBus = (maxChannel/(50*64)); // number of manus per buspatch
226
227 // 64 manu cards for one buspatch
228 manuId = inBusId/manuPerBus;
229 manuId &= 0x7FF; // 11 bits
230
231 // channel id
232 channelId = (inBusId % manuPerBus);
233 channelId &= 0x3F; // 6 bits
234
235 // charge
236 charge = digit->Signal();
237 charge &= 0xFFF;
238
239 if (fPrintLevel)
240 printf("id: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d, charge %d\n",
241 id, busPatchId, manuId, channelId, digit->PadX(), digit->PadY(), digit->Signal());
242 //packing word
243 AliBitPacking::PackWord((UInt_t)parity,word,29,31);
244 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
245 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
246 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
247
248 // set DDL Event
249 if (digit->PadX() > 0) {
250 eventDDL1->SetRawData(word);
251 eventDDL1->SetBusPatchId(busPatchId); // information not usable only last bus patch stored
252 } else {
253 eventDDL2->SetRawData(word);
254 eventDDL2->SetBusPatchId(busPatchId);
255 }
256 if (fPrintLevel) {
257 printf("word: 0x%x, ",word);
258 printf("manuId back %d, ",eventDDL1->GetManuId(eventDDL1->GetLength()-1));
259 printf("channelId back %d, ",eventDDL1->GetChannelId(eventDDL1->GetLength()-1));
260 printf("charge back %d\n",eventDDL1->GetCharge(eventDDL1->GetLength()-1));
261 }
262 }
263 }
264 // write DDL event
265 nWord = eventDDL1->GetLength();
266 if (nWord > 0) { // not empty event
267 fwrite(eventDDL1->GetAddress(),sizeof(int),nWord+2,fFile1);
268 dummy = eventDDL1->GetEoD();
269 fwrite(&dummy,sizeof(int),1,fFile1);// could be nicer !
270 }
271 nWord = eventDDL2->GetLength();
272 if (nWord > 0) {
273 fwrite(eventDDL2->GetAddress(),sizeof(int),nWord+2,fFile2);
274 dummy = eventDDL2->GetEoD();
275 fwrite(&dummy,sizeof(int),1,fFile2);
276 }
277 delete eventDDL1;
278 delete eventDDL2;
279 return kTRUE;
280}