]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTOUT.cxx
various fixes in the HLTOUT treatment
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUT.cxx
index 0641d8d094b551f1c7fa60c3afaf92822cef54e3..2a6d96c178f652becec2394efa1cf49796d1954f 100644 (file)
@@ -28,6 +28,7 @@
 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 
 #include <cerrno>
+#include <cassert>
 #include "AliHLTOUT.h"
 
 /** ROOT macro for the implementation of ROOT specific class methods */
@@ -40,7 +41,8 @@ AliHLTOUT::AliHLTOUT()
   fFlags(0),
   fBlockDescList(),
   fCurrent(fBlockDescList.begin()),
-  fpBuffer(NULL)
+  fpBuffer(NULL),
+  fDataHandlers()
 {
   // see header file for class documentation
   // or
@@ -62,19 +64,34 @@ AliHLTOUT::~AliHLTOUT()
   // see header file for class documentation
 }
 
+int AliHLTOUT::Init()
+{
+  // see header file for class documentation
+  int iResult=0;
+  SetStatusFlag(kCollecting);
+  if ((iResult=GenerateIndex())>=0) {
+    if ((iResult=InitHandlers())>=0) {
+    }
+  }
+  ClearStatusFlag(kCollecting);
+  return iResult;
+}
+
 int AliHLTOUT::GetNofDataBlocks()
 {
   // see header file for class documentation
   return fBlockDescList.size();
 }
 
-int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec)
+int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
+                                   AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
 {
   // see header file for class documentation
   if (CheckStatusFlag(kLocked)) return -EPERM;
   fCurrent=fBlockDescList.begin();
   fSearchDataType=dt;
   fSearchSpecification=spec;
+  //fSearchHandlerType=handlerType;
   return FindAndSelectDataBlock();
 }
 
@@ -82,6 +99,7 @@ int AliHLTOUT::SelectNextDataBlock()
 {
   // see header file for class documentation
   if (CheckStatusFlag(kLocked)) return -EPERM;
+  if (fCurrent==fBlockDescList.end()) return -ENOENT;
   fCurrent++;
   return FindAndSelectDataBlock();
 }
@@ -92,12 +110,14 @@ int AliHLTOUT::FindAndSelectDataBlock()
   if (CheckStatusFlag(kLocked)) return -EPERM;
   int iResult=-ENOENT;
   while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
-    if ((fSearchDataType==kAliHLTAnyDataType || (*fCurrent)==fSearchDataType) &&
-       fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification) {
-      iResult=0;
+    if ((*fCurrent)==fSearchDataType &&
+       fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification &&
+       1/*fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput*/) {
+      iResult=fCurrent->GetIndex();
       // TODO: check the byte order on the current system and the byte order of the
       // data block, print warning when missmatch and user did not check
-      AliHLTOUTByteOrder_t blockBO=CheckByteOrder();
+      //AliHLTOUTByteOrder_t blockBO=CheckByteOrder();
+      CheckByteOrder();
       /*
        if (blockBO!=fByteOrder) {
        SetStatusFlag(kByteOrderWarning);
@@ -109,6 +129,8 @@ int AliHLTOUT::FindAndSelectDataBlock()
       // TODO: check the alignment on the current system and the alignment of the
       // data block, print warning when missmatch and user did not check
       ClearStatusFlag(kAlignmentChecked);
+
+      break;
     }
     fCurrent++;
   }
@@ -127,6 +149,13 @@ int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32
   return iResult;
 }
 
+AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
+{
+  // see header file for class documentation
+  if (fCurrent==fBlockDescList.end()) return AliHLTOUTInvalidIndex;
+  return fCurrent->GetIndex();
+}
+
 int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
 {
   // see header file for class documentation
@@ -164,6 +193,7 @@ int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
 
 AliHLTOUT::AliHLTOUTByteOrder_t AliHLTOUT::CheckByteOrder()
 {
+  // see header file for class documentation
   if (fCurrent!=fBlockDescList.end()) {
     SetStatusFlag(kByteOrderChecked);
     AliHLTOUT::AliHLTOUTByteOrder_t order=CheckBlockByteOrder((*fCurrent).GetIndex());
@@ -174,6 +204,7 @@ AliHLTOUT::AliHLTOUTByteOrder_t AliHLTOUT::CheckByteOrder()
 
 int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType_t type)
 {
+  // see header file for class documentation
   if (fCurrent!=fBlockDescList.end()) {
     SetStatusFlag(kAlignmentChecked);
     int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
@@ -181,3 +212,122 @@ int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType_t type)
   }
   return -ENOENT;
 }
+
+int AliHLTOUT::InitHandlers()
+{
+  // see header file for class documentation
+  int iResult=0;
+  AliHLTOUTIndexList remnants;
+  for (iResult=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); iResult>=0; iResult=SelectNextDataBlock()) {
+    remnants.push_back(GetDataBlockIndex());
+    AliHLTComponentDataType dt=kAliHLTVoidDataType;
+    AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
+    if ((iResult=GetDataBlockDescription(dt, spec))<0) break;
+    for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
+      AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
+      if (pAgent->GetHandlerDescription(dt, spec, &handlerDesc)>0) {
+       AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
+       iResult=InsertHandler(entry);
+       remnants.pop_back();
+       break;
+      }
+    }
+  }
+  if (remnants.size()>0) {
+    HLTWarning("no handlers found for %d data blocks out of %d", remnants.size(), GetNofDataBlocks());
+    vector<AliHLTOUTBlockDescriptor>::iterator block=fBlockDescList.begin();
+    for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
+      for (int trials=0; trials<2; trials++) {
+       do {
+         // we start searching the index from the current position in the block list
+         if ((*block).GetIndex()==*element) break;
+       } while ((++block)!=fBlockDescList.end());
+       if (block==fBlockDescList.end()) {
+         // rewind and try again
+         block=fBlockDescList.begin();
+       }
+      }
+      assert(block!=fBlockDescList.end());
+      if (block!=fBlockDescList.end()) {
+       HLTDebug("   %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
+      }
+    }
+  }
+  return iResult;
+}
+
+int AliHLTOUT::InsertHandler(const AliHLTOUTHandlerListEntry &entry)
+{
+  // see header file for class documentation
+  int iResult=0;
+  vector<AliHLTOUTHandlerListEntry>::iterator element=fDataHandlers.begin();
+  while (element!=fDataHandlers.end()) {
+    if (entry==(*element)) break;
+    element++;
+  }
+  if (element==fDataHandlers.end()) {
+    fDataHandlers.push_back(entry);
+  } else {
+    
+  }
+  return iResult;
+}
+
+AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler, 
+                                                               AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
+                                                               AliHLTModuleAgent* pAgent,
+                                                               AliHLTUInt32_t index)
+  :
+  fpHandler(pHandler),
+  fHandlerDesc(handlerDesc),
+  fpAgent(pAgent),
+  fBlocks()
+{
+  // see header file for class documentation
+  fBlocks.push_back(index);
+}
+
+AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
+  :
+  fpHandler(src.fpHandler),
+  fHandlerDesc(src.fHandlerDesc),
+  fpAgent(src.fpAgent),
+  fBlocks()
+{
+  // see header file for class documentation
+  fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
+}
+
+AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
+{
+  // see header file for class documentation
+}
+
+AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
+{
+  // see header file for class documentation
+  fpHandler=src.fpHandler;
+  fHandlerDesc=src.fHandlerDesc;
+  fpAgent=src.fpAgent;
+  fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
+  return *this;
+}
+
+AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
+{
+  // see header file for class documentation
+  return fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
+}
+
+bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
+{
+  // see header file for class documentation
+  assert(0); // not yet implemented
+  return false;
+}
+
+void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
+{
+  // see header file for class documentation
+  fBlocks.push_back(index);
+}