]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRawReader.cxx
Minor fixes in the event tag to take into account the new way of storing the trigger...
[u/mrichter/AliRoot.git] / MUON / AliMUONRawReader.cxx
CommitLineData
a19e2543 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//
ced309a5 18// MUON Raw Data reader in ALICE-MUON
19// Class version 3 (further details could be found in Alice-note)
a19e2543 20//
21// Implemented non-constant buspatch numbers for tracking
22// with correct DDL id (first guess)
23// (Ch. Finck, dec 2005)
24//
a19e2543 25//
26// Raw2Digits:
27// Using real mapping for tracker
28// Indranil Das (Adapted for runloader: Ch. Finck) july 05
ced309a5 29// Add reader for scaler trigger events
30// Use memcpy instead of assignment elt by elt
31// (Ch. Finck, Jan 06)
a19e2543 32//
33////////////////////////////////////
34
35#include <fstream>
36#include <string>
37
38#include <TClonesArray.h>
39
a19e2543 40#include "AliBitPacking.h"
41#include "AliRawReader.h"
42#include "AliLog.h"
43#include "AliRun.h"
44
2cbb173f 45#include "AliMpBusPatch.h"
46
a19e2543 47#include "AliMUON.h"
48#include "AliMUONRawReader.h"
49#include "AliMUONDigit.h"
50
51#include "AliMUONConstants.h"
52#include "AliMUONData.h"
53
54#include "AliMUONSubEventTracker.h"
ced309a5 55#include "AliMUONScalerEventTrigger.h"
a19e2543 56#include "AliMUONSubEventTrigger.h"
57#include "AliMUONDDLTracker.h"
58#include "AliMUONDDLTrigger.h"
59
60#include "AliMUONLocalTrigger.h"
61#include "AliMUONGlobalTrigger.h"
62
63#include "AliMUONGeometrySegmentation.h"
64#include "AliMUONGeometryModule.h"
65#include "AliMUONGeometryStore.h"
66#include "AliMpSegFactory.h"
67#include "AliMpPlaneType.h"
68#include "AliMpVSegmentation.h"
69#include "AliMpHelper.h"
70#include "AliMpPad.h"
2cbb173f 71#include "AliMpDEManager.h"
a19e2543 72
73ClassImp(AliMUONRawReader) // Class implementation in ROOT context
74//__________________________________________________________________________
2cbb173f 75AliMUONRawReader::AliMUONRawReader(AliMUONData* data)
76: TObject(),
77 fScalerEvent(kFALSE)
a19e2543 78{
d19b6003 79// Standard Constructor
80
2cbb173f 81 AliDebug(1,"");
82
a19e2543 83 // initialize segmentation factory
84 fSegFactory = new AliMpSegFactory();
85
86 // initialize container
87 fMUONData = data;
88
89 // ddl pointer
90 fDDLTracker = new AliMUONDDLTracker();
91 fDDLTrigger = new AliMUONDDLTrigger();
92
93 fBusPatchManager = new AliMpBusPatch();
94 fBusPatchManager->ReadBusPatchFile();
95
2cbb173f 96 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
97 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
98 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
a19e2543 99}
100
101//__________________________________________________________________________
102AliMUONRawReader::AliMUONRawReader()
103 : TObject(),
104 fMUONData(0),
a19e2543 105 fSegFactory(0),
106 fDDLTracker(0),
ced309a5 107 fDDLTrigger(0),
108 fBusPatchManager(0),
109 fScalerEvent(kFALSE)
a19e2543 110{
111 // Default Constructor
2cbb173f 112 AliDebug(1,"");
113 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
114 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
115 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
a19e2543 116}
117
118//_______________________________________________________________________
119AliMUONRawReader::AliMUONRawReader (const AliMUONRawReader& rhs)
120 : TObject(rhs)
121{
122// Protected copy constructor
123
124 AliFatal("Not implemented.");
125}
126
127//_______________________________________________________________________
128AliMUONRawReader &
129AliMUONRawReader::operator=(const AliMUONRawReader& rhs)
130{
131// Protected assignement operator
132
133 if (this == &rhs) return *this;
134
135 AliFatal("Not implemented.");
136
137 return *this;
138}
139
140//__________________________________________________________________________
2cbb173f 141AliMUONRawReader::~AliMUONRawReader()
a19e2543 142{
d19b6003 143// Destructor
144
a19e2543 145 delete fSegFactory;
146
2cbb173f 147 delete fDDLTracker;
148 delete fDDLTrigger;
a19e2543 149
2cbb173f 150 delete fBusPatchManager;
151
152 AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
153 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
154 AliInfo(Form(" Execution time for MUON tracker (mapping calls part) "
155 ": R:%.2fs C:%.2fs",
156 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
157 AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
158 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
a19e2543 159
a19e2543 160}
161
162//____________________________________________________________________
163Int_t AliMUONRawReader::Raw2Digits(AliRawReader* rawReader)
164{
165
166 // generate digits
167 ReadTrackerDDL(rawReader);
168
169 // generate trigger
170 ReadTriggerDDL(rawReader);
171
172 return kTRUE;
173
174}
175
176//____________________________________________________________________
177Int_t AliMUONRawReader::ReadTrackerDDL(AliRawReader* rawReader)
178{
179 // reading tracker DDL
180 // filling the TClonesArray in MUONData
181 //
2cbb173f 182 fTrackerTimer.Start(kFALSE);
183
a19e2543 184 AliMUONSubEventTracker* subEventTracker = new AliMUONSubEventTracker();
185 AliMUONDigit* digit = new AliMUONDigit();
186
187
ced309a5 188 //Read Header Size of DDL,Block,DSP and BusPatch (put k before constant imb'cile)
a19e2543 189
ced309a5 190 Int_t kDDLHeaderSize = fDDLTracker->GetHeaderSize();
191 Int_t kBlockHeaderSize = fDDLTracker->GetBlkHeaderLength();
192 Int_t kDspHeaderSize = fDDLTracker->GetDspHeaderLength();
193 Int_t kBusPatchHeaderSize = subEventTracker->GetHeaderLength();
a19e2543 194
195 Int_t totalDDLSize, totalBlockSize, totalDspSize , totalBusPatchSize, dataSize;
196
197
198 Int_t iBusPerDSP[5];//number of bus patches per DSP
199 Int_t iDspMax; //number max of DSP per block
200
201 // minimum data size (only header's)
202 Int_t blankDDLSize;
203 Int_t blankBlockSize;
204 Int_t blankDspSize;
205
206 for(Int_t iDDL = 0; iDDL < 20; iDDL++) { // DDL loop
207
208 AliDebug(3, Form("Chamber %d\n", iDDL/2 +1 ));
209
210 // getting DSP info
211 fBusPatchManager->GetDspInfo(iDDL/2, iDspMax, iBusPerDSP);
212
213 // Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most and each of DSP has at most 5 buspatches.
214 // This information is used to calculate the size of headers (DDL,Block and DSP) which has no interesting data.
ced309a5 215 blankDDLSize = kDDLHeaderSize + 2*kBlockHeaderSize + 2*iDspMax*kDspHeaderSize;
216 blankBlockSize = kBlockHeaderSize + iDspMax*kDspHeaderSize;
a19e2543 217
218 for (Int_t i = 0; i < iDspMax; i++) {
ced309a5 219 blankDDLSize += 2*iBusPerDSP[i]*kBusPatchHeaderSize;
220 blankBlockSize += iBusPerDSP[i]*kBusPatchHeaderSize;
a19e2543 221 }
c837da58 222 rawReader->Reset();
a19e2543 223 rawReader->Select(0X9, iDDL, iDDL); //Select the DDL file to be read
224
225 rawReader->ReadHeader();
226
227 totalDDLSize = (rawReader->GetDataSize() + sizeof(AliRawDataHeader))/4; // 4 is multiplied to convert byte 2 words
228
229 if(totalDDLSize > blankDDLSize) { // Compare the DDL header with an empty DDL header size to read the file
230
ced309a5 231 Int_t totalDataWord = rawReader->GetDataSize(); // in bytes
232 UInt_t *buffer = new UInt_t[totalDataWord/4];
c837da58 233
ced309a5 234 rawReader->ReadNext((UChar_t*)buffer, totalDataWord);
a19e2543 235
236 // elex info
237 Int_t buspatchId;
238 UChar_t channelId;
239 UShort_t manuId;
240 Char_t parity;
241 UShort_t charge;
242
243 // indexes
244 Int_t indexDsp;
245 Int_t indexBusPatch;
246 Int_t index = 0;
247
248 for(Int_t iBlock = 0; iBlock < 2 ;iBlock++){ // loop over 2 blocks
249 totalBlockSize = buffer[index];
250
251 if(totalBlockSize > blankBlockSize) { // compare block header
ced309a5 252 index += kBlockHeaderSize;
a19e2543 253
254 for(Int_t iDsp = 0; iDsp < iDspMax ;iDsp++){ //DSP loop
255
256 totalDspSize = buffer[index];
257 indexDsp = index;
258
ced309a5 259 blankDspSize = kDspHeaderSize + iBusPerDSP[iDsp]*kBusPatchHeaderSize; // no data just header
a19e2543 260
261 if(totalDspSize > blankDspSize) { // Compare DSP Header
ced309a5 262 index += kDspHeaderSize;
a19e2543 263
264 for(Int_t iBusPatch = 0; iBusPatch < iBusPerDSP[iDsp]; iBusPatch++) {
265
ced309a5 266 //copy buffer into header structure
267 memcpy(subEventTracker->GetBusPatchHeader(), &buffer[index], kBusPatchHeaderSize*4);
268
269 totalBusPatchSize = subEventTracker->GetTotalLength();
270 buspatchId = subEventTracker->GetBusPatchId();
a19e2543 271 indexBusPatch = index;
ced309a5 272
a19e2543 273
ced309a5 274 if(totalBusPatchSize > kBusPatchHeaderSize) { //Check Buspatch header, not empty events
a19e2543 275
ced309a5 276 index += kBusPatchHeaderSize;
277 dataSize = subEventTracker->GetLength();
27b09716 278 Int_t bufSize = subEventTracker->GetBufSize();
a19e2543 279
280 if(dataSize>0) { // check data present
27b09716 281 if (dataSize > bufSize) subEventTracker->SetAlloc(dataSize);
a19e2543 282
ced309a5 283 //copy buffer into data structure
284 memcpy(subEventTracker->GetData(), &buffer[index], dataSize*4);
285 index += dataSize;
286
a19e2543 287 for(Int_t iData = 0; iData < dataSize; iData++) {
288
a19e2543 289 // digits info
290 parity = subEventTracker->GetParity(iData); // test later for parity
291 manuId = subEventTracker->GetManuId(iData);
292 channelId = subEventTracker->GetChannelId(iData);
293 charge = subEventTracker->GetCharge(iData);
27b09716 294
a19e2543 295 // set charge
296 digit->SetSignal(charge);
2cbb173f 297 digit->SetPhysicsSignal(charge);
298 digit->SetADC(charge);
a19e2543 299 Int_t error = GetMapping(buspatchId,manuId,channelId,digit); // Get Back the hits at pads
300 if (error) continue;
301
302 // debugging
303 if (AliLog::GetGlobalDebugLevel() == 3) {
304 Int_t padX = digit->PadX();
305 Int_t padY = digit->PadY();
306 Int_t iCath = digit->Cathode();
2cbb173f 307 Int_t detElemId = digit->DetElemId();
a19e2543 308
2cbb173f 309 AliDebug(1,Form("output detElemId %d busPatchid %d PadX %d PadY %d iCath %d \n",
310 detElemId, buspatchId, padX, padY, iCath));
a19e2543 311
2cbb173f 312 AliDebug(3,Form("detElemId %d Padx %d Pady %d, Cath %d, charge %d",detElemId, padX, padY, iCath, charge));
a19e2543 313 }
314
315 // fill digits
316 fMUONData->AddDigit(iDDL/2, *digit);
317
318 } // data loop
319 } // dataSize test
320 } // testing buspatch
321
322 index = indexBusPatch + totalBusPatchSize;
323
324 } //buspatch loop
325
326 } // dsp test
327
328 index = indexDsp + totalDspSize;
329
330 } // dsp loop
331
332 } //block test
333
334 index = totalBlockSize;
335
336 } //block loop
337
338 delete[] buffer;
339 } //loop checking the header size of DDL
340
341 //delete rawReader;
342 } // DDL loop
343
344
345 delete subEventTracker;
346 delete digit;
347
2cbb173f 348 fTrackerTimer.Stop();
349
a19e2543 350 return kTRUE;
351}
352
353//____________________________________________________________________
354Int_t AliMUONRawReader::GetMapping(Int_t busPatchId, UShort_t manuId,
355 UChar_t channelId, AliMUONDigit* digit )
356{
357
358 // mapping for tracker
359
2cbb173f 360 fMappingTimer.Start(kFALSE);
361
a19e2543 362 // getting DE from buspatch
2cbb173f 363 Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
364 AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
a19e2543 365
2cbb173f 366 AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);
367 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
a19e2543 368
2cbb173f 369 if (!pad.IsValid())
370 {
371 AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",
372 detElemId, busPatchId, manuId, channelId));
373 fMappingTimer.Stop();
a19e2543 374 return kTRUE;
375 } // return error
376
2cbb173f 377 // Getting padX, padY and cathode number.
a19e2543 378 Int_t padX = pad.GetIndices().GetFirst();
a19e2543 379 Int_t padY = pad.GetIndices().GetSecond();
2cbb173f 380 Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
381
a19e2543 382 // storing into digits
383 digit->SetPadX(padX);
384 digit->SetPadY(padY);
385 digit->SetCathode(iCath);
2cbb173f 386 digit->SetDetElemId(detElemId);
387 digit->SetElectronics(manuId,channelId);
388
389 AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
390 detElemId, busPatchId, manuId, channelId, padX, padY));
391 StdoutToAliDebug(3,digit->Print(););
392
393 fMappingTimer.Stop();
a19e2543 394 return kFALSE;
395}
396
397//____________________________________________________________________
398Int_t AliMUONRawReader::ReadTriggerDDL(AliRawReader* rawReader)
399{
400
401 // reading DDL for trigger
402
2cbb173f 403 fTriggerTimer.Start(kFALSE);
404
a19e2543 405 AliMUONSubEventTrigger* subEventTrigger = new AliMUONSubEventTrigger();
ced309a5 406 AliMUONScalerEventTrigger* scalerEvent = 0x0;
407
a19e2543 408 AliMUONGlobalTrigger* globalTrigger = 0x0;
409 AliMUONLocalTrigger* localTrigger = new AliMUONLocalTrigger();
410
411
ced309a5 412 //Int_t kDDLHeaderSize = fDDLTrigger->GetHeaderSize();
a19e2543 413 // we dont need this, as size of ddl data is same for triger and no trigger
414
ced309a5 415 Int_t kDDLEnhanceHeaderSize = fDDLTrigger->GetHeaderLength();
416 Int_t kRegHeaderSize = subEventTrigger->GetRegHeaderLength() ;
a19e2543 417
418 Int_t loCircuit, loStripX, loDev, loStripY, loLpt, loHpt;
419 Char_t loDecision;
420
421 UShort_t x1Pattern, x2Pattern, x3Pattern, x4Pattern;
422 UShort_t y1Pattern, y2Pattern, y3Pattern, y4Pattern;
423
a19e2543 424 // loop over the two ddl's
425 for(Int_t iDDL = 0; iDDL < 2; iDDL++) { //DDL loop
426
c837da58 427 rawReader->Reset();
a19e2543 428 rawReader->Select(0XA,iDDL,iDDL); //Select the DDL file to be read
429
430 rawReader->ReadHeader();
431
ced309a5 432 Int_t totalDataWord = rawReader->GetDataSize(); // in bytes
433 UInt_t *buffer = new UInt_t[totalDataWord/4];
a19e2543 434
ced309a5 435 rawReader->ReadNext((UChar_t*)buffer, totalDataWord);
a19e2543 436
437 Int_t index = 0;
ced309a5 438 fDDLTrigger->SetDDLWord(buffer[index++]);
439
440 if(fDDLTrigger->GetEventType() == 2) {
441 fScalerEvent = kTRUE;
442 scalerEvent = new AliMUONScalerEventTrigger();
443 } else
444 fScalerEvent = kFALSE;
445
446 if(fScalerEvent) {
447 // 6 DARC scaler words
448 memcpy(scalerEvent->GetDarcScalers(), &buffer[index], scalerEvent->GetDarcScalerLength()*4);
449 index += scalerEvent->GetDarcScalerLength();
450 }
451
452 // 4 words of global board input + Global board output
453 memcpy(fDDLTrigger->GetGlobalInput(), &buffer[index], (kDDLEnhanceHeaderSize-1)*4);
454 index += kDDLEnhanceHeaderSize - 1; // kind tricky cos scaler info in-between Darc header
a19e2543 455
ced309a5 456 if(fScalerEvent) {
457 // 10 Global scaler words
458 memcpy(scalerEvent->GetGlobalScalers(), &buffer[index], scalerEvent->GetGlobalScalerLength()*4);
459 index += scalerEvent->GetGlobalScalerLength();
460 }
a19e2543 461
462 // fill global trigger information
463 globalTrigger = GetGlobalTriggerPattern(fDDLTrigger->GetGlobalOuput());
464 fMUONData->AddGlobalTrigger(*globalTrigger);
ced309a5 465
a19e2543 466 // 8 regional boards
467 for (Int_t iReg = 0; iReg < 8; iReg++) { //loop over regeonal card
468
ced309a5 469 memcpy(subEventTrigger->GetRegHeader(), &buffer[index], kRegHeaderSize*4);
470 index += kRegHeaderSize;
a19e2543 471
ced309a5 472 // 11 regional scaler word
473 if(fScalerEvent) {
474 memcpy(scalerEvent->GetRegScalers(), &buffer[index], scalerEvent->GetRegScalerLength()*4);
475 index += scalerEvent->GetRegScalerLength();
476 }
a19e2543 477
478 // 16 local cards per regional board
479 for (Int_t iLoc = 0; iLoc < 16; iLoc++) { //loop over local card
480
481 Int_t iLocIndex = index;
482
483 // 5 word trigger information
484 for(Int_t iData = 0; iData < 5 ;iData++ ){
485 subEventTrigger->SetLocalData(buffer[index++],5*iLoc+iData); //read local data
486 }
487
488 if(buffer[iLocIndex] > 0) {
489
490 loCircuit = (Int_t)subEventTrigger->GetLocalId(iLoc)+ 16*iReg + 128*iDDL;
ced309a5 491 loStripX = (Int_t)subEventTrigger->GetXPos(iLoc);
492 loStripY = (Int_t)subEventTrigger->GetYPos(iLoc);
493 loDev = (Int_t)subEventTrigger->GetXDev(iLoc);
a19e2543 494
495 // fill local trigger
496 localTrigger->SetLoCircuit(loCircuit);
497 localTrigger->SetLoStripX(loStripX );
498 localTrigger->SetLoStripY(loStripY);
499 localTrigger->SetLoDev(loDev);
500
501 loDecision = subEventTrigger->GetLocalDec(iLoc);
502 loLpt = loDecision & 0x3;
503 loHpt = (loDecision >> 2) & 0x3;
504
505 // fill local trigger
506 localTrigger->SetLoLpt(loLpt);
507 localTrigger->SetLoHpt(loHpt);
508
509 //getting pattern from subvent
510 x1Pattern = subEventTrigger->GetX1(iLoc);
511 x2Pattern = subEventTrigger->GetX2(iLoc);
512 x3Pattern = subEventTrigger->GetX3(iLoc);
513 x4Pattern = subEventTrigger->GetX4(iLoc);
514
515 y1Pattern = subEventTrigger->GetY1(iLoc);
516 y2Pattern = subEventTrigger->GetY2(iLoc);
517 y3Pattern = subEventTrigger->GetY3(iLoc);
518 y4Pattern = subEventTrigger->GetY4(iLoc);
519
520 // fill local trigger
521 localTrigger->SetX1Pattern(x1Pattern);
522 localTrigger->SetX2Pattern(x2Pattern);
523 localTrigger->SetX3Pattern(x3Pattern);
524 localTrigger->SetX4Pattern(x4Pattern);
525
526 localTrigger->SetY1Pattern(y1Pattern);
527 localTrigger->SetY2Pattern(y2Pattern);
528 localTrigger->SetY3Pattern(y3Pattern);
529 localTrigger->SetY4Pattern(y4Pattern);
530 fMUONData->AddLocalTrigger(*localTrigger);
531
ced309a5 532 } // if buffer[] > 0
533
534 // 45 regional scaler word
535 if(fScalerEvent) {
536 memcpy(scalerEvent->GetLocalScalers(), &buffer[index], scalerEvent->GetLocalScalerLength()*4);
537 index += scalerEvent->GetLocalScalerLength();
a19e2543 538 }
539
540 } // local card loop
541
542 } // regional card loop
543
544 delete [] buffer;
545 } // DDL loop
546
547 delete subEventTrigger;
548 delete globalTrigger;
549 delete localTrigger;
550
2cbb173f 551 delete scalerEvent;
ced309a5 552
2cbb173f 553 fTriggerTimer.Stop();
a19e2543 554 return kTRUE;
555
556}
557//____________________________________________________________________
558AliMUONGlobalTrigger* AliMUONRawReader::GetGlobalTriggerPattern(Int_t gloTrigPat) const
559{
560 // global trigger pattern calculation
561
562 Int_t globalSinglePlus[3]; // tot num of single plus
563 Int_t globalSingleMinus[3]; // tot num of single minus
564 Int_t globalSingleUndef[3]; // tot num of single undefined
565 Int_t globalPairUnlike[3]; // tot num of unlike-sign pairs
566 Int_t globalPairLike[3]; // tot num of like-sign pairs
567
568
569 for (Int_t i = 0; i < 3; i++) {
c14da03e 570
571 globalSinglePlus[i] = (gloTrigPat >> i) & 0x1;
572 globalSingleMinus[i] = (gloTrigPat >> (i+3)) & 0x1;
573 globalSingleUndef[i] = (gloTrigPat >> (i+6)) & 0x1;
574 globalPairUnlike[i] = (gloTrigPat >> (i+9)) & 0x1;
575 globalPairLike[i] = (gloTrigPat >> (i+12)) & 0x1;
a19e2543 576 }
577
578 return (new AliMUONGlobalTrigger(globalSinglePlus, globalSingleMinus,
579 globalSingleUndef, globalPairUnlike,
580 globalPairLike));
581
582}
583