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