]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRawWriter.cxx
In AliMUONRawWriter:
[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
3d1463c8 18//-----------------------------------------------------------------------------
9265505b 19/// \class AliMUONRawWriter
20/// MUON Raw Data generaton in ALICE-MUON
5cab551d 21/// Raw data structure could be found in Alice-note.
9265505b 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)
31/// Ch. Finck, July 04
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
35/// Ch. Finck, Jan. 06
36/// Using bus itr in DDL instead of simple incrementation
37/// treat correctly the DDL & buspatch for station 3.
38/// Using informations from AliMUONTriggerCrateStore for
39/// empty slots and non-notified cards in trigger crates.
40/// Ch. Finck, August 06.
5cab551d 41/// Using AliMpDDLStore::GetBusPatchId.
78649106 42///
43/// \author Ch. Finck, Feb. 07.
3d1463c8 44//-----------------------------------------------------------------------------
5cab551d 45
a19e2543 46
2cbb173f 47#include "AliMUONRawWriter.h"
a19e2543 48
344ef20f 49#include "AliMUONBlockHeader.h"
50#include "AliMUONBusStruct.h"
a19e2543 51#include "AliMUONConstants.h"
2cf44ef3 52#include "AliMUONDarcHeader.h"
48217459 53#include "AliMUONVDigit.h"
54#include "AliMUONVDigitStore.h"
344ef20f 55#include "AliMUONDspHeader.h"
2cbb173f 56#include "AliMUONGlobalTrigger.h"
344ef20f 57#include "AliMUONLocalStruct.h"
2cbb173f 58#include "AliMUONLocalTrigger.h"
a844d67f 59#include "AliMUONLocalTriggerBoard.h"
4798d385 60#include "AliMUONRegionalTrigger.h"
344ef20f 61#include "AliMUONRegHeader.h"
2ed86fc4 62
48217459 63#include "AliMUONVTriggerStore.h"
134d2964 64#include "AliCodeTimer.h"
9265505b 65
88a58c26 66#include "AliMpCDB.h"
e5ced899 67#include "AliMpDDLStore.h"
68#include "AliMpDDL.h"
92c23b09 69#include "AliMpRegionalTrigger.h"
2ed86fc4 70#include "AliMpTriggerCrate.h"
71#include "AliMpLocalBoard.h"
e5ced899 72#include "AliMpDetElement.h"
2cbb173f 73#include "AliMpDEManager.h"
344ef20f 74#include "AliMpExMap.h"
1c80232e 75#include "AliMpConstants.h"
a19e2543 76#include "AliMpPlaneType.h"
9265505b 77#include "AliMpSegmentation.h"
2cbb173f 78#include "AliMpStationType.h"
a19e2543 79#include "AliMpVSegmentation.h"
9265505b 80
344ef20f 81#include "AliRawReader.h"
0014fbe8 82#include "AliRawDataHeaderSim.h"
9265505b 83#include "AliBitPacking.h"
84#include "AliDAQ.h"
85#include "AliLog.h"
86
a844d67f 87#include "TObjArray.h"
1c80232e 88#include "TStopwatch.h"
c4860b34 89#include <Riostream.h>
2cf44ef3 90
9265505b 91/// \cond CLASSIMP
a19e2543 92ClassImp(AliMUONRawWriter) // Class implementation in ROOT context
9265505b 93/// \endcond
ced309a5 94
a19e2543 95//__________________________________________________________________________
48217459 96AliMUONRawWriter::AliMUONRawWriter()
9f5dcca3 97 : TObject(),
9f5dcca3 98 fBlockHeader(new AliMUONBlockHeader()),
99 fDspHeader(new AliMUONDspHeader()),
9f5dcca3 100 fDarcHeader(new AliMUONDarcHeader()),
101 fRegHeader(new AliMUONRegHeader()),
102 fLocalStruct(new AliMUONLocalStruct()),
5cab551d 103 fDDLStore(AliMpDDLStore::Instance()),
9f5dcca3 104 fScalerEvent(kFALSE),
0014fbe8 105 fHeader(0x0),
48217459 106 fBufferSize((((43*AliMpConstants::ManuNofChannels() + 4)*5 + 10)*5 + 8)*2),
107 fBuffer(new Int_t [fBufferSize])
a19e2543 108{
9265505b 109 /// Standard Constructor
110
2cbb173f 111 AliDebug(1,"Standard ctor");
a19e2543 112
84ceeb06 113 // setting data key to default value (only for writting)
114 fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey());
115 fDspHeader->SetDataKey(fDspHeader->GetDefaultDataKey());
84ceeb06 116
88a58c26 117 // Load mapping
118 if ( ! fDDLStore ) {
119 if ( ! AliMpCDB::LoadDDLStore() ) {
120 AliFatal("Could not access mapping from OCDB !");
121 }
122 fDDLStore = AliMpDDLStore::Instance();
123 }
a19e2543 124}
125
a19e2543 126//__________________________________________________________________________
127AliMUONRawWriter::~AliMUONRawWriter(void)
128{
9265505b 129 /// Destructor
130
2cbb173f 131 AliDebug(1,"dtor");
132
2cf44ef3 133 delete fBlockHeader;
134 delete fDspHeader;
2cf44ef3 135 delete fDarcHeader;
136 delete fRegHeader;
137 delete fLocalStruct;
48217459 138 delete[] fBuffer;
a19e2543 139}
2cbb173f 140
2ed86fc4 141//____________________________________________________________________
142void AliMUONRawWriter::LocalWordPacking(UInt_t& word, UInt_t locId, UInt_t locDec,
143 UInt_t trigY, UInt_t posY, UInt_t posX,
144 UInt_t sdevX, UInt_t devX)
145{
146/// pack local trigger word
147
148 AliBitPacking::PackWord(locId,word,19,22); //card id number in crate
149 AliBitPacking::PackWord(locDec,word,15,18);
150 AliBitPacking::PackWord(trigY,word,14,14);
151 AliBitPacking::PackWord(posY,word,10,13);
152 AliBitPacking::PackWord(sdevX,word,9,9);
153 AliBitPacking::PackWord(devX,word,5,8);
154 AliBitPacking::PackWord(posX,word,0,4);
155
156}
157
a19e2543 158//____________________________________________________________________
57e2ad1a 159Int_t AliMUONRawWriter::Digits2Raw(const AliMUONVDigitStore* digitStore,
160 const AliMUONVTriggerStore* triggerStore)
a19e2543 161{
9265505b 162 /// convert digits of the current event to raw data
163
99c136e1 164 AliCodeTimerAuto("",0)
48217459 165
a19e2543 166 Int_t idDDL;
1d81a83f 167 Char_t name[255];
a19e2543 168
344ef20f 169 // tracking chambers
170
48217459 171 if ( digitStore )
172 {
dd0be8a7 173 AliCodeTimerAuto("for Tracker",1)
1d81a83f 174
630711ed 175 AliMpExMap busPatchMap;
1d81a83f 176
48217459 177 Int_t nDDLs = AliDAQ::NumberOfDdls("MUONTRK");
178
179 Int_t nofBusPatches(0);
180
181 for (Int_t iDDL = 0; iDDL < nDDLs; ++iDDL )
182 {
183 AliMpDDL* ddl = fDDLStore->GetDDL(iDDL);
184 nofBusPatches += ddl->GetNofBusPatches();
185 }
186
187 busPatchMap.SetSize(nofBusPatches);
188
189 Digits2BusPatchMap(*digitStore,busPatchMap);
1d81a83f 190
48217459 191 for (Int_t iDDL = 0; iDDL < nDDLs; ++iDDL )
192 {
193 WriteTrackerDDL(busPatchMap,iDDL);
194 }
195 AliDebug(1,"Tracker written");
a19e2543 196 }
197
48217459 198 if ( triggerStore )
199 {
70d92702 200 AliCodeTimerAuto("for Trigger",1)
a19e2543 201
48217459 202 // trigger chambers
203
b672bf31 204 AliFstream* file[2];
48217459 205
206 // open files
207 idDDL = 0;// MUTR
208 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
b672bf31 209 file[0] = new AliFstream(name);
48217459 210
211 idDDL = 1;// MUTR
212 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
b672bf31 213 file[1] = new AliFstream(name);
48217459 214
215 WriteTriggerDDL(*triggerStore,file);
216
217 // reset and close
b672bf31 218 delete file[0];
219 delete file[1];
48217459 220
221 AliDebug(1,"Trigger written");
222 }
344ef20f 223
a19e2543 224 return kTRUE;
225}
2cbb173f 226
48217459 227//______________________________________________________________________________
228void
229AliMUONRawWriter::Digits2BusPatchMap(const AliMUONVDigitStore& digitStore,
230 AliMpExMap& busPatchMap)
a19e2543 231{
48217459 232 /// Create bus patch structures corresponding to digits in the store
233
99c136e1 234 AliCodeTimerAuto("",0)
2cbb173f 235
84aac932 236 static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
48217459 237
2cf44ef3 238 // DDL event one per half chamber
48217459 239
2cf44ef3 240 // raw data
a19e2543 241 Char_t parity = 0x4;
242 UShort_t manuId = 0;
243 UChar_t channelId = 0;
244 UShort_t charge = 0;
245 Int_t busPatchId = 0;
630711ed 246 Int_t currentBusPatchId = -1;
a19e2543 247 UInt_t word;
2cf44ef3 248
630711ed 249 AliMUONBusStruct* busStruct(0x0);
250
48217459 251 TIter next(digitStore.CreateTrackerIterator());
252 AliMUONVDigit* digit;
253
254 while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
255 {
256 charge = digit->ADC();
257 if ( charge > kMAXADC )
258 {
259 // This is most probably an error in the digitizer (which should insure
260 // the adc is below kMAXADC), so make it a (non-fatal) error indeed.
a3eb0a94 261 AliError(Form("adc value %d above 0x%x for DE %d . Setting to 0x%x. Digit is:",
262 charge,kMAXADC,digit->DetElemId(),kMAXADC));
48217459 263 StdoutToAliError(digit->Print());
264 charge = kMAXADC;
265 }
266
267 // inverse mapping
268 busPatchId = GetBusPatch(*digit);
2cf44ef3 269
48217459 270 if (busPatchId<0) continue;
271
272 if ( digit->ManuId() > 0x7FF ||
273 digit->ManuChannel() > 0x3F )
274 {
275 StdoutToAliError(digit->Print(););
276 AliFatal("ManuId,ManuChannel are invalid for the digit above.");
277 }
278
279 manuId = ( digit->ManuId() & 0x7FF ); // 11 bits
280 channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits
281
282 //packing word
283 word = 0;
284 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
285 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
286 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
287
288 // parity word
289 parity = word & 0x1;
290 for (Int_t i = 1; i <= 30; ++i)
291 {
292 parity ^= ((word >> i) & 0x1);
293 }
294 AliBitPacking::PackWord((UInt_t)parity,word,31,31);
630711ed 295
296 if ( currentBusPatchId != busPatchId )
297 {
298 busStruct =
299 static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
300 currentBusPatchId = busPatchId;
301 }
48217459 302
303 if (!busStruct)
304 {
305 busStruct = new AliMUONBusStruct;
306 busStruct->SetDataKey(busStruct->GetDefaultDataKey());
307 busStruct->SetBusPatchId(busPatchId);
308 busStruct->SetLength(0);
309 busPatchMap.Add(busPatchId,busStruct);
310 }
311
312 // set sub Event
313 busStruct->AddData(word);
314 }
315}
2cf44ef3 316
48217459 317//______________________________________________________________________________
318void
319AliMUONRawWriter::WriteTrackerDDL(AliMpExMap& busPatchMap, Int_t iDDL)
320{
321 /// Write DDL file for one tracker DDL
322
344ef20f 323 // buffer size (max'ed out)
324 // (((43 manus max per bus patch *64 channels + 4 bus patch words) * 5 bus patch
325 // + 10 dsp words)*5 dsps + 8 block words)*2 blocks
48217459 326
99c136e1 327 AliCodeTimerAuto("",0)
a19e2543 328
0014fbe8 329 if (fHeader == 0x0) {
330 AliError("Raw data header must be set");
331 return;
332 }
48217459 333 memset(fBuffer,0,fBufferSize*sizeof(Int_t));
344ef20f 334
48217459 335 AliMpDDL* ddl = fDDLStore->GetDDL(iDDL);
336 Int_t iDspMax = ddl->GetMaxDsp();
337 Int_t iBusPerDSP[5]; //number of bus patches per DSP
338 ddl->GetBusPerDsp(iBusPerDSP);
339 Int_t busIter = 0;
344ef20f 340
48217459 341 Int_t totalDDLLength = 0;
a19e2543 342
48217459 343 Int_t index = 0;
344
345 // two blocks A and B per DDL
346 for (Int_t iBlock = 0; iBlock < 2; ++iBlock)
347 {
348 // block header
349 Int_t length = fBlockHeader->GetHeaderLength();
350 memcpy(&fBuffer[index],fBlockHeader->GetHeader(),length*4);
351 Int_t indexBlk = index;
352 index += length;
344ef20f 353
48217459 354 // 5 DSP's max per block
355 for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp)
356 {
357 // DSP header
bf0d3528 358 Int_t dspHeaderLength = fDspHeader->GetHeaderLength();
359 memcpy(&fBuffer[index],fDspHeader->GetHeader(),dspHeaderLength*4);
48217459 360 Int_t indexDsp = index;
bf0d3528 361 index += dspHeaderLength;
344ef20f 362
48217459 363 // 5 buspatches max per DSP
364 for (Int_t i = 0; i < iBusPerDSP[iDsp]; ++i)
365 {
366 Int_t iBusPatch = ddl->GetBusPatchId(busIter++);
344ef20f 367
48217459 368 // iteration over bus patch in DDL
369 if (iBusPatch == -1)
370 {
371 AliWarning(Form("Error in bus itr in DDL %d\n", iDDL));
372 continue;
344ef20f 373 }
374
48217459 375 AliMUONBusStruct* busStructPtr = static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(iBusPatch));
344ef20f 376
48217459 377 // check if buspatchid has digit
378 if (busStructPtr)
379 {
380 // add bus patch structure header
bf0d3528 381 Int_t busHeaderLength = busStructPtr->GetHeaderLength();
382 memcpy(&fBuffer[index],busStructPtr->GetHeader(),busHeaderLength*4);
383 index += busHeaderLength;
48217459 384
385 // add bus patch data
bf0d3528 386 Int_t busLength = busStructPtr->GetLength();
387 memcpy(&fBuffer[index],busStructPtr->GetData(),busLength*4);
388 index += busLength;
48217459 389 }
390 else
391 {
392 // writting anyhow buspatch structure (empty ones)
393 fBuffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size
394 fBuffer[index++] = busStructPtr->GetHeaderLength(); // header length
395 fBuffer[index++] = 0; // raw data length
396 fBuffer[index++] = iBusPatch; // bus patch
397 }
398 } // bus patch
344ef20f 399
48217459 400 // check if totalLength even
401 // set padding word in case
402 // Add one word 0xBEEFFACE at the end of DSP structure
403 Int_t totalDspLength = index - indexDsp;
404 if ((totalDspLength % 2) == 1)
405 {
406 fBuffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1;
407 fBuffer[index++] = fDspHeader->GetDefaultPaddingWord();
408 totalDspLength++;
409 }
344ef20f 410
1c66abf3 411 Int_t dspLength = totalDspLength - fDspHeader->GetHeaderLength();
344ef20f 412
48217459 413 fBuffer[indexDsp+1] = totalDspLength; // dsp total length
414 fBuffer[indexDsp+2] = dspLength; // data length
344ef20f 415
48217459 416 } // dsp
417
418 Int_t totalBlkLength = index - indexBlk;
419 Int_t blkLength = totalBlkLength - fBlockHeader->GetHeaderLength();
1c66abf3 420 totalDDLLength += totalBlkLength;
48217459 421
422 fBuffer[indexBlk+1] = totalBlkLength; // total block length
423 fBuffer[indexBlk+2] = blkLength;
1c66abf3 424
48217459 425 } // block
344ef20f 426
1c66abf3 427 // add twice the end of CRT structure data key
428 // hope it's good placed (ChF)
429 fBuffer[index++] = fBlockHeader->GetDdlDataKey();
430 fBuffer[index++] = fBlockHeader->GetDdlDataKey();
431 totalDDLLength += 2;
432
48217459 433 // writting onto disk
434 // total length in bytes
435 // DDL header
0014fbe8 436
437 Int_t headerSize = sizeof(AliRawDataHeader)/4;
48217459 438
0014fbe8 439 fHeader->fSize = (totalDDLLength + headerSize) * 4;
48217459 440
b672bf31 441 AliFstream* file = new AliFstream(AliDAQ::DdlFileName("MUONTRK",iDDL));
48217459 442
0014fbe8 443 file->WriteBuffer((char*)fHeader,headerSize*4);
b672bf31 444 file->WriteBuffer((char*)fBuffer,sizeof(int)*index);
445 delete file;
a19e2543 446}
ced309a5 447
48217459 448//______________________________________________________________________________
449Int_t AliMUONRawWriter::GetBusPatch(const AliMUONVDigit& digit) const
344ef20f 450{
9265505b 451 /// Determine the BusPatch this digit belongs to.
452
5cab551d 453 return fDDLStore->GetBusPatchId(digit.DetElemId(),digit.ManuId());
344ef20f 454}
455
48217459 456//______________________________________________________________________________
b672bf31 457Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore, AliFstream* file[2])
a19e2543 458{
9265505b 459 /// Write trigger DDL
2cbb173f 460
99c136e1 461 AliCodeTimerAuto("",0)
48217459 462
0014fbe8 463 if (fHeader == 0x0) {
464 AliError("Raw data header must be set");
465 return 0;
466 }
467
a19e2543 468 // DDL event one per half chamber
a19e2543 469
2cf44ef3 470 // DDL header size
471 Int_t headerSize = sizeof(AliRawDataHeader)/4;
ced309a5 472
a19e2543 473 // global trigger for trigger pattern
48217459 474 AliMUONGlobalTrigger* gloTrg = triggerStore.Global();
344ef20f 475 if (!gloTrg)
476 {
344ef20f 477 return 0;
478 }
479
073695a9 480 Int_t gloTrigResp = gloTrg->GetGlobalResponse();
41a38dec 481 UInt_t *gloTrigInput = gloTrg->GetGlobalInput();
a19e2543 482
a19e2543 483 UInt_t word;
484 Int_t* buffer = 0;
485 Int_t index;
2ed86fc4 486 Int_t locCard;
1afc1008 487 UChar_t locDec, trigY, posY, posX, regOut;
bebe0279 488 UInt_t regInpLpt;
489 UInt_t regInpHpt;
490
1afc1008 491 UInt_t devX;
c4860b34 492 UChar_t sdevX;
1afc1008 493 UInt_t version = 1; // software version
494 UInt_t eventPhys = 1; // trigger type: 1 for physics, 0 for software
495 UInt_t serialNb = 0xF; // serial nb of card: all bits on for the moment
d622a0ec 496 Int_t globalFlag = 0; // set to 1 if global info present in DDL else set to 0
497
498 // size of headers
499 static const Int_t kDarcHeaderLength = fDarcHeader->GetDarcHeaderLength();
500 static const Int_t kGlobalHeaderLength = fDarcHeader->GetGlobalHeaderLength();
501 static const Int_t kDarcScalerLength = fDarcHeader->GetDarcScalerLength();
502 static const Int_t kGlobalScalerLength = fDarcHeader->GetGlobalScalerLength();
503 static const Int_t kRegHeaderLength = fRegHeader->GetHeaderLength();
504 static const Int_t kRegScalerLength = fRegHeader->GetScalerLength();
505 static const Int_t kLocHeaderLength = fLocalStruct->GetLength();
506 static const Int_t kLocScalerLength = fLocalStruct->GetScalerLength();
507
508 // [16(local)*6 words + 6 words]*8(reg) + 8 words = 824
509 static const Int_t kBufferSize = (16 * (kLocHeaderLength+1) + (kRegHeaderLength+1))* 8
510 + kDarcHeaderLength + kGlobalHeaderLength + 2;
511
512 // [16(local)*51 words + 16 words]*8(reg) + 8 + 10 + 8 words scaler event 6682 words
513 static const Int_t kScalerBufferSize = (16 * (kLocHeaderLength + kLocScalerLength +1) +
514 (kRegHeaderLength + kRegScalerLength +1))* 8 +
515 (kDarcHeaderLength + kDarcScalerLength +
516 kGlobalHeaderLength + kGlobalScalerLength + 2);
f4ee80d2 517 if(fScalerEvent) {
d622a0ec 518 eventPhys = 0; //set to generate scaler events
dd1cc6f0 519 fHeader->fWord2 |= (0x1 << 14); // set L1SwC bit on
f4ee80d2 520 }
ced309a5 521 if(fScalerEvent)
d622a0ec 522 buffer = new Int_t [kScalerBufferSize];
ced309a5 523 else
d622a0ec 524 buffer = new Int_t [kBufferSize];
ced309a5 525
a844d67f 526 // reset crate
a19e2543 527
528 // open DDL file, on per 1/2 chamber
48217459 529 for ( Int_t iDDL = 0; iDDL < 2; ++iDDL )
530 {
a19e2543 531 index = 0;
532
a19e2543 533 if (iDDL == 0) // suppose global info in DDL one
a19e2543 534 globalFlag = 1;
d622a0ec 535 else
536 globalFlag = 0;
ced309a5 537
d622a0ec 538 word = 0;
539 // set darc status word
540 // see AliMUONDarcHeader.h for details
541 AliBitPacking::PackWord((UInt_t)eventPhys,word,30,30);
542 AliBitPacking::PackWord((UInt_t)serialNb,word,20,23);
543 AliBitPacking::PackWord((UInt_t)globalFlag,word,10,10);
544 AliBitPacking::PackWord((UInt_t)version,word,12,19);
2cf44ef3 545 fDarcHeader->SetWord(word);
18d3ded7 546
d622a0ec 547 memcpy(&buffer[index], fDarcHeader->GetHeader(), (kDarcHeaderLength)*4);
bebe0279 548 index += kDarcHeaderLength;
a19e2543 549
073695a9 550 // no global input for the moment....
41a38dec 551 if (iDDL == 0) {
552 fDarcHeader->SetGlobalOutput(gloTrigResp);
553 for (Int_t ii = 0; ii < 4; ii++) {
554 fDarcHeader->SetGlobalInput(gloTrigInput[ii],ii);
555 }
556 } else {
557 fDarcHeader->SetGlobalOutput(0);
558 }
ced309a5 559
560 if (fScalerEvent) {
561 // 6 DARC scaler words
d622a0ec 562 memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),kDarcScalerLength*4);
bebe0279 563 index += kDarcScalerLength;
ced309a5 564 }
2cf44ef3 565 // end of darc word
566 buffer[index++] = fDarcHeader->GetEndOfDarc();
ced309a5 567
568 // 4 words of global board input + Global board output
d622a0ec 569 memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (kGlobalHeaderLength)*4);
bebe0279 570 index += kGlobalHeaderLength;
ced309a5 571
572 if (fScalerEvent) {
573 // 10 Global scaler words
eb3886c8 574 memcpy(&buffer[index], fDarcHeader->GetGlobalScalers(), kGlobalScalerLength*4);
bebe0279 575 index += kGlobalScalerLength;
ced309a5 576 }
a19e2543 577
2cf44ef3 578 // end of global word
579 buffer[index++] = fDarcHeader->GetEndOfGlobal();
92c23b09 580 const AliMpRegionalTrigger* reg = AliMpDDLStore::Instance()->GetRegionalTrigger();
2cf44ef3 581
92c23b09 582 Int_t nCrate = reg->GetNofTriggerCrates()/2;
a19e2543 583 // 8 regional cards per DDL
92c23b09 584 for (Int_t iReg = 0; iReg < nCrate; ++iReg) {
a19e2543 585
2ed86fc4 586 // crate info
587 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->GetTriggerCrate(iDDL, iReg);
a844d67f 588
589 if (!crate)
2ed86fc4 590 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
a844d67f 591
4798d385 592 // regional info tree, make sure that no reg card missing
92c23b09 593 AliMUONRegionalTrigger* regTrg = triggerStore.FindRegional(crate->GetId());
594 if (!regTrg)
595 AliError(Form("Missing regional board %d in trigger Store\n", crate->GetId()));
596
a19e2543 597 // Regional card header
598 word = 0;
00f56161 599
600 // set darc status word
601 fRegHeader->SetDarcWord(word);
602
4798d385 603 regOut = regTrg->GetOutput();
f4e2cda2 604 regInpLpt = regTrg->GetLocalOutput(0);
605 regInpHpt = regTrg->GetLocalOutput(1);
4798d385 606
d622a0ec 607 // fill darc word, not darc status for the moment (empty)
608 //see AliMUONRegHeader.h for details
609 AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31);
46df197d 610 AliBitPacking::PackWord((UInt_t)serialNb,word,20,25);
611 AliBitPacking::PackWord((UInt_t)version,word,8,15);
612 AliBitPacking::PackWord((UInt_t)crate->GetId(),word,16,19);
4798d385 613 AliBitPacking::PackWord((UInt_t)regOut,word,0,7);
2cf44ef3 614 fRegHeader->SetWord(word);
d622a0ec 615
bebe0279 616
617 // fill header later, need local response
618 Int_t indexReg = index;
619 index += kRegHeaderLength;
a19e2543 620
ced309a5 621 // 11 regional scaler word
622 if (fScalerEvent) {
bebe0279 623 memcpy(&buffer[index], fRegHeader->GetScalers(), kRegScalerLength*4);
624 index += kRegScalerLength;
ced309a5 625 }
a19e2543 626
2cf44ef3 627 // end of regional word
628 buffer[index++] = fRegHeader->GetEndOfReg();
a844d67f 629
a19e2543 630 // 16 local card per regional board
4798d385 631 // UShort_t localMask = 0x0;
c4860b34 632
92c23b09 633 Int_t nLocalBoard = AliMpConstants::LocalBoardNofChannels();
634
635 for (Int_t iLoc = 0; iLoc < nLocalBoard; iLoc++) {
c4860b34 636
2ed86fc4 637 // slot zero for Regional card
638 Int_t localBoardId = crate->GetLocalBoardId(iLoc);
639
640 if (localBoardId) { // if not empty slot
641 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(localBoardId);
642
643 if (localBoard->IsNotified()) {// if notified board
644 AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(localBoardId);
645
646 locCard = locTrg->LoCircuit();
647 locDec = locTrg->GetLoDecision();
648 trigY = locTrg->LoTrigY();
649 posY = locTrg->LoStripY();
650 posX = locTrg->LoStripX();
651 devX = locTrg->LoDev();
652 sdevX = locTrg->LoSdev();
653
654 AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n",
655 locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
656 //packing word
657 word = 0;
658 LocalWordPacking(word, (UInt_t)iLoc, (UInt_t)locDec, (UInt_t)trigY, (UInt_t)posY,
659 (UInt_t)posX, (UInt_t)sdevX, (UInt_t)devX);
660
661 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
662 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
663 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
664 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
665 buffer[index++] = (Int_t)word; // data word
666
667
668 }
669 // fill copy card X-Y inputs from the notified cards
670 if (localBoard->GetInputXfrom() && localBoard->GetInputYfrom())
671 {
672 // not triggered
673 locDec = 0; trigY = 1; posY = 15;
674 posX = 0; devX = 0; sdevX = 1;
675 LocalWordPacking(word, (UInt_t)iLoc, (UInt_t)locDec, (UInt_t)trigY, (UInt_t)posY,
676 (UInt_t)posX, (UInt_t)sdevX, (UInt_t)devX);
677
678 Int_t localFromId = localBoard->GetInputXfrom();
679 AliMUONLocalTrigger* locTrgfrom = triggerStore.FindLocal(localFromId);
680
681 buffer[index++] = 0; // copy only X3-4 & Y1-4
682 buffer[index++] = (locTrgfrom->GetX3Pattern() | (locTrgfrom->GetX4Pattern() << 16));
683 buffer[index++] = (locTrgfrom->GetY1Pattern() | (locTrgfrom->GetY2Pattern() << 16));
684 buffer[index++] = (locTrgfrom->GetY3Pattern() | (locTrgfrom->GetY4Pattern() << 16));
685 buffer[index++] = word;
a844d67f 686 }
2ed86fc4 687
688 } else {
689 // fill with 10CDEAD word for empty slots
690 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
691 buffer[index++] = fLocalStruct->GetDisableWord();
692 }// condition localBoard
693
694 // 45 regional scaler word
695 if (fScalerEvent) {
696 memcpy(&buffer[index], fLocalStruct->GetScalers(), kLocScalerLength*4);
697 index += kLocScalerLength;
698 }
c4860b34 699
2ed86fc4 700 // end of local structure words
701 buffer[index++] = fLocalStruct->GetEndOfLocal();
c4860b34 702
2cf44ef3 703 } // local card
bebe0279 704 // fill regional header with local output
f4e2cda2 705 fRegHeader->SetInput(regInpLpt, 0);
bebe0279 706 fRegHeader->SetInput(regInpHpt, 1);
bebe0279 707 memcpy(&buffer[indexReg],fRegHeader->GetHeader(),kRegHeaderLength*4);
c4860b34 708
a19e2543 709 } // Regional card
710
a19e2543 711
712 // writting onto disk
a844d67f 713 // write DDL's
0014fbe8 714 fHeader->fSize = (index + headerSize) * 4;// total length in bytes
715 file[iDDL]->WriteBuffer((char*)fHeader,headerSize*4);
b672bf31 716 file[iDDL]->WriteBuffer((char*)buffer,sizeof(int)*index);
a19e2543 717
718 }
719 delete[] buffer;
720
ced309a5 721 return kTRUE;
a19e2543 722}
48217459 723
84ceeb06 724//____________________________________________________________________
725void AliMUONRawWriter::SetScalersNumbers()
726{
9265505b 727 /// set numbers for scaler events for trigger headers
728 /// since this is provided by the experiment
729 /// put dummy numbers to check the monitoring
84ceeb06 730
731 fDarcHeader->SetScalersNumbers();
732 fRegHeader->SetScalersNumbers();
733 fLocalStruct->SetScalersNumbers();
734
735 fScalerEvent = kTRUE;
736}
a844d67f 737