]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/AliHLTTPCEsdWriterComponent.cxx
- added general data type for ESD objects
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCEsdWriterComponent.cxx
index 973de6523db435835baa58d91da3407580cf6ff6..451b576b6fcc3fbb2baad44daceec42ae0aa09c4 100644 (file)
             mapping tracker in the AliESD format
 
                                                                           */
+// see header file for class documentation
+// or
+// refer to README to build package
+// or
+// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+
+#include <cassert>
 #include "AliHLTTPCEsdWriterComponent.h"
 #include "AliESDEvent.h"
+#include "AliESDtrack.h"
 #include "TTree.h"
+#include "TFile.h"
 #include "AliHLTTPCTrack.h"
 #include "AliHLTTPCTrackArray.h"
 #include "AliHLTTPCTrackletDataFormat.h"
 #include "AliHLTTPCDefinitions.h"
-
-/** global instance for component registration */
-AliHLTTPCEsdWriterComponent gTPCEsdWriter;
+#include "AliHLTTPCTransform.h"
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTTPCEsdWriterComponent)
 
 AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent()
-  :
-  fTree(NULL),
-  fESD(NULL)
 {
   // see header file for class documentation
   // or
@@ -49,36 +53,53 @@ AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent()
   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 }
 
-AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent(const AliHLTTPCEsdWriterComponent&)
+AliHLTTPCEsdWriterComponent::~AliHLTTPCEsdWriterComponent()
+{
+  // see header file for class documentation
+}
+
+AliHLTTPCEsdWriterComponent::AliWriter::AliWriter()
   :
   fTree(NULL),
-  fESD(NULL)
+  fESD(NULL),
+  fBase(new AliHLTTPCEsdWriterComponent)
 {
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 }
 
-AliHLTTPCEsdWriterComponent& AliHLTTPCEsdWriterComponent::operator=(const AliHLTTPCEsdWriterComponent&)
+AliHLTTPCEsdWriterComponent::AliWriter::~AliWriter()
 {
-  return *this;
+  // see header file for class documentation
+  if (fBase) delete fBase;
+  fBase=NULL;
 }
 
-AliHLTTPCEsdWriterComponent::~AliHLTTPCEsdWriterComponent()
+void AliHLTTPCEsdWriterComponent::AliWriter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
 {
   // see header file for class documentation
+  list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
 }
 
-int AliHLTTPCEsdWriterComponent::InitWriter()
+int AliHLTTPCEsdWriterComponent::AliWriter::InitWriter()
 {
   // see header file for class documentation
   int iResult=0;
   fESD = new AliESDEvent;
   if (fESD) {
     fESD->CreateStdContent();
+    // we have to open a TFile in order to avoid warnings related to
+    // memory resident TTree's. Bad Root feature, yes ;-(
+    // Unfortunatly, opening a dummy file leads to the file to be
+    // created.
+    //TFile dummy("/tmp/dummy-to-avoid-ttree-warnigs", "CRAETE");
     fTree = new TTree("esdTree", "Tree with HLT ESD objects");
     if (fTree) {
       fESD->WriteToTree(fTree);
     }
-    delete fESD;
-    fESD=NULL;
   }
   if (fTree==NULL) {
     iResult=-ENOMEM;
@@ -86,7 +107,7 @@ int AliHLTTPCEsdWriterComponent::InitWriter()
   return iResult;
 }
 
-int AliHLTTPCEsdWriterComponent::CloseWriter()
+int AliHLTTPCEsdWriterComponent::AliWriter::CloseWriter()
 {
   // see header file for class documentation
   int iResult=0;
@@ -102,24 +123,47 @@ int AliHLTTPCEsdWriterComponent::CloseWriter()
   return iResult;
 }
 
-int AliHLTTPCEsdWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData,
+int AliHLTTPCEsdWriterComponent::AliWriter::DumpEvent( const AliHLTComponentEventData& evtData,
                                            const AliHLTComponentBlockData* blocks, 
-                                           AliHLTComponentTriggerData& trigData )
+                                           AliHLTComponentTriggerData& /*trigData*/ )
 {
   // see header file for class documentation
   int iResult=0;
   TTree* pTree=fTree;
-  if (pTree) {
-    fESD = new AliESDEvent;
+  assert(fBase);
+  if (pTree && fBase) {
     if (fESD) {
-      fESD->CreateStdContent();
       AliESDEvent* pESD=fESD;
 
+      iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt);
+
+    } else {
+      iResult=-ENOMEM;
+    }
+  }
+  return iResult;
+}
+
+int AliHLTTPCEsdWriterComponent::AliWriter::ScanArgument(int argc, const char** argv)
+{
+  // see header file for class documentation
+  int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv);
+  return iResult;
+}
+
+int AliHLTTPCEsdWriterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD,
+                                              const AliHLTComponentBlockData* blocks,
+                                              int nBlocks, int* pMinSlice,
+                                              int* pMaxSlice)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (pESD && blocks) {
       const AliHLTComponentBlockData* iter = NULL;
       AliHLTTPCTrackletData* inPtr=NULL;
       int bIsTrackSegs=0;
  
-      for (int ndx=0; ndx<(int)evtData.fBlockCnt && iResult>=0; ndx++) {
+      for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
        iter = blocks+ndx;
        if ( (bIsTrackSegs=(iter->fDataType == AliHLTTPCDefinitions::fgkTrackSegmentsDataType))==1 ||
             iter->fDataType == AliHLTTPCDefinitions::fgkTracksDataType ) {
@@ -127,11 +171,16 @@ int AliHLTTPCEsdWriterComponent::DumpEvent( const AliHLTComponentEventData& evtD
          Int_t maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
          if (bIsTrackSegs==0) {
            // slice parameter and data specification ignored, tracks already in global coordinates
-           minslice=0;
-           maxslice=0;
+           minslice=-1;
+           maxslice=-1;
+           if (pMinSlice) *pMinSlice=0;
+           if (pMaxSlice) *pMaxSlice=AliHLTTPCTransform::GetNSlice()-1;
+         } else {
+           if (pMinSlice && (*pMinSlice==-1 || *pMinSlice>minslice)) *pMinSlice=minslice;
+           if (pMaxSlice && (*pMaxSlice==-1 || *pMaxSlice<maxslice)) *pMaxSlice=maxslice;
          }
          //HLTDebug("dataspec %#x minslice %d", iter->fSpecification, minslice);
-         if (minslice >=0 && minslice<36) {
+         if (minslice >=-1 && minslice<AliHLTTPCTransform::GetNSlice()) {
            if (minslice!=maxslice) {
              HLTWarning("data from multiple sectors in one block: "
                         "possible missmatch in treatment of local coordinate system");
@@ -148,26 +197,19 @@ int AliHLTTPCEsdWriterComponent::DumpEvent( const AliHLTComponentEventData& evtD
          }
        }
       }
-      if (iResult>=0) {
+      if (iResult>=0 && pTree) {
        pTree->Fill();
       }
 
-      fESD->Reset();
-      delete pESD;
-    } else {
-      iResult=-ENOMEM;
-    }
+      pESD->Reset();
+    
+  } else {
+    HLTError("invalid paremeter");
+    iResult=-EINVAL;
   }
   return iResult;
 }
 
-int AliHLTTPCEsdWriterComponent::ScanArgument(int argc, const char** argv)
-{
-  // see header file for class documentation
-  int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv);
-  return iResult;
-}
-
 int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESDEvent* pESD)
 {
   // see header file for class documentation
@@ -199,3 +241,122 @@ int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESD
   }
   return iResult;
 }
+
+AliHLTTPCEsdWriterComponent::AliConverter::AliConverter()
+  :
+  fBase(new AliHLTTPCEsdWriterComponent),
+  fWriteTree(1)
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+}
+
+AliHLTTPCEsdWriterComponent::AliConverter::~AliConverter()
+{
+  // see header file for class documentation
+  if (fBase) delete fBase;
+  fBase=NULL;
+}
+
+void AliHLTTPCEsdWriterComponent::AliConverter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
+{
+  // see header file for class documentation
+  list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
+}
+
+AliHLTComponentDataType AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataType()
+{
+  // see header file for class documentation
+  return kAliHLTDataTypeESDTree;
+}
+
+void AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
+{
+  // see header file for class documentation
+  constBase=1000000;
+  inputMultiplier=1.0;
+}
+
+int AliHLTTPCEsdWriterComponent::AliConverter::DoInit(int argc, const char** argv)
+{
+  // see header file for class documentation
+  int iResult=0;
+  TString argument="";
+  int bMissingParam=0;
+  for (int i=0; i<argc && iResult>=0; i++) {
+    argument=argv[i];
+    if (argument.IsNull()) continue;
+
+    // -notree
+    if (argument.CompareTo("-notree")==0) {
+      fWriteTree=0;
+
+      // -tree
+    } else if (argument.CompareTo("-tree")==0) {
+      fWriteTree=1;
+
+    } else {
+      HLTError("unknown argument %s", argument.Data());
+      break;
+    }
+  }
+  if (bMissingParam) {
+    HLTError("missing parameter for argument %s", argument.Data());
+    iResult=-EINVAL;
+  }
+
+  return iResult;
+}
+
+int AliHLTTPCEsdWriterComponent::AliConverter::DoDeinit()
+{
+  // see header file for class documentation
+  return 0;
+}
+
+int AliHLTTPCEsdWriterComponent::AliConverter::DoEvent(const AliHLTComponentEventData& evtData, 
+                                                      const AliHLTComponentBlockData* blocks, 
+                                                      AliHLTComponentTriggerData& /*trigData*/,
+                                                      AliHLTUInt8_t* /*outputPtr*/, 
+                                                      AliHLTUInt32_t& /*size*/,
+                                                      AliHLTComponentBlockDataList& /*outputBlocks*/ )
+{
+  // see header file for class documentation
+  int iResult=0;
+  assert(fBase);
+  // we have to open a TFile in order to avoid warnings related to
+  // memory resident TTree's. Bad Root feature, yes ;-(
+  // Unfortunatly, opening a dummy file leads to the file to be
+  // created.
+  //TFile dummy("/tmp/dummy-to-avoid-ttree-warnigs", "RECREATE");
+  AliESDEvent* pESD = new AliESDEvent;
+  if (pESD && fBase) {
+    pESD->CreateStdContent();
+    TTree* pTree = NULL;
+    // TODO: Matthias 06.12.2007
+    // Tried to write the ESD directly instead to a tree, but this did not work
+    // out. Information in the ESD is different, needs investigation.
+    if (fWriteTree)
+      pTree = new TTree("esdTree", "Tree with HLT ESD objects");
+    if (pTree) {
+      pESD->WriteToTree(pTree);
+    }
+
+    if ((iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt))>=0) {
+       // TODO: set the specification correctly
+      if (pTree)
+       iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginTPC, 0);
+      else
+       iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, 0);
+    }
+    if (pTree)
+      delete pTree;
+
+    delete pESD;
+  }
+  return iResult;
+}
+