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