1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ////////////////////////////////////
18 // MUON Raw Data generator in ALICE-MUON
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.
27 ////////////////////////////////////
29 #include "AliMUONRawData.h"
30 #include "AliMUONDigit.h"
31 #include "AliMUONConstants.h"
32 #include "AliMUONData.h"
33 #include "AliMUONDDLTracker.h"
35 #include "AliRunLoader.h"
36 #include "AliLoader.h"
37 #include "AliBitPacking.h"
38 #include "AliRawDataHeader.h"
40 const Int_t AliMUONRawData::fgkDefaultPrintLevel = 0;
42 ClassImp(AliMUONRawData) // Class implementation in ROOT context
44 //__________________________________________________________________________
45 AliMUONRawData::AliMUONRawData(AliLoader* loader)
48 // Standard Constructor
56 fPrintLevel = fgkDefaultPrintLevel;
58 // initialize loader's
61 // initialize container
62 fMUONData = new AliMUONData(fLoader,"MUON","MUON");
65 //__________________________________________________________________________
66 AliMUONRawData::AliMUONRawData()
72 fPrintLevel(fgkDefaultPrintLevel),
76 // Default Constructor
79 //_______________________________________________________________________
80 AliMUONRawData::AliMUONRawData (const AliMUONRawData& rhs)
83 // Protected copy constructor
85 Fatal("AliMUONRawData", "Not implemented.");
88 //_______________________________________________________________________
90 AliMUONRawData::operator=(const AliMUONRawData& rhs)
92 // Protected assignement operator
94 if (this == &rhs) return *this;
96 Fatal("operator=", "Not implemented.");
101 //__________________________________________________________________________
102 AliMUONRawData::~AliMUONRawData(void)
108 //____________________________________________________________________
109 Int_t AliMUONRawData::WriteRawData()
111 // convert digits of the current event to raw data
117 fLoader->LoadDigits("READ");
118 fMUONData->SetTreeAddress("D");
119 // printf("je suis dans WriteRawData\n");
121 for (Int_t ich = 0; ich < AliMUONConstants::NTrackingCh(); ich++) {
124 DDLId = ich * 2 + 0x900;
125 sprintf(name, "MUON_%d.ddl",DDLId);
126 fFile1 = fopen(name,"w");
128 DDLId = (ich * 2) + 1 + 0x900 ;
129 sprintf(name, "MUON_%d.ddl",DDLId);
130 fFile2 = fopen(name,"w");
137 fMUONData->ResetDigits();
142 //____________________________________________________________________
143 Int_t AliMUONRawData::WriteDDL(Int_t iCh)
146 TClonesArray* muonDigits = 0;
148 // DDL event one per half chamber
149 AliMUONDDLTracker* eventDDL1;
150 AliMUONDDLTracker* eventDDL2;
163 Int_t offsetX = 0; // offet row
164 Int_t offsetY = 0; // offset columns
165 Int_t offsetCath = 0; //offset from one cathod to the other
166 Int_t maxChannel = 0; // maximum nb of channel in 1/2 chamber
172 AliRawDataHeader header;
174 eventDDL1 = new AliMUONDDLTracker();
175 eventDDL2 = new AliMUONDDLTracker();
177 for (Int_t iCath = 0; iCath < 2; iCath++) {
180 printf("WriteDDL chamber %d and cathode %d\n", iCh+1, iCath);
182 fMUONData->ResetDigits();
183 fMUONData->GetCathode(iCath);
184 muonDigits = fMUONData->Digits(iCh);
186 nDigits = muonDigits->GetEntriesFast();
188 printf("ndigits = %d\n",nDigits);
190 // open DDL file, on per 1/2 chamber
192 for (Int_t idig = 0; idig < nDigits; idig++) {
194 digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
204 maxChannel = (offsetY * offsetX + 2* offsetY + offsetCath);
215 maxChannel = (256 * offsetX + offsetX + offsetCath);
219 // manu Id directly from a matrix 8*8, same segmentation for B and NB
220 // 50 buspatches for 1/2 chamber
222 id = (TMath::Abs(digit->PadX()) * offsetX + digit->PadY() + offsetY +
226 Int_t inBusId = (id - maxChannel/50 * busPatchId);// id channel in buspatch
227 Int_t manuPerBus = (maxChannel/(50*64)); // number of manus per buspatch
229 // 64 manu cards for one buspatch
230 manuId = inBusId/manuPerBus;
231 manuId &= 0x7FF; // 11 bits
234 channelId = (inBusId % manuPerBus);
235 channelId &= 0x3F; // 6 bits
238 charge = digit->Signal();
242 printf("id: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d, charge %d\n",
243 id, busPatchId, manuId, channelId, digit->PadX(), digit->PadY(), digit->Signal());
245 AliBitPacking::PackWord((UInt_t)parity,word,29,31);
246 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
247 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
248 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
251 if (digit->PadX() > 0) {
252 eventDDL1->SetRawData(word);
253 eventDDL1->SetBusPatchId(busPatchId); // information not usable only last bus patch stored
255 eventDDL2->SetRawData(word);
256 eventDDL2->SetBusPatchId(busPatchId);
259 printf("word: 0x%x, ",word);
260 printf("manuId back %d, ",eventDDL1->GetManuId(eventDDL1->GetLength()-1));
261 printf("channelId back %d, ",eventDDL1->GetChannelId(eventDDL1->GetLength()-1));
262 printf("charge back %d\n",eventDDL1->GetCharge(eventDDL1->GetLength()-1));
267 nWord = eventDDL1->GetLength();
268 if (nWord > 0) { // not empty event
269 header.fSize = nWord*4 + sizeof(AliRawDataHeader) + 12; // include EoD & length
270 fwrite((char*)(&header),sizeof(header),1,fFile1);
271 fwrite(eventDDL1->GetAddress(),sizeof(int),nWord+2,fFile1);
272 dummy = eventDDL1->GetEoD();
273 fwrite(&dummy,sizeof(int),1,fFile1);// could be nicer !
275 nWord = eventDDL2->GetLength();
277 header.fSize = nWord*4 + sizeof(AliRawDataHeader) + 12;
278 fwrite((char*)(&header),sizeof(header),1,fFile2);
279 fwrite(eventDDL2->GetAddress(),sizeof(int),nWord+2,fFile2);
280 dummy = eventDDL2->GetEoD();
281 fwrite(&dummy,sizeof(int),1,fFile2);