///
/// @file AliHLTMUONTriggerReconstructorComponent.cxx
/// @author Indranil Das <indra.das@saha.ac.in>, Artur Szostak <artursz@iafrica.com>
-/// @date
+/// @date 18 Sep 2007
/// @brief Implementation of the trigger DDL reconstructor component.
///
#include "AliHLTMUONConstants.h"
#include "AliHLTMUONUtils.h"
#include "AliHLTMUONDataBlockWriter.h"
+#include "AliRawDataHeader.h"
#include "AliCDBManager.h"
#include "AliCDBStorage.h"
#include "AliGeomManager.h"
AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() :
- AliHLTProcessor(),
+ AliHLTMUONProcessor(),
fTrigRec(NULL),
fDDL(-1),
fWarnForUnexpecedBlock(false),
- fSuppressPartialTrigs(false)
+ fStopOnOverflow(false),
+ fUseCrateId(true)
{
///
/// Default constructor.
fDDL = -1;
fWarnForUnexpecedBlock = false;
- fSuppressPartialTrigs = false;
+ fStopOnOverflow = false;
+ fUseCrateId = true;
const char* lutFileName = NULL;
const char* cdbPath = NULL;
Int_t run = -1;
bool useCDB = false;
+ bool suppressPartialTrigs = true;
+ bool tryRecover = false;
for (int i = 0; i < argc; i++)
{
unsigned long num = strtoul(argv[i+1], &cpErr, 0);
if (cpErr == NULL or *cpErr != '\0')
{
- HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1] );\
+ HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1]);
// Make sure to delete fTrigRec to avoid partial initialisation.
delete fTrigRec;
fTrigRec = NULL;
}
if (num < 21 or 22 < num)
{
- HLTError("The DDL ID number must be in the range [21..22].");
+ HLTError("The DDL number must be in the range [21..22].");
// Make sure to delete fTrigRec to avoid partial initialisation.
delete fTrigRec;
fTrigRec = NULL;
continue;
}
+ if (strcmp( argv[i], "-ddlid" ) == 0)
+ {
+ if ( argc <= i+1 )
+ {
+ HLTError("DDL equipment ID number not specified. It must be in the range [2816..2817]" );
+ // Make sure to delete fTrigRec to avoid partial initialisation.
+ delete fTrigRec;
+ fTrigRec = NULL;
+ return -EINVAL;
+ }
+
+ char* cpErr = NULL;
+ unsigned long num = strtoul(argv[i+1], &cpErr, 0);
+ if (cpErr == NULL or *cpErr != '\0')
+ {
+ HLTError("Cannot convert '%s' to a DDL equipment ID Number.", argv[i+1]);
+ // Make sure to delete fTrigRec to avoid partial initialisation.
+ delete fTrigRec;
+ fTrigRec = NULL;
+ return -EINVAL;
+ }
+ fDDL = AliHLTMUONUtils::EquipIdToDDLNumber(num); // Convert to DDL number in the range 0..21
+ if (fDDL < 20 or 21 < fDDL)
+ {
+ HLTError("The DDL equipment ID number must be in the range [2816..2817].");
+ // Make sure to delete fTrigRec to avoid partial initialisation.
+ delete fTrigRec;
+ fTrigRec = NULL;
+ return -EINVAL;
+ }
+
+ i++;
+ continue;
+ }
+
if (strcmp( argv[i], "-cdb" ) == 0)
{
useCDB = true;
if (strcmp( argv[i], "-suppress_partial_triggers" ) == 0)
{
- fSuppressPartialTrigs = true;
+ suppressPartialTrigs = true;
+ continue;
+ }
+
+ if (strcmp( argv[i], "-generate_partial_triggers" ) == 0)
+ {
+ suppressPartialTrigs = false;
+ continue;
+ }
+
+ if (strcmp( argv[i], "-stop_on_buffer_overflow" ) == 0)
+ {
+ fStopOnOverflow = true;
+ continue;
+ }
+
+ if (strcmp( argv[i], "-tryrecover" ) == 0)
+ {
+ tryRecover = true;
+ continue;
+ }
+
+ if (strcmp( argv[i], "-dont_use_crateid" ) == 0)
+ {
+ fUseCrateId = false;
continue;
}
int result = 0;
if (useCDB)
{
- HLTInfo("Loading lookup table information from CDB for DDL %d.", fDDL+1);
+ HLTInfo("Loading lookup table information from CDB for DDL %d (ID = %d).",
+ fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL)
+ );
if (fDDL == -1)
HLTWarning("DDL number not specified. The lookup table loaded from CDB will be empty!");
result = ReadCDB(cdbPath, run);
return result;
}
+ fTrigRec->SuppressPartialTriggers(suppressPartialTrigs);
+ fTrigRec->TryRecover(tryRecover);
+ fTrigRec->UseCrateId(fUseCrateId);
+
return 0;
}
// reconstruction algorithm on the raw data.
for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
{
-#ifdef __DEBUG
- char id[kAliHLTComponentDataTypefIDsize+1];
- for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
- id[i] = blocks[n].fDataType.fID[i];
- id[kAliHLTComponentDataTypefIDsize] = '\0';
- char origin[kAliHLTComponentDataTypefOriginSize+1];
- for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
- origin[i] = blocks[n].fDataType.fOrigin[i];
- origin[kAliHLTComponentDataTypefOriginSize] = '\0';
-#endif // __DEBUG
- HLTDebug("Handling block: %u, with fDataType.fID = '%s',"
- " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.",
- n, static_cast<char*>(id), static_cast<char*>(origin),
- blocks[n].fPtr, blocks[n].fSize
+ HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
+ n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fPtr, blocks[n].fSize
);
if (blocks[n].fDataType != AliHLTMUONConstants::DDLRawDataType()
{
// Log a message indicating that we got a data block that we
// do not know how to handle.
- char id[kAliHLTComponentDataTypefIDsize+1];
- for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
- id[i] = blocks[n].fDataType.fID[i];
- id[kAliHLTComponentDataTypefIDsize] = '\0';
- char origin[kAliHLTComponentDataTypefOriginSize+1];
- for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
- origin[i] = blocks[n].fDataType.fOrigin[i];
- origin[kAliHLTComponentDataTypefOriginSize] = '\0';
-
if (fWarnForUnexpecedBlock)
- HLTWarning("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X",
- static_cast<char*>(id), static_cast<char*>(origin), blocks[n].fSpecification
+ HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
+ DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification
);
else
- HLTDebug("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X",
- static_cast<char*>(id), static_cast<char*>(origin), blocks[n].fSpecification
+ HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
+ DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification
);
continue;
}
+ AliHLTInt32_t receivedDDL = AliHLTMUONUtils::SpecToDDLNumber(blocks[n].fSpecification);
if (fDDL != -1)
{
- bool ddl[22];
- AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
- if (not ddl[fDDL])
+ if (receivedDDL != fDDL)
{
- HLTWarning("Received raw data from an unexpected DDL.");
+ HLTWarning("Received raw data from DDL %d (ID = %d),"
+ " but expect data only from DDL %d (ID = %d).",
+ receivedDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(receivedDDL),
+ fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL)
+ );
}
}
AliHLTMUONTriggerRecordsBlockWriter block(outputPtr+totalSize, size-totalSize);
if (not block.InitCommonHeader())
{
- HLTError("There is not enough space in the output buffer for the new data block.",
+ HLTError("There is not enough space in the output buffer for the new data block."
" We require at least %ufTrigRec->GetkDDLHeaderSize() bytes, but have %u bytes left.",
sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType),
block.BufferSize()
break;
}
- AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
- AliHLTUInt32_t ddlRawDataSize = totalDDLSize - 8;
- AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) + 8;
+ AliHLTUInt32_t totalDDLSize = blocks[n].fSize;
+ if (totalDDLSize < sizeof(AliRawDataHeader))
+ {
+ HLTError("Raw data block %d is %d bytes in size and is too short to"
+ " possibly contain valid DDL raw data. We expect it to have"
+ " at least %d bytes for the commond data header.",
+ n, totalDDLSize, sizeof(AliRawDataHeader)
+ );
+ continue;
+ }
+ AliRawDataHeader* header = reinterpret_cast<AliRawDataHeader*>(blocks[n].fPtr);
+ AliHLTUInt32_t payloadSize = totalDDLSize - sizeof(AliRawDataHeader);
+ AliHLTUInt8_t* buffer = reinterpret_cast<AliHLTUInt8_t*>(header + 1);
AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries();
-
+
+ // Decode if this is a scalar event or not.
+ bool scalarEvent = ((header->GetL1TriggerMessage() & 0x1) == 0x1);
+
+ // Remember: the following does NOT change the mapping!
+ // It is just to generate unique trigger record IDs.
+ fTrigRec->SetDDL(receivedDDL);
+
bool runOk = fTrigRec->Run(
- buffer, ddlRawDataSize,
- block.GetArray(), nofTrigRec,
- fSuppressPartialTrigs
+ buffer, payloadSize, scalarEvent,
+ block.GetArray(), nofTrigRec
);
if (not runOk)
{
- HLTError("Error while processing of trigger DDL reconstruction algorithm.");
- size = totalSize; // Must tell the framework how much buffer space was used.
- return -EIO;
+ HLTError("Error while processing the trigger DDL reconstruction algorithm.");
+ if (not fTrigRec->OverflowedOutputBuffer()
+ or (fTrigRec->OverflowedOutputBuffer() and fStopOnOverflow)
+ )
+ {
+ size = totalSize; // Must tell the framework how much buffer space was used.
+ return -EIO;
+ }
}
// nofTrigRec should now contain the number of triggers actually found
return -EINVAL;
}
- Bool_t warn = kFALSE;
-
- AliCDBManager* cdbManager = AliCDBManager::Instance();
- if (cdbManager == NULL)
- {
- HLTError("CDB manager instance does not exist.");
- return -EIO;
- }
-
- const char* cdbPathUsed = "unknown (not set)";
- if (cdbPath != NULL)
- {
- cdbManager->SetDefaultStorage(cdbPath);
- cdbPathUsed = cdbPath;
- }
- else
- {
- AliCDBStorage* store = cdbManager->GetDefaultStorage();
- if (store != NULL) cdbPathUsed = store->GetURI().Data();
- }
-
- if (run != -1) cdbManager->SetRun(run);
- Int_t runUsed = cdbManager->GetRun();
-
- if (not AliMpCDB::LoadDDLStore(warn))
- {
- HLTError("Failed to load DDL store specified for CDB path '%s' and run no. %d",
- cdbPathUsed, runUsed
- );
- return -ENOENT;
- }
+ int result = FetchMappingStores(cdbPath, run);
+ // Error message already generated in FetchMappingStores.
+ if (result != 0) return result;
AliMpDDLStore* ddlStore = AliMpDDLStore::Instance();
- if (ddlStore == NULL)
- {
- HLTError("Could not find DDL store instance.");
- return -EIO;
- }
+
AliMpSegmentation* segmentation = AliMpSegmentation::Instance();
if (segmentation == NULL)
{
return -EIO;
}
- AliGeomManager::LoadGeometry();
+ // Only load geometry if not already loaded.
+ if (AliGeomManager::GetGeometry() == NULL)
+ {
+ AliGeomManager::LoadGeometry();
+ }
AliMUONGeometryTransformer transformer;
if (not transformer.LoadGeometryData())
{
AliHLTMUONTriggerRecoLookupTable* lookupTable = fTrigRec->LookupTableBuffer();
- for (Int_t i = 0; i < 8; i++)
+ for (Int_t i = 0; i < 16; i++)
for (Int_t j = 0; j < 16; j++)
for (Int_t k = 0; k < 4; k++)
for (Int_t n = 0; n < 2; n++)
for (Int_t m = 0; m < 16; m++)
{
+ lookupTable->fRow[i][j][k][n][m].fIdFlags = 0x0;
lookupTable->fRow[i][j][k][n][m].fX = 0;
lookupTable->fRow[i][j][k][n][m].fY = 0;
lookupTable->fRow[i][j][k][n][m].fZ = 0;
AliMpTriggerCrate* crate = ddlStore->GetTriggerCrate(fDDL, iReg);
if (crate == NULL)
{
- cerr << "ERROR: Could not get crate for regional header = " << iReg
- << ", and DDL ID = " << fDDL << endl;
+ HLTError("Could not get crate mapping for regional header = %d"
+ " and DDL %d (ID = %d).",
+ iReg, fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL)
+ );
+ continue;
+ }
+ // Depending on the value of fUseCrateId, use either the crate ID as would
+ // be found in the regional header structures or the sequencial index number
+ // of the structure.
+ UInt_t crateId = (fUseCrateId ? crate->GetId() : iReg);
+ if (crateId >= 16)
+ {
+ HLTError("The crate ID number (%d) for regional header = %d and"
+ " DDL %d (ID = %d) is too big. It should be in the range [0..15]",
+ crateId, iReg, fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL)
+ );
continue;
}
AliMpLocalBoard* localBoard = ddlStore->GetLocalBoard(boardId);
if (localBoard == NULL)
{
- cerr << "ERROR: Could not get loacl board: " << boardId << endl;
+ HLTError("Could not get local board: %d.", boardId);
continue;
}
{
Int_t detElemId = ddlStore->GetDEfromLocalBoard(boardId, iChamber);
+ AliHLTUInt32_t idflags = AliHLTMUONUtils::PackRecHitFlags(iChamber+10, detElemId);
+
const AliMUONGeometryDetElement* detElemTransform = transformer.GetDetElement(detElemId);
if (detElemTransform == NULL)
{
- cerr << "ERROR: Got NULL pointer for geometry transformer for detection element ID = "
- << detElemId << endl;
+ HLTError("Got NULL pointer for geometry transformer"
+ " for detection element ID = %d.",
+ detElemId
+ );
continue;
}
detElemTransform->Local2Global(lx, ly, 0, gx, gy, gz);
// Fill the LUT
- lookupTable->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fX = gx;
- lookupTable->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fY = gy;
- lookupTable->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fZ = gz;
+ lookupTable->fRow[crateId][iLocBoard][iChamber][iCathode][bitxy].fIdFlags = idflags;
+ lookupTable->fRow[crateId][iLocBoard][iChamber][iCathode][bitxy].fX = gx;
+ lookupTable->fRow[crateId][iLocBoard][iChamber][iCathode][bitxy].fY = gy;
+ lookupTable->fRow[crateId][iLocBoard][iChamber][iCathode][bitxy].fZ = gz;
}
}
}
}
}
-
+
return 0;
}
bool AliHLTMUONTriggerReconstructorComponent::GenerateLookupTable(
AliHLTInt32_t ddl, const char* filename,
const char* cdbPath, Int_t run
+ //TODO add option fCrateId
)
{
/// Generates a binary file containing the lookup table (LUT) from the
);
if (not file)
{
- cerr << "ERROR: There was a problem writing to the file: " << filename << endl;
+ std::cerr << "ERROR: There was a problem writing to the file: " << filename << std::endl;
return false;
}
file.close();