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