+
+AliHLTUInt64_t AliHLTOUT::ByteSwap64(AliHLTUInt64_t src)
+{
+ // see header file for class documentation
+ return ((src & 0xFFULL) << 56) |
+ ((src & 0xFF00ULL) << 40) |
+ ((src & 0xFF0000ULL) << 24) |
+ ((src & 0xFF000000ULL) << 8) |
+ ((src & 0xFF00000000ULL) >> 8) |
+ ((src & 0xFF0000000000ULL) >> 24) |
+ ((src & 0xFF000000000000ULL) >> 40) |
+ ((src & 0xFF00000000000000ULL) >> 56);
+}
+
+AliHLTUInt32_t AliHLTOUT::ByteSwap32(AliHLTUInt32_t src)
+{
+ // see header file for class documentation
+ return ((src & 0xFFULL) << 24) |
+ ((src & 0xFF00ULL) << 8) |
+ ((src & 0xFF0000ULL) >> 8) |
+ ((src & 0xFF000000ULL) >> 24);
+}
+
+AliHLTOUT* AliHLTOUT::New(AliRawReader* pRawReader)
+{
+ // see header file for class documentation
+ AliHLTOUT* instance=New("AliHLTOUTRawReader");
+ if (instance) {
+ instance->SetParam(pRawReader);
+ }
+ return instance;
+}
+
+AliHLTOUT* AliHLTOUT::New(TTree* pDigitTree, int event)
+{
+ // see header file for class documentation
+ AliHLTOUT* instance=New("AliHLTOUTDigitReader");
+ if (instance) {
+ instance->SetParam(pDigitTree, event);
+ }
+ return instance;
+}
+
+AliHLTOUT* AliHLTOUT::New(const char* classname)
+{
+ // see header file for class documentation
+ int iLibResult=0;
+ AliHLTOUT* instance=NULL;
+ AliHLTLogging log;
+ TClass* pCl=NULL;
+ ROOT::NewFunc_t pNewFunc=NULL;
+ do {
+ pCl=TClass::GetClass(classname);
+ } while (!pCl && (iLibResult=gSystem->Load("libHLTRec.so"))==0);
+ if (iLibResult>=0) {
+ if (pCl && (pNewFunc=pCl->GetNew())!=NULL) {
+ void* p=(*pNewFunc)(NULL);
+ if (p) {
+ instance=reinterpret_cast<AliHLTOUT*>(p);
+ if (!instance) {
+ log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "type cast to AliHLTOUT instance failed");
+ }
+ } else {
+ log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "can not create AliHLTOUT instance from class descriptor");
+ }
+ } else {
+ log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "can not find AliHLTOUT class descriptor");
+ }
+ } else {
+ log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "can not load libHLTrec library");
+ }
+ return instance;
+}
+
+void AliHLTOUT::Delete(AliHLTOUT* pInstance)
+{
+ // see header file for class documentation
+ if (!pInstance) return;
+ if (pInstance==fgGlobalInstance) return;
+
+ // check if the library is still there in order to have the
+ // destructor available
+ TClass* pCl1=TClass::GetClass("AliHLTOUTRawReader");
+ TClass* pCl2=TClass::GetClass("AliHLTOUTDigitReader");
+ if (!pCl1 && !pCl2) {
+ AliHLTLogging log;
+ log.Logging(kHLTLogError, "AliHLTOUT::Delete", "HLTOUT handling", "potential memory leak: libHLTrec library not available, skipping destruction %p", pInstance);
+ return;
+ }
+
+ delete pInstance;
+}
+
+void AliHLTOUT::SetParam(AliRawReader* /*pRawReader*/)
+{
+ // see header file for class documentation
+ // default implementation, we should never get here
+ // this function can only be called from the class itsself and
+ // is intended to be used with the New functions. If we get into
+ // the default implementation there is a class mismatch.
+ assert(0);
+ fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
+}
+
+void AliHLTOUT::SetParam(TTree* /*pDigitTree*/, int /*event*/)
+{
+ // see header file for class documentation
+ // default implementation, we should never get here
+ // this function can only be called from the class itsself and
+ // is intended to be used with the New functions. If we get into
+ // the default implementation there is a class mismatch.
+ assert(0);
+ fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
+}
+
+int AliHLTOUT::SelectDataBlock()
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (fCurrent>=fBlockDescList.size()) return 0;
+ fBlockDescList[fCurrent].Select(true);
+ EnableBlockSelection();
+ return iResult;
+}
+
+int AliHLTOUT::SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerDesc)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (!pHandlerDesc) return 0;
+
+ AliHLTOUTBlockDescriptorVector::iterator element;
+ for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
+ block!=fBlockDescList.end();
+ block++) {
+ if (block->GetHandlerDesc()==*pHandlerDesc && pHandlerDesc->HasIndex(block->GetIndex()))
+ block->Select(true);
+ else
+ block->Select(false);
+ }
+ EnableBlockSelection();
+
+ return iResult;
+}
+
+int AliHLTOUT::EnableBlockSelection()
+{
+ // see header file for class documentation
+ SetStatusFlag(kBlockSelection);
+ return 0;
+}
+
+int AliHLTOUT::DisableBlockSelection()
+{
+ // see header file for class documentation
+ ClearStatusFlag(kBlockSelection);
+ return 0;
+}
+
+int AliHLTOUT::ResetBlockSelection()
+{
+ // see header file for class documentation
+ for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
+ block!=fBlockDescList.end();
+ block++) {
+ block->Select(false);
+ }
+ return 0;
+}
+
+int AliHLTOUT::MarkDataBlockProcessed()
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (fCurrent>=fBlockDescList.size()) return 0;
+ fBlockDescList[fCurrent].MarkProcessed();
+ return iResult;
+}
+
+int AliHLTOUT::MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (!pHandlerDesc) return 0;
+
+ AliHLTOUTBlockDescriptorVector::iterator element;
+ for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
+ block!=fBlockDescList.end();
+ block++) {
+ if (block->GetHandlerDesc()==*pHandlerDesc && pHandlerDesc->HasIndex(block->GetIndex()))
+ block->MarkProcessed();
+ }
+
+ return iResult;
+}
+
+int AliHLTOUT::AddSubCollection(AliHLTOUT* pCollection)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (!pCollection) return 0;
+
+ SetStatusFlag(kCollecting);
+ int index=-1;
+ for (index=pCollection->SelectFirstDataBlock();
+ index>=0;
+ index=pCollection->SelectNextDataBlock()) {
+ AliHLTComponentDataType dt=kAliHLTVoidDataType;
+ AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
+ pCollection->GetDataBlockDescription(dt, spec);
+ AliHLTOUTBlockDescriptor desc(dt, spec, index, pCollection);
+ AddBlockDescriptor(desc);
+ iResult++;
+ }
+ if (iResult>0) {
+ if (CheckStatusFlag(kIsSubCollection)) {
+ fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "AddSubCollection" , __FILE__ , __LINE__ , "HLTOUT object %p has already been added as sub-collection", pCollection);
+ } else {
+ pCollection->SetStatusFlag(kIsSubCollection);
+ }
+ }
+ ClearStatusFlag(kCollecting);
+
+ return iResult;
+}
+
+int AliHLTOUT::ReleaseSubCollection(AliHLTOUT* pCollection)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (!pCollection) return 0;
+
+ AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
+ while (block!=fBlockDescList.end()) {
+ if ((*block)==pCollection) {
+ block=fBlockDescList.erase(block);
+ continue;
+ }
+ block++;
+ }
+ pCollection->ClearStatusFlag(kIsSubCollection);
+
+ return iResult;
+}
+
+int AliHLTOUT::Reset()
+{
+ // see header file for class documentation
+ int iResult=0;
+ AliHLTOUTPVector subCollections;
+ AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
+ while (block!=fBlockDescList.end()) {
+ if (!((*block)==this)) {
+ AliHLTOUTPVector::iterator collection=subCollections.begin();
+ for (; collection!=subCollections.end(); collection++)
+ if((*block)==*collection) break;
+ if (collection==subCollections.end())
+ subCollections.push_back(block->GetCollection());
+ }
+ block=fBlockDescList.erase(block);
+ }
+
+ for (AliHLTOUTPVector::iterator collection=subCollections.begin();
+ collection!=subCollections.end(); collection++) {
+ (*collection)->Reset();
+ (*collection)->ClearStatusFlag(kIsSubCollection);
+ }
+
+ ResetInput();
+
+ return iResult;
+}
+
+int AliHLTOUT::ResetInput()
+{
+ // default implementation, nothing to do
+ return 0;
+}
+
+const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTBlockDescriptor::GetHandlerDesc()
+{
+ // see header file for class documentation
+ if (fpCollection) {
+ AliHLTOUTHandlerListEntryVector::iterator element=fpCollection->fDataHandlers.begin();
+ while (element!=fpCollection->fDataHandlers.end()) {
+ if (element->HasIndex(GetIndex())) {
+ return *element;
+ }
+ element++;
+ }
+ }
+ return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
+}