]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRawWriter.cxx
New file; like tpc_gui.C but sets-up pad-row noise supression data needed for politic...
[u/mrichter/AliRoot.git] / MUON / AliMUONRawWriter.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
da8d4b6d 16/* $Id$ */
17
a19e2543 18////////////////////////////////////
19//
ced309a5 20// MUON Raw Data generaton in ALICE-MUON
a19e2543 21// This class version 3 (further details could be found in Alice-note)
22//
23// Implemented non-constant buspatch numbers for tracking
24// with correct DDL id (first guess)
25// (Ch. Finck, dec 2005)
26//
27// Digits2Raw:
28// Generates raw data for MUON tracker and finally for trigger
29// Using real mapping (inverse) for tracker
30// For trigger there is no mapping (mapping could be found in AliMUONTriggerCircuit)
2cf44ef3 31// Ch. Finck, July 04
ced309a5 32// Use memcpy instead of assignment elt by elt
33// Introducing variable DSP numbers, real manu numbers per buspatch for st12
34// Implemented scaler event for Trigger
2cf44ef3 35// Ch. Finck, Jan. 06
a19e2543 36//
37////////////////////////////////////
38
2cbb173f 39#include "AliMUONRawWriter.h"
a19e2543 40
a19e2543 41#include "AliBitPacking.h"
2cf44ef3 42#include "AliRawReader.h"
a19e2543 43#include "AliLog.h"
a19e2543 44#include "AliMUON.h"
a19e2543 45#include "AliMUONConstants.h"
2cf44ef3 46
47#include "AliMUONDarcHeader.h"
48#include "AliMUONRegHeader.h"
49#include "AliMUONLocalStruct.h"
50#include "AliMUONDspHeader.h"
51#include "AliMUONBlockHeader.h"
52
2cbb173f 53#include "AliMUONData.h"
54#include "AliMUONDigit.h"
2cbb173f 55#include "AliMUONGlobalTrigger.h"
56#include "AliMUONLocalTrigger.h"
2cf44ef3 57
2cbb173f 58#include "AliMpBusPatch.h"
59#include "AliMpDEManager.h"
60#include "AliMpPad.h"
a19e2543 61#include "AliMpPlaneType.h"
2cbb173f 62#include "AliMpSegFactory.h"
63#include "AliMpStationType.h"
a19e2543 64#include "AliMpVSegmentation.h"
2cf44ef3 65
2cbb173f 66#include "TClonesArray.h"
2cf44ef3 67
a19e2543 68ClassImp(AliMUONRawWriter) // Class implementation in ROOT context
ced309a5 69
70Int_t AliMUONRawWriter::fgManuPerBusSwp1B[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 224, 232};
71Int_t AliMUONRawWriter::fgManuPerBusSwp1NB[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 225, 233};
72
73Int_t AliMUONRawWriter::fgManuPerBusSwp2B[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 226, 246};
74Int_t AliMUONRawWriter::fgManuPerBusSwp2NB[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 227, 245};
75
76
a19e2543 77//__________________________________________________________________________
2cbb173f 78AliMUONRawWriter::AliMUONRawWriter(AliMUONData* data)
79: TObject(),
80 fScalerEvent(kFALSE)
a19e2543 81{
2cf44ef3 82 //
a19e2543 83 // Standard Constructor
2cf44ef3 84 //
2cbb173f 85 AliDebug(1,"Standard ctor");
86
a19e2543 87 // initialize container
a19e2543 88 fMUONData = data;
89
90 // initialize array
2cf44ef3 91 fBusArray = new TClonesArray("AliMUONBusStruct",1000);
92 fBusArray->SetOwner(kTRUE);
a19e2543 93
94 // ddl pointer
2cf44ef3 95 fBlockHeader = new AliMUONBlockHeader();
96 fDspHeader = new AliMUONDspHeader();
97 fBusStruct = new AliMUONBusStruct();
98
99 fDarcHeader = new AliMUONDarcHeader();
100 fRegHeader = new AliMUONRegHeader();
101 fLocalStruct = new AliMUONLocalStruct();
a19e2543 102
103 fBusPatchManager = new AliMpBusPatch();
104 fBusPatchManager->ReadBusPatchFile();
2cbb173f 105
106 fSegFactory = new AliMpSegFactory();
107
108 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
109 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
110 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
111
a19e2543 112}
113
114//__________________________________________________________________________
115AliMUONRawWriter::AliMUONRawWriter()
116 : TObject(),
117 fMUONData(0),
2cf44ef3 118 fBlockHeader(0),
119 fDspHeader(0),
120 fBusStruct(0),
121 fDarcHeader(0),
122 fRegHeader(0),
123 fLocalStruct(0),
ced309a5 124 fBusPatchManager(0),
2cbb173f 125 fScalerEvent(kFALSE),
126 fSegFactory(0x0)
a19e2543 127{
2cf44ef3 128 //
a19e2543 129 // Default Constructor
2cf44ef3 130 //
2cbb173f 131 AliDebug(1,"Default ctor");
132 fFile[0] = fFile[1] = 0x0;
133 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
134 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
135 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
a19e2543 136}
137
138//_______________________________________________________________________
139AliMUONRawWriter::AliMUONRawWriter (const AliMUONRawWriter& rhs)
140 : TObject(rhs)
141{
2cf44ef3 142 //
143 // Protected copy constructor
144 //
a19e2543 145 AliFatal("Not implemented.");
146}
147
148//_______________________________________________________________________
149AliMUONRawWriter &
150AliMUONRawWriter::operator=(const AliMUONRawWriter& rhs)
151{
2cf44ef3 152 //
153 // Protected assignement operator
154 //
a19e2543 155 if (this == &rhs) return *this;
156
157 AliFatal("Not implemented.");
158
159 return *this;
160}
161
162//__________________________________________________________________________
163AliMUONRawWriter::~AliMUONRawWriter(void)
164{
2cf44ef3 165 //
166 // Destructor
167 //
2cbb173f 168 AliDebug(1,"dtor");
169
2cf44ef3 170 delete fBusArray;
2cbb173f 171
2cf44ef3 172 delete fBlockHeader;
173 delete fDspHeader;
174 delete fBusStruct;
175 delete fDarcHeader;
176 delete fRegHeader;
177 delete fLocalStruct;
a19e2543 178
2cbb173f 179 delete fBusPatchManager;
180
181 delete fSegFactory;
182
183 AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
184 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
185 AliInfo(Form(" Execution time for MUON tracker (mapping calls part) "
186 ": R:%.2fs C:%.2fs",
187 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
188 AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
189 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
a19e2543 190}
2cbb173f 191
a19e2543 192//____________________________________________________________________
193Int_t AliMUONRawWriter::Digits2Raw()
194{
2cf44ef3 195 //
196 // convert digits of the current event to raw data
197 //
a19e2543 198 Int_t idDDL;
199 Char_t name[20];
200
2cbb173f 201 fMUONData->GetLoader()->LoadDigits("READ");
a19e2543 202
203 fMUONData->SetTreeAddress("D,GLT");
204
2cbb173f 205 fMUONData->ResetDigits();
206 fMUONData->ResetTrigger();
207
208 // This will get both tracker and trigger digits.
209 fMUONData->GetDigits();
210
a19e2543 211 // tracking chambers
212
2cbb173f 213 for (Int_t ich = 0; ich < AliMUONConstants::NTrackingCh(); ich++)
214 {
a19e2543 215 // open files
216 idDDL = ich * 2 + 0x900; // official number for MUON
217 sprintf(name, "MUON_%d.ddl",idDDL);
218 fFile[0] = fopen(name,"w");
219
220 idDDL = (ich * 2) + 1 + 0x900;
221 sprintf(name, "MUON_%d.ddl",idDDL);
222 fFile[1] = fopen(name,"w");
2cbb173f 223
a19e2543 224 WriteTrackerDDL(ich);
225
226 // reset and close
227 fclose(fFile[0]);
228 fclose(fFile[1]);
a19e2543 229 }
230
231 // trigger chambers
232
233 // open files
234 idDDL = 0xA00;// official number for MUTR
235 sprintf(name, "MUTR_%d.ddl",idDDL);
236 fFile[0] = fopen(name,"w");
237
238 idDDL = 0xA00 + 1;
239 sprintf(name, "MUTR_%d.ddl",idDDL);
240 fFile[1] = fopen(name,"w");
241
242 WriteTriggerDDL();
243
244 // reset and close
245 fclose(fFile[0]);
246 fclose(fFile[1]);
2cbb173f 247
248 fMUONData->ResetDigits();
249 fMUONData->ResetTrigger();
250 fMUONData->GetLoader()->UnloadDigits();
a19e2543 251
252 return kTRUE;
253}
2cbb173f 254
a19e2543 255//____________________________________________________________________
256Int_t AliMUONRawWriter::WriteTrackerDDL(Int_t iCh)
257{
258 // writing DDL for tracker
259 // used inverse mapping
2cf44ef3 260 //
2cbb173f 261 fTrackerTimer.Start(kFALSE);
262
2cf44ef3 263
84aac932 264 static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
2cf44ef3 265
a19e2543 266 // resets
267 TClonesArray* muonDigits = 0;
2cf44ef3 268
269 fBusArray->Delete();
270
a19e2543 271
272 //
2cf44ef3 273 TArrayI nbInBus;
274
275 nbInBus.Set(5000);
276
a19e2543 277 nbInBus.Reset();
278
279 // DDL header
2cf44ef3 280 Int_t headerSize = sizeof(fHeader)/4;
281
282 // DDL event one per half chamber
a19e2543 283
2cf44ef3 284 // raw data
a19e2543 285 Char_t parity = 0x4;
286 UShort_t manuId = 0;
287 UChar_t channelId = 0;
288 UShort_t charge = 0;
289 Int_t busPatchId = 0;
a19e2543 290 UInt_t word;
2cf44ef3 291
292 // block length
293 Int_t totalBlkLength;
294 Int_t blkLength;
295
296 // total DDL length
297 Int_t totalDDLLength;
298
299 // indexes
a19e2543 300 Int_t index;
301 Int_t indexDsp;
302 Int_t indexBlk;
2cf44ef3 303
304 // digits
305 Int_t nEntries = 0;
306 Int_t* buffer = 0;
a19e2543 307 Int_t padX;
308 Int_t padY;
309 Int_t cathode = 0;
310 Int_t detElemId;
311 Int_t nDigits;
312
313 const AliMUONDigit* digit;
314
315 AliDebug(3, Form("WriteDDL chamber %d\n", iCh+1));
316
a19e2543 317 muonDigits = fMUONData->Digits(iCh);
318
319 nDigits = muonDigits->GetEntriesFast();
320 AliDebug(3,Form("ndigits = %d\n",nDigits));
321
322 // loop over digit
323 for (Int_t idig = 0; idig < nDigits; idig++) {
324
325 digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
326
327 padX = digit->PadX();
328 padY = digit->PadY();
ce13d60d 329 charge = digit->ADC();
84aac932 330 if ( charge > kMAXADC )
2cbb173f 331 {
332 // This is most probably an error in the digitizer (which should insure
84aac932 333 // the adc is below kMAXADC), so make it a (non-fatal) error indeed.
2cbb173f 334 AliError(Form("adc value %d above %x. Setting to %x",
84aac932 335 charge,kMAXADC,kMAXADC));
336 charge = kMAXADC;
2cbb173f 337 }
a19e2543 338 cathode = digit->Cathode();
339 detElemId = digit->DetElemId();
340
341 // inverse mapping
2cbb173f 342 busPatchId = GetBusPatch(*digit);
343 if (busPatchId<0) continue;
344
345 if ( digit->ManuId() > 0x7FF || digit->ManuId() < 0 ||
346 digit->ManuChannel() > 0x3F || digit->ManuChannel() < 0 )
347 {
348 StdoutToAliError(digit->Print(););
349 AliFatal("ManuId,ManuChannel are invalid for the digit above.");
350 }
351
352 manuId = ( digit->ManuId() & 0x7FF ); // 11 bits
353 channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits
2cf44ef3 354
355 AliDebug(3,Form("input IdDE %d busPatchId %d PadX %d PadY %d iCath %d \n",
a19e2543 356 detElemId, busPatchId, padX, padY, cathode));
2cf44ef3 357
a19e2543 358 AliDebug(3,Form("busPatchId %d, manuId %d channelId %d\n", busPatchId, manuId, channelId ));
2cf44ef3 359
a19e2543 360 //packing word
361 AliBitPacking::PackWord((UInt_t)parity,word,29,31);
362 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
363 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
364 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
365
366 // set sub Event
2cf44ef3 367 fBusStruct->SetLength(0);
368 fBusStruct->AddData(word);
369 fBusStruct->SetBusPatchId(busPatchId);
a19e2543 370
371 // storing the number of identical buspatches
372 nbInBus[busPatchId]++;
2cf44ef3 373 AddData(*fBusStruct);
374
a19e2543 375 }
376
377 // sorting by buspatch
2cf44ef3 378 fBusArray->Sort();
a19e2543 379
380 // gather datas from same bus patch
2cf44ef3 381 nEntries = fBusArray->GetEntriesFast();
a19e2543 382
2cf44ef3 383 for (Int_t i = 0; i < nEntries; i++) {
384 AliMUONBusStruct* temp = (AliMUONBusStruct*)fBusArray->At(i);
a19e2543 385 busPatchId = temp->GetBusPatchId();
386
387 // add bus patch header, length and total length managed by subevent class
388 temp->SetTriggerWord(0xdeadbeef);
2cf44ef3 389 for (Int_t j = 0; j < nbInBus[busPatchId]-1; j++) {
390 AliMUONBusStruct* temp1 = (AliMUONBusStruct*)fBusArray->At(++i);
a19e2543 391 temp->AddData(temp1->GetData(0));
2cf44ef3 392 fBusArray->RemoveAt(i) ;
a19e2543 393 }
394 }
2cf44ef3 395 fBusArray->Compress();
a19e2543 396
2cf44ef3 397 if (AliLog::GetGlobalDebugLevel() == 3) {
398 nEntries = fBusArray->GetEntriesFast();
399 for (Int_t i = 0; i < nEntries; i++) {
400 AliMUONBusStruct* temp = (AliMUONBusStruct*)fBusArray->At(i);
a19e2543 401 printf("busPatchid back %d\n",temp->GetBusPatchId());
2cf44ef3 402 for (Int_t j = 0; j < temp->GetLength(); j++) {
403 printf("manuId back %d, ",temp->GetManuId(j));
404 printf("channelId back %d, ",temp->GetChannelId(j));
405 printf("charge back %d\n",temp->GetCharge(j));
a19e2543 406 }
407 }
408 printf("\n");
409 }
410
411 // getting info for the number of buspatches
412 Int_t iBusPatch;
413 Int_t length;
414 Int_t iBusPerDSP[5];//number of bus patches per DSP
415 Int_t iDspMax; //number max of DSP per block
a19e2543 416 Int_t iFile = 0;
417 fBusPatchManager->GetDspInfo(iCh, iDspMax, iBusPerDSP);
418
419 TArrayI* vec = fBusPatchManager->GetBusfromDE((iCh+1)*100);
420
421 Int_t iBus0AtCh = vec->At(0); //get first bus patch id for a given ich
422
423 AliDebug(3,Form("iBus0AtCh %d", iBus0AtCh));
424
425 iBusPatch = iBus0AtCh - 1; // starting point for each chamber
426
2cf44ef3 427 // nEntries = fBusArray->GetEntriesFast();
428 AliMUONBusStruct* temp = 0x0;
429
a19e2543 430 // open DDL file, on per 1/2 chamber
2cf44ef3 431 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
432
433 totalDDLLength = 0;
434
a19e2543 435 // filling buffer
436 buffer = new Int_t [(2048+24)*50]; // 24 words in average for one buspatch and 2048 manu info at most
2cf44ef3 437
a19e2543 438 indexBlk = 0;
439 indexDsp = 0;
440 index = 0;
2cf44ef3 441
a19e2543 442 // two blocks A and B per DDL
2cf44ef3 443 for (Int_t iBlock = 0; iBlock < 2; iBlock++) {
444
a19e2543 445 // block header
2cf44ef3 446 length = fBlockHeader->GetHeaderLength();
447 memcpy(&buffer[index],fBlockHeader->GetHeader(),length*4);
a19e2543 448 indexBlk = index;
449 index += length;
2cf44ef3 450
a19e2543 451 // 5 DSP's max per block
2cf44ef3 452 for (Int_t iDsp = 0; iDsp < iDspMax; iDsp++) {
453
454 // DSP header
455 length = fDspHeader->GetHeaderLength();
456 memcpy(&buffer[index],fDspHeader->GetHeader(),length*4);
457 indexDsp = index;
458 index += length;
459
460 // 5 buspatches max per DSP
461 for (Int_t i = 0; i < iBusPerDSP[iDsp]; i++) {
462
463 iBusPatch++;
464 if ((fBusPatchManager->GetDDLfromBus(iBusPatch) % 2) == 0) // comparing to DDL file
465 iFile = 1;
466 else
467 iFile = 0;
468
469 AliDebug(3,Form("iCh %d iDDL %d iBlock %d iDsp %d busPatchId %d", iCh, iDDL, iBlock, iDsp, iBusPatch));
470
471 nEntries = fBusArray->GetEntriesFast();
cd640dc7 472 busPatchId = -1;
2cf44ef3 473 for (Int_t iEntries = 0; iEntries < nEntries; iEntries++) { // method "bourrique"...
474 temp = (AliMUONBusStruct*)fBusArray->At(iEntries);
475 busPatchId = temp->GetBusPatchId();
476 if (busPatchId == iBusPatch) break;
477 busPatchId = -1;
478 AliDebug(3,Form("busPatchId %d", temp->GetBusPatchId()));
479 }
480
481 // check if buspatchid has digit
482 if (busPatchId != -1) {
483 // add bus patch structure
484 length = temp->GetHeaderLength();
485 memcpy(&buffer[index],temp->GetBusPatchHeader(),length*4);
486 index += length;
487 for (Int_t j = 0; j < temp->GetLength(); j++) {
488 buffer[index++] = temp->GetData(j);
489 AliDebug(3,Form("busPatchId %d, manuId %d channelId %d\n", temp->GetBusPatchId(),
490 temp->GetManuId(j), temp->GetChannelId(j) ));
491 }
492 // fBusArray->RemoveAt(iEntries);
493 // fBusArray->Compress();
494 } else {
495 // writting anyhow buspatch structure (empty ones)
496 buffer[index++] = 4; // total length
497 buffer[index++] = 0; // raw data length
498 buffer[index++] = iBusPatch; // bus patch
499 buffer[index++] = 0xdeadbeef; // trigger word
500 }
501 } // bus patch
502
503 buffer[indexDsp] = index - indexDsp; // dsp total length
504 buffer[indexDsp+1] = index - indexDsp - fDspHeader->GetHeaderLength();
505 if ((index - indexDsp) % 2 == 0) // event word
506 buffer[indexDsp+7] = 0;
507 else
508 buffer[indexDsp+7] = 1;
509
a19e2543 510 } // dsp
2cf44ef3 511
512 totalBlkLength = index - indexBlk;
513 blkLength = totalBlkLength - fBlockHeader->GetHeaderLength();
514 totalDDLLength += totalBlkLength;
515
516 buffer[indexBlk] = totalBlkLength; // total block length
517 buffer[indexBlk+1] = blkLength;
518
519 if ((totalBlkLength % 2) == 1) { //add padding word for 64bits transfert
520 buffer[indexBlk] += 1; // correct length for padding word
521 buffer[indexBlk+1] += 1;
522 totalDDLLength++;
523 index++;
524
525 Int_t indexCopy = indexBlk + fBlockHeader->GetHeaderLength();
526 Int_t *buf = new Int_t [blkLength];
527
528 memcpy(&buf[0], &buffer[indexCopy], blkLength*4);// copy in tmp buffer
529 memcpy(&buffer[indexCopy+1], &buf[0], blkLength*4); // re-copy buffer one elt shifted
530 delete [] buf;
531 buffer[indexCopy] = 0xDEAD; // mark padding word
532 } // padding condition
533
534 } // block
a19e2543 535
536 //writting onto disk
537 // write DDL 1 & 2
2cf44ef3 538 fHeader.fSize = (totalDDLLength + headerSize) * 4;// total length in bytes
539 fwrite((char*)(&fHeader),headerSize*4,1,fFile[iFile]);
a19e2543 540 fwrite(buffer,sizeof(int),index,fFile[iFile]);
2cf44ef3 541
a19e2543 542 delete[] buffer;
543 }
544
2cbb173f 545 fTrackerTimer.Stop();
a19e2543 546 return kTRUE;
547}
ced309a5 548
549//____________________________________________________________________
2cbb173f 550Int_t AliMUONRawWriter::GetBusPatch(const AliMUONDigit& digit)
ced309a5 551{
2cf44ef3 552 //
2cbb173f 553 // Determine the BusPatch this digit belongs to.
2cf44ef3 554 //
2cbb173f 555 fMappingTimer.Start(kFALSE);
556
ced309a5 557 Int_t* ptr = 0;
558
559 // information from digits
2cbb173f 560 Int_t detElemId = digit.DetElemId();
561
562 AliMpVSegmentation* seg =
563 fSegFactory->CreateMpSegmentationByElectronics(detElemId, digit.ManuId());
564
565 AliMpPlaneType plane = seg->PlaneType();
ced309a5 566
2cbb173f 567 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
ced309a5 568
2cbb173f 569 if ( stationType == kStation1 || stationType == kStation2 )
570 {
571 if (plane == kBendingPlane)
572 {
573 ptr = &fgManuPerBusSwp1B[0];
574 }
575 else
576 {
577 ptr = &fgManuPerBusSwp1NB[0];
ced309a5 578 }
579 }
2cbb173f 580 else
581 {
582 if (plane == kBendingPlane)
583 {
584 ptr = &fgManuPerBusSwp2B[0];
585 }
586 else
587 {
588 ptr = &fgManuPerBusSwp2NB[0];
589 }
ced309a5 590 }
591
ced309a5 592 // Getting buspatch id
2cbb173f 593 TArrayI* vec = fBusPatchManager->GetBusfromDE(detElemId);
ced309a5 594 Int_t pos = 0;
595
2cbb173f 596 Int_t m = ( digit.ManuId() & 0x3FF ); // remove bit 10
597 //FIXME : how can we remove that condition
598 // on the 10-th bit ? All the rest need not any knowledge about it,
599 // can't we find a way to get manu<->buspatch transparent to this too ?
600
601 if ( stationType == kStation1 || stationType == kStation2 )
602 {
ced309a5 603 for (Int_t i = 0; i < 12; i++)
2cbb173f 604 {
605 if (m >= *(ptr + pos++)) break;
606 }
607 }
608 else
609 {
ced309a5 610 // offset of 100 in manuId for following bus patch
2cbb173f 611 pos = m/100;
ced309a5 612 }
613
614 if (pos >(Int_t) vec->GetSize())
2cbb173f 615 {
616 AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n",
617 pos, (Int_t)vec->GetSize(), digit.ManuId(), detElemId));
618 AliError(Form("Chamber %s Plane %s manuId %d m %d",
619 StationTypeName(stationType).Data(),
620 PlaneTypeName(plane).Data(),
621 digit.ManuId(),
622 m));
623 return -1;
624 }
ced309a5 625
2cbb173f 626 Int_t busPatchId = vec->At(pos);
ced309a5 627
2cbb173f 628 fMappingTimer.Stop();
629
630 return busPatchId;
ced309a5 631}
632
a19e2543 633//____________________________________________________________________
634Int_t AliMUONRawWriter::WriteTriggerDDL()
635{
2cf44ef3 636 //
637 // Write trigger DDL
638 //
2cbb173f 639 fTriggerTimer.Start(kFALSE);
640
a19e2543 641 // DDL event one per half chamber
a19e2543 642
a19e2543 643 // stored local id number
644 TArrayI isFired(256);
645 isFired.Reset();
646
647
2cf44ef3 648 // DDL header size
649 Int_t headerSize = sizeof(AliRawDataHeader)/4;
ced309a5 650
a19e2543 651 TClonesArray* localTrigger;
652 TClonesArray* globalTrigger;
653 AliMUONGlobalTrigger* gloTrg;
654 AliMUONLocalTrigger* locTrg = 0x0;
655
a19e2543 656 // global trigger for trigger pattern
657 globalTrigger = fMUONData->GlobalTrigger();
658 gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
2cf44ef3 659 Int_t gloTrigPat = gloTrg->GetGlobalPattern();
a19e2543 660
661 // local trigger
662 localTrigger = fMUONData->LocalTrigger();
663
664 UInt_t word;
665 Int_t* buffer = 0;
666 Int_t index;
667 Int_t iEntries = 0;
668 Int_t iLocCard, locCard;
669 Char_t locDec, trigY, posY, posX,regOut;
670 Int_t devX;
671 Int_t version = 1; // software version
672 Int_t eventType = 1; // trigger type: 1 for physics ?
673 Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment
674 Int_t globalFlag = 1; // set to 2 if global info present in DDL else set to 1
675
ced309a5 676 if(fScalerEvent)
677 eventType = 2; //set to generate scaler events
678
a19e2543 679 Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
680 // stored the local card id that's fired
681 for (Int_t i = 0; i < nEntries; i++) {
682 locTrg = (AliMUONLocalTrigger*)localTrigger->At(i);
683 isFired[locTrg->LoCircuit()] = 1; // storing local boards with informations
684 }
685
686 if (!nEntries)
62c04fc3 687 AliInfo("No Trigger information available");
a19e2543 688
ced309a5 689 if(fScalerEvent)
00f56161 690 // [16(local)*51 words + 16 words]*8(reg) + 6 + 12 + 6 words scaler event 6672 words
691 buffer = new Int_t [6680];
ced309a5 692 else
00f56161 693 // [16(local)*6 words + 5 words]*8(reg) + 10 words = 818
694 buffer = new Int_t [818];
ced309a5 695
a19e2543 696
697 // open DDL file, on per 1/2 chamber
698 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
699
700 index = 0;
701
a19e2543 702 word = 0;
00f56161 703 // set darc status word
a19e2543 704 AliBitPacking::PackWord((UInt_t)iDDL+1,word,28,31); //see AliMUONDDLTrigger.h for details
705 AliBitPacking::PackWord((UInt_t)serialNb,word,24,27);
706 AliBitPacking::PackWord((UInt_t)version,word,16,23);
707 AliBitPacking::PackWord((UInt_t)eventType,word,12,15);
708
709 if (iDDL == 0) // suppose global info in DDL one
710 globalFlag = 2;
711 else
712 globalFlag = 1;
ced309a5 713
a19e2543 714 AliBitPacking::PackWord((UInt_t)globalFlag,word,8,11);
2cf44ef3 715 fDarcHeader->SetWord(word);
18d3ded7 716
717 memcpy(&buffer[index], fDarcHeader->GetHeader(), (fDarcHeader->GetDarcHeaderLength())*4);
718 index += fDarcHeader->GetDarcHeaderLength();
a19e2543 719
720 if (iDDL == 0)
2cf44ef3 721 fDarcHeader->SetGlobalOutput(gloTrigPat);// no global input for the moment....
a19e2543 722 else
2cf44ef3 723 fDarcHeader->SetGlobalOutput(0);
ced309a5 724
725 if (fScalerEvent) {
726 // 6 DARC scaler words
2cf44ef3 727 memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),fDarcHeader->GetDarcScalerLength()*4);
728 index += fDarcHeader->GetDarcScalerLength();
ced309a5 729 }
2cf44ef3 730 // end of darc word
731 buffer[index++] = fDarcHeader->GetEndOfDarc();
ced309a5 732
733 // 4 words of global board input + Global board output
18d3ded7 734 memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (fDarcHeader->GetGlobalHeaderLength())*4);
735 index += fDarcHeader->GetGlobalHeaderLength();
ced309a5 736
737 if (fScalerEvent) {
738 // 10 Global scaler words
2cf44ef3 739 memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], fDarcHeader->GetGlobalScalerLength()*4);
740 index += fDarcHeader->GetGlobalScalerLength();
ced309a5 741 }
a19e2543 742
2cf44ef3 743 // end of global word
744 buffer[index++] = fDarcHeader->GetEndOfGlobal();
745
a19e2543 746 // 8 regional cards per DDL
747 for (Int_t iReg = 0; iReg < 8; iReg++) {
748
a19e2543 749 // Regional card header
750 word = 0;
00f56161 751
752 // set darc status word
753 fRegHeader->SetDarcWord(word);
754
a19e2543 755 regOut = 0;
2cf44ef3 756 AliBitPacking::PackWord((UInt_t)serialNb,word,24,28); //see AliMUONLocalStruct.h for details
a19e2543 757 AliBitPacking::PackWord((UInt_t)version,word,16,23);
758 AliBitPacking::PackWord((UInt_t)iReg,word,12,15);
759 AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // whenever regional output will be implemented
760
2cf44ef3 761 fRegHeader->SetWord(word);
762 memcpy(&buffer[index],fRegHeader->GetHeader(),fRegHeader->GetHeaderLength()*4);
763 index += fRegHeader->GetHeaderLength();
a19e2543 764
ced309a5 765 // 11 regional scaler word
766 if (fScalerEvent) {
2cf44ef3 767 memcpy(&buffer[index], fRegHeader->GetScalers(), fRegHeader->GetScalerLength()*4);
768 index += fRegHeader->GetScalerLength();
ced309a5 769 }
a19e2543 770
2cf44ef3 771 // end of regional word
772 buffer[index++] = fRegHeader->GetEndOfReg();
773
a19e2543 774 // 16 local card per regional board
775 for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
776
777 iLocCard = iLoc + iReg*16 + iDDL*128;
778
779 if (isFired[iLocCard]) {
780 locTrg = (AliMUONLocalTrigger*)localTrigger->At(iEntries);
781 locCard = locTrg->LoCircuit();
782 locDec = locTrg->GetLoDecision();
783 trigY = 0;
784 posY = locTrg->LoStripY();
785 posX = locTrg->LoStripX();
786 devX = locTrg->LoDev();
787 AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n",
788 locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
789 } else { //no trigger (see PRR chpt 3.4)
2cf44ef3 790 locCard = -1; // not possible on 4 bits
a19e2543 791 locDec = 0;
792 trigY = 1;
793 posY = 15;
794 posX = 0;
795 devX = 0x8;
796 }
797
798 //packing word
799 word = 0;
800 AliBitPacking::PackWord((UInt_t)(iLocCard % 16),word,19,22); //card id number in crate
801 AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
802 AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
803 AliBitPacking::PackWord((UInt_t)posY,word,10,13);
804 AliBitPacking::PackWord((UInt_t)devX,word,5,9);
805 AliBitPacking::PackWord((UInt_t)posX,word,0,4);
806
807 if (locCard == iLocCard) {
808 // add local cards structure
809 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
810 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
811 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
812 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
813 buffer[index++] = (Int_t)word; // data word
814 if (iEntries < nEntries-1)
815 iEntries++;
816 } else {
817 buffer[index++] = 0; // 4 words for x1, x2, y1, y2
818 buffer[index++] = 0;
819 buffer[index++] = 0;
820 buffer[index++] = 0;
821 buffer[index++] = (Int_t)word; // data word
822
823 }
ced309a5 824 // 45 regional scaler word
825 if (fScalerEvent) {
2cf44ef3 826 memcpy(&buffer[index], fLocalStruct->GetScalers(), fLocalStruct->GetScalerLength()*4);
827 index += fLocalStruct->GetScalerLength();
ced309a5 828 }
829
2cf44ef3 830 // end of local structure words
831 buffer[index++] = fLocalStruct->GetEndOfLocal();
a19e2543 832
2cf44ef3 833 } // local card
a19e2543 834
835 } // Regional card
836
a19e2543 837
838 // writting onto disk
839 // write DDL 1
2cf44ef3 840 fHeader.fSize = (index + headerSize) * 4;// total length in bytes
841 fwrite((char*)(&fHeader),headerSize*4,1,fFile[iDDL]);
a19e2543 842 fwrite(buffer,sizeof(int),index,fFile[iDDL]);
843
844 }
845 delete[] buffer;
846
2cbb173f 847 fTriggerTimer.Stop();
848
ced309a5 849 return kTRUE;
a19e2543 850}