/* $Id$ */
+//-----------------------------------------------------------------------------
/// \class AliMUONRawWriter
/// MUON Raw Data generaton in ALICE-MUON
/// Raw data structure could be found in Alice-note.
/// Using AliMpDDLStore::GetBusPatchId.
///
/// \author Ch. Finck, Feb. 07.
+//-----------------------------------------------------------------------------
#include "AliMUONRawWriter.h"
#include "AliMUONLocalTriggerBoard.h"
#include "AliMUONRegionalTrigger.h"
#include "AliMUONRegHeader.h"
-#include "AliMUONTriggerCrate.h"
-#include "AliMUONTriggerCrateStore.h"
+
#include "AliMUONVTriggerStore.h"
-#include "AliMUONStopwatchGroup.h"
-#include "AliMUONStopwatchGroupElement.h"
+#include "AliCodeTimer.h"
#include "AliMpDDLStore.h"
#include "AliMpDDL.h"
+#include "AliMpRegionalTrigger.h"
+#include "AliMpTriggerCrate.h"
+#include "AliMpLocalBoard.h"
#include "AliMpDetElement.h"
#include "AliMpDEManager.h"
#include "AliMpExMap.h"
#include "AliMpVSegmentation.h"
#include "AliRawReader.h"
+#include "AliRawDataHeaderSim.h"
#include "AliBitPacking.h"
#include "AliDAQ.h"
#include "AliLog.h"
fRegHeader(new AliMUONRegHeader()),
fLocalStruct(new AliMUONLocalStruct()),
fDDLStore(AliMpDDLStore::Instance()),
- fCrateManager(new AliMUONTriggerCrateStore()),
fScalerEvent(kFALSE),
- fHeader(),
- fTimers(new AliMUONStopwatchGroup),
+ fHeader(0x0),
fBufferSize((((43*AliMpConstants::ManuNofChannels() + 4)*5 + 10)*5 + 8)*2),
fBuffer(new Int_t [fBufferSize])
{
fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey());
fDspHeader->SetDataKey(fDspHeader->GetDefaultDataKey());
- // Crate manager
- fCrateManager->ReadFromFile();
-
}
//__________________________________________________________________________
delete fDarcHeader;
delete fRegHeader;
delete fLocalStruct;
- delete fCrateManager;
- AliInfo("Timers:");
- fTimers->Print();
- delete fTimers;
delete[] fBuffer;
}
+//____________________________________________________________________
+void AliMUONRawWriter::LocalWordPacking(UInt_t& word, UInt_t locId, UInt_t locDec,
+ UInt_t trigY, UInt_t posY, UInt_t posX,
+ UInt_t sdevX, UInt_t devX)
+{
+/// pack local trigger word
+
+ AliBitPacking::PackWord(locId,word,19,22); //card id number in crate
+ AliBitPacking::PackWord(locDec,word,15,18);
+ AliBitPacking::PackWord(trigY,word,14,14);
+ AliBitPacking::PackWord(posY,word,10,13);
+ AliBitPacking::PackWord(sdevX,word,9,9);
+ AliBitPacking::PackWord(devX,word,5,8);
+ AliBitPacking::PackWord(posX,word,0,4);
+
+}
+
//____________________________________________________________________
Int_t AliMUONRawWriter::Digits2Raw(AliMUONVDigitStore* digitStore,
AliMUONVTriggerStore* triggerStore)
{
/// convert digits of the current event to raw data
- AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::Digits2Raw");
+ AliCodeTimerAuto("")
Int_t idDDL;
Char_t name[255];
if ( digitStore )
{
- AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::Digits2Raw for Tracker");
+ AliCodeTimerAuto("for Tracker")
- AliMpExMap busPatchMap(true);
+ AliMpExMap busPatchMap;
Int_t nDDLs = AliDAQ::NumberOfDdls("MUONTRK");
if ( triggerStore )
{
- AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::Digits2Raw for Trigger");
+ AliCodeTimerAuto("for Trigger")
// trigger chambers
- FILE* file[2];
+ AliFstream* file[2];
// open files
idDDL = 0;// MUTR
strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
- file[0] = fopen(name,"w");
+ file[0] = new AliFstream(name);
idDDL = 1;// MUTR
strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
- file[1] = fopen(name,"w");
+ file[1] = new AliFstream(name);
WriteTriggerDDL(*triggerStore,file);
// reset and close
- fclose(file[0]);
- fclose(file[1]);
+ delete file[0];
+ delete file[1];
AliDebug(1,"Trigger written");
}
{
/// Create bus patch structures corresponding to digits in the store
- AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::Digits2BusPatchMap");
+ AliCodeTimerAuto("")
static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
UChar_t channelId = 0;
UShort_t charge = 0;
Int_t busPatchId = 0;
+ Int_t currentBusPatchId = -1;
UInt_t word;
+ AliMUONBusStruct* busStruct(0x0);
+
TIter next(digitStore.CreateTrackerIterator());
AliMUONVDigit* digit;
{
// This is most probably an error in the digitizer (which should insure
// the adc is below kMAXADC), so make it a (non-fatal) error indeed.
- AliError(Form("adc value %d above %x for DE %d . Setting to %x. Digit is:",
- digit->DetElemId(),charge,kMAXADC,kMAXADC));
+ AliError(Form("adc value %d above 0x%x for DE %d . Setting to 0x%x. Digit is:",
+ charge,kMAXADC,digit->DetElemId(),kMAXADC));
StdoutToAliError(digit->Print());
charge = kMAXADC;
}
parity ^= ((word >> i) & 0x1);
}
AliBitPacking::PackWord((UInt_t)parity,word,31,31);
-
- AliMUONBusStruct* busStruct =
- static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
+
+ if ( currentBusPatchId != busPatchId )
+ {
+ busStruct =
+ static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
+ currentBusPatchId = busPatchId;
+ }
if (!busStruct)
{
// (((43 manus max per bus patch *64 channels + 4 bus patch words) * 5 bus patch
// + 10 dsp words)*5 dsps + 8 block words)*2 blocks
- AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::WriteTrackerDDL");
+ AliCodeTimerAuto("")
+ if (fHeader == 0x0) {
+ AliError("Raw data header must be set");
+ return;
+ }
memset(fBuffer,0,fBufferSize*sizeof(Int_t));
AliMpDDL* ddl = fDDLStore->GetDDL(iDDL);
for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp)
{
// DSP header
- Int_t length = fDspHeader->GetHeaderLength();
- memcpy(&fBuffer[index],fDspHeader->GetHeader(),length*4);
+ Int_t dspHeaderLength = fDspHeader->GetHeaderLength();
+ memcpy(&fBuffer[index],fDspHeader->GetHeader(),dspHeaderLength*4);
Int_t indexDsp = index;
- index += length;
+ index += dspHeaderLength;
// 5 buspatches max per DSP
for (Int_t i = 0; i < iBusPerDSP[iDsp]; ++i)
if (busStructPtr)
{
// add bus patch structure header
- Int_t length = busStructPtr->GetHeaderLength();
- memcpy(&fBuffer[index],busStructPtr->GetHeader(),length*4);
- index += length;
+ Int_t busHeaderLength = busStructPtr->GetHeaderLength();
+ memcpy(&fBuffer[index],busStructPtr->GetHeader(),busHeaderLength*4);
+ index += busHeaderLength;
// add bus patch data
- length = busStructPtr->GetLength();
- memcpy(&fBuffer[index],busStructPtr->GetData(),length*4);
- index += length;
+ Int_t busLength = busStructPtr->GetLength();
+ memcpy(&fBuffer[index],busStructPtr->GetData(),busLength*4);
+ index += busLength;
}
else
{
totalDspLength++;
}
- Int_t dspLength = totalDspLength - fDspHeader->GetHeaderLength();
+ Int_t dspLength = totalDspLength - fDspHeader->GetHeaderLength();
fBuffer[indexDsp+1] = totalDspLength; // dsp total length
fBuffer[indexDsp+2] = dspLength; // data length
Int_t totalBlkLength = index - indexBlk;
Int_t blkLength = totalBlkLength - fBlockHeader->GetHeaderLength();
- totalDDLLength += totalBlkLength;
+ totalDDLLength += totalBlkLength;
fBuffer[indexBlk+1] = totalBlkLength; // total block length
fBuffer[indexBlk+2] = blkLength;
-
+
} // block
+ // add twice the end of CRT structure data key
+ // hope it's good placed (ChF)
+ fBuffer[index++] = fBlockHeader->GetDdlDataKey();
+ fBuffer[index++] = fBlockHeader->GetDdlDataKey();
+ totalDDLLength += 2;
+
// writting onto disk
// total length in bytes
// DDL header
- Int_t headerSize = sizeof(fHeader)/4;
+
+ Int_t headerSize = sizeof(AliRawDataHeader)/4;
- fHeader.fSize = (totalDDLLength + headerSize) * 4;
+ fHeader->fSize = (totalDDLLength + headerSize) * 4;
- FILE* file = fopen(AliDAQ::DdlFileName("MUONTRK",iDDL),"w");
+ AliFstream* file = new AliFstream(AliDAQ::DdlFileName("MUONTRK",iDDL));
- fwrite((char*)(&fHeader),headerSize*4,1,file);
- fwrite(fBuffer,sizeof(int),index,file);
- fclose(file);
+ file->WriteBuffer((char*)fHeader,headerSize*4);
+ file->WriteBuffer((char*)fBuffer,sizeof(int)*index);
+ delete file;
}
//______________________________________________________________________________
}
//______________________________________________________________________________
-Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore, FILE* file[2])
+Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore, AliFstream* file[2])
{
/// Write trigger DDL
- AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::WriteTriggerDDL");
+ AliCodeTimerAuto("")
+
+ if (fHeader == 0x0) {
+ AliError("Raw data header must be set");
+ return 0;
+ }
// DDL event one per half chamber
}
Int_t gloTrigResp = gloTrg->GetGlobalResponse();
+ UInt_t *gloTrigInput = gloTrg->GetGlobalInput();
UInt_t word;
Int_t* buffer = 0;
Int_t index;
- Int_t iLocCard, locCard;
+ Int_t locCard;
UChar_t locDec, trigY, posY, posX, regOut;
UInt_t regInpLpt;
UInt_t regInpHpt;
(kRegHeaderLength + kRegScalerLength +1))* 8 +
(kDarcHeaderLength + kDarcScalerLength +
kGlobalHeaderLength + kGlobalScalerLength + 2);
- if(fScalerEvent)
+ if(fScalerEvent) {
eventPhys = 0; //set to generate scaler events
-
+ fHeader->fWord2 |= (0x1 << 14); // set L1SwC bit on
+ }
if(fScalerEvent)
buffer = new Int_t [kScalerBufferSize];
else
index += kDarcHeaderLength;
// no global input for the moment....
- if (iDDL == 0)
- fDarcHeader->SetGlobalOutput(gloTrigResp);
- else
- fDarcHeader->SetGlobalOutput(0);
+ if (iDDL == 0) {
+ fDarcHeader->SetGlobalOutput(gloTrigResp);
+ for (Int_t ii = 0; ii < 4; ii++) {
+ fDarcHeader->SetGlobalInput(gloTrigInput[ii],ii);
+ }
+ } else {
+ fDarcHeader->SetGlobalOutput(0);
+ }
if (fScalerEvent) {
// 6 DARC scaler words
// end of global word
buffer[index++] = fDarcHeader->GetEndOfGlobal();
+ const AliMpRegionalTrigger* reg = AliMpDDLStore::Instance()->GetRegionalTrigger();
+ Int_t nCrate = reg->GetNofTriggerCrates()/2;
// 8 regional cards per DDL
- for (Int_t iReg = 0; iReg < 8; iReg++) {
+ for (Int_t iReg = 0; iReg < nCrate; ++iReg) {
- // crate info
- AliMUONTriggerCrate* crate = fCrateManager->Crate(iDDL, iReg);
+ // crate info
+ AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->GetTriggerCrate(iDDL, iReg);
if (!crate)
- AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
+ AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
// regional info tree, make sure that no reg card missing
- AliMUONRegionalTrigger* regTrg = triggerStore.FindRegional(iReg+iDDL*8);
-
+ AliMUONRegionalTrigger* regTrg = triggerStore.FindRegional(crate->GetId());
+ if (!regTrg)
+ AliError(Form("Missing regional board %d in trigger Store\n", crate->GetId()));
+
// Regional card header
word = 0;
// fill darc word, not darc status for the moment (empty)
//see AliMUONRegHeader.h for details
AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31);
- AliBitPacking::PackWord((UInt_t)serialNb,word,19,24);
- AliBitPacking::PackWord((UInt_t)version,word,16,23);
- AliBitPacking::PackWord((UInt_t)iReg,word,15,18);
+ AliBitPacking::PackWord((UInt_t)serialNb,word,20,25);
+ AliBitPacking::PackWord((UInt_t)version,word,8,15);
+ AliBitPacking::PackWord((UInt_t)crate->GetId(),word,16,19);
AliBitPacking::PackWord((UInt_t)regOut,word,0,7);
fRegHeader->SetWord(word);
// end of regional word
buffer[index++] = fRegHeader->GetEndOfReg();
- TObjArray *boards = crate->Boards();
-
-
// 16 local card per regional board
// UShort_t localMask = 0x0;
- for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
-
- // slot zero for Regional card
- AliMUONLocalTriggerBoard* localBoard = (AliMUONLocalTriggerBoard*)boards->At(iLoc+1);
-
- if (localBoard) { // if not empty slot
-
- if ((iLocCard = localBoard->GetNumber()) != 0) {// if notified board
-
- AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(iLocCard);
-
- locCard = locTrg->LoCircuit();
-
- locDec = locTrg->GetLoDecision();
- trigY = locTrg->LoTrigY();
- posY = locTrg->LoStripY();
- posX = locTrg->LoStripX();
- devX = locTrg->LoDev();
- sdevX = locTrg->LoSdev();
-
- AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n",
- locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
- //packing word
- word = 0;
- AliBitPacking::PackWord((UInt_t)iLoc,word,19,22); //card id number in crate
- AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
- AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
- AliBitPacking::PackWord((UInt_t)posY,word,10,13);
- AliBitPacking::PackWord((UInt_t)sdevX,word,9,9);
- AliBitPacking::PackWord((UInt_t)devX,word,5,8);
- AliBitPacking::PackWord((UInt_t)posX,word,0,4);
-
- buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
- buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
- buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
- buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
- buffer[index++] = (Int_t)word; // data word
- } else {// number!=0
- // fill with 10CDEAD word for 'non-notified' slots
- for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
- buffer[index++] = fLocalStruct->GetDisableWord();
- }
- } else {
- // fill with 10CDEAD word for empty slots
- for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
- buffer[index++] = fLocalStruct->GetDisableWord();
- }// condition localBoard
+ Int_t nLocalBoard = AliMpConstants::LocalBoardNofChannels();
+
+ for (Int_t iLoc = 0; iLoc < nLocalBoard; iLoc++) {
- // 45 regional scaler word
- if (fScalerEvent) {
- memcpy(&buffer[index], fLocalStruct->GetScalers(), kLocScalerLength*4);
- index += kLocScalerLength;
+ // slot zero for Regional card
+ Int_t localBoardId = crate->GetLocalBoardId(iLoc);
+
+ if (localBoardId) { // if not empty slot
+ AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(localBoardId);
+
+ if (localBoard->IsNotified()) {// if notified board
+ AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(localBoardId);
+
+ locCard = locTrg->LoCircuit();
+ locDec = locTrg->GetLoDecision();
+ trigY = locTrg->LoTrigY();
+ posY = locTrg->LoStripY();
+ posX = locTrg->LoStripX();
+ devX = locTrg->LoDev();
+ sdevX = locTrg->LoSdev();
+
+ AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n",
+ locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
+ //packing word
+ word = 0;
+ LocalWordPacking(word, (UInt_t)iLoc, (UInt_t)locDec, (UInt_t)trigY, (UInt_t)posY,
+ (UInt_t)posX, (UInt_t)sdevX, (UInt_t)devX);
+
+ buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
+ buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
+ buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
+ buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
+ buffer[index++] = (Int_t)word; // data word
+
+
+ }
+ // fill copy card X-Y inputs from the notified cards
+ if (localBoard->GetInputXfrom() && localBoard->GetInputYfrom())
+ {
+ // not triggered
+ locDec = 0; trigY = 1; posY = 15;
+ posX = 0; devX = 0; sdevX = 1;
+ LocalWordPacking(word, (UInt_t)iLoc, (UInt_t)locDec, (UInt_t)trigY, (UInt_t)posY,
+ (UInt_t)posX, (UInt_t)sdevX, (UInt_t)devX);
+
+ Int_t localFromId = localBoard->GetInputXfrom();
+ AliMUONLocalTrigger* locTrgfrom = triggerStore.FindLocal(localFromId);
+
+ buffer[index++] = 0; // copy only X3-4 & Y1-4
+ buffer[index++] = (locTrgfrom->GetX3Pattern() | (locTrgfrom->GetX4Pattern() << 16));
+ buffer[index++] = (locTrgfrom->GetY1Pattern() | (locTrgfrom->GetY2Pattern() << 16));
+ buffer[index++] = (locTrgfrom->GetY3Pattern() | (locTrgfrom->GetY4Pattern() << 16));
+ buffer[index++] = word;
}
+
+ } else {
+ // fill with 10CDEAD word for empty slots
+ for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
+ buffer[index++] = fLocalStruct->GetDisableWord();
+ }// condition localBoard
+
+ // 45 regional scaler word
+ if (fScalerEvent) {
+ memcpy(&buffer[index], fLocalStruct->GetScalers(), kLocScalerLength*4);
+ index += kLocScalerLength;
+ }
- // end of local structure words
- buffer[index++] = fLocalStruct->GetEndOfLocal();
+ // end of local structure words
+ buffer[index++] = fLocalStruct->GetEndOfLocal();
} // local card
// fill regional header with local output
// writting onto disk
// write DDL's
- fHeader.fSize = (index + headerSize) * 4;// total length in bytes
- fwrite((char*)(&fHeader),headerSize*4,1,file[iDDL]);
- fwrite(buffer,sizeof(int),index,file[iDDL]);
+ fHeader->fSize = (index + headerSize) * 4;// total length in bytes
+ file[iDDL]->WriteBuffer((char*)fHeader,headerSize*4);
+ file[iDDL]->WriteBuffer((char*)buffer,sizeof(int)*index);
}
delete[] buffer;