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