]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
moved from BASE to BASE/util
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 14 Mar 2007 10:44:52 +0000 (10:44 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 14 Mar 2007 10:44:52 +0000 (10:44 +0000)
HLT/BASE/util/AliHLTFilePublisher.cxx [new file with mode: 0644]
HLT/BASE/util/AliHLTRootFilePublisherComponent.cxx [new file with mode: 0644]
HLT/BASE/util/AliHLTRootFilePublisherComponent.h [new file with mode: 0644]
HLT/BASE/util/AliHLTRootFileWriterComponent.cxx [new file with mode: 0644]
HLT/BASE/util/AliHLTRootFileWriterComponent.h [new file with mode: 0644]

diff --git a/HLT/BASE/util/AliHLTFilePublisher.cxx b/HLT/BASE/util/AliHLTFilePublisher.cxx
new file mode 100644 (file)
index 0000000..bd81e57
--- /dev/null
@@ -0,0 +1,292 @@
+// $Id$
+
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
+ *          for The ALICE Off-line Project.                               *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/** @file   AliHLTFilePublisher.cxx
+    @author Matthias Richter
+    @date   
+    @brief  HLT file publisher component implementation. */
+
+#if __GNUC__>= 3
+using namespace std;
+#endif
+
+#include "AliHLTFilePublisher.h"
+#include <TObjString.h>
+#include <TMath.h>
+#include <TFile.h>
+
+/** the global object for component registration */
+AliHLTFilePublisher gAliHLTFilePublisher;
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTFilePublisher)
+
+AliHLTFilePublisher::AliHLTFilePublisher()
+  :
+  AliHLTDataSource(),
+  fFileNames(),
+  fFiles(),
+  fpCurrent(NULL),
+  fDataType(kAliHLTVoidDataType),
+  fSpecification(~(AliHLTUInt32_t)0),
+  fMaxSize(0)
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+
+  // make the lists owners of their objects in order to automatically
+  // de-allocate the objects
+  fFileNames.SetOwner();
+  fFiles.SetOwner();
+}
+
+AliHLTFilePublisher::AliHLTFilePublisher(const AliHLTFilePublisher&)
+  :
+  AliHLTDataSource(),
+  fFileNames(),
+  fFiles(),
+  fpCurrent(NULL),
+  fDataType(kAliHLTVoidDataType),
+  fSpecification(0),
+  fMaxSize(0)
+{
+  // see header file for class documentation
+  HLTFatal("copy constructor untested");
+}
+
+AliHLTFilePublisher& AliHLTFilePublisher::operator=(const AliHLTFilePublisher&)
+{ 
+  // see header file for class documentation
+  HLTFatal("assignment operator untested");
+  return *this;
+}
+
+AliHLTFilePublisher::~AliHLTFilePublisher()
+{
+  // see header file for class documentation
+
+  // file list and file name list are owner of their objects and
+  // delete all the objects
+}
+
+const char* AliHLTFilePublisher::GetComponentID()
+{
+  // see header file for class documentation
+  return "FilePublisher";
+}
+
+AliHLTComponentDataType AliHLTFilePublisher::GetOutputDataType()
+{
+  // see header file for class documentation
+  return fDataType;
+}
+
+void AliHLTFilePublisher::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+{
+  // see header file for class documentation
+  constBase=fMaxSize;
+  inputMultiplier=1.0;
+}
+
+AliHLTComponent* AliHLTFilePublisher::Spawn()
+{
+  // see header file for class documentation
+  return new AliHLTFilePublisher;
+}
+
+int AliHLTFilePublisher::DoInit( int argc, const char** argv )
+{
+  // see header file for class documentation
+
+  //HLTDebug("%d %s", argc, argv[0]);
+  int iResult=0;
+  TString argument="";
+  int bMissingParam=0;
+  for (int i=0; i<argc && iResult>=0; i++) {
+    argument=argv[i];
+    if (argument.IsNull()) continue;
+
+    // -datafile
+    if (argument.CompareTo("-datafile")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      TObjString* parameter=new TObjString(argv[i]);
+      if (parameter) {
+       fFileNames.Add(parameter);
+      } else {
+       iResult=-ENOMEM;
+      }
+
+      // -datafilelist
+    } else if (argument.CompareTo("-datafilelist")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      HLTWarning("-datafilelist option not yet implemented");
+
+      // -datatype
+    } else if (argument.CompareTo("-datatype")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
+      if ((bMissingParam=(++i>=argc))) break;
+      memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
+
+      // -dataspec
+    } else if (argument.CompareTo("-dataspec")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      TString parameter(argv[i]);
+      parameter.Remove(TString::kLeading, ' '); // remove all blanks
+      if (parameter.IsDigit()) {
+       fSpecification=(AliHLTUInt32_t)parameter.Atoi();
+      } else if (parameter.BeginsWith("0x") &&
+                parameter.Replace(0,2,"",0).IsHex()) {
+       sscanf(parameter.Data(),"%x", &fSpecification);
+      } else {
+       HLTError("wrong parameter for argument %s, number expected", argument.Data());
+       iResult=-EINVAL;
+      }
+    } else {
+      if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) {
+       HLTError("unknown argument %s", argument.Data());
+       break;
+      } else if (iResult==-EPROTO) {
+       bMissingParam=1;
+       break;
+      } else if (iResult>=0) {
+       i+=iResult;
+       iResult=0;
+      }
+    }
+  }
+  if (bMissingParam) {
+    HLTError("missing parameter for argument %s", argument.Data());
+    iResult=-EINVAL;
+  }
+  if (fFileNames.GetSize()==0) {
+    HLTError("the publisher needs at least one file argument");
+    iResult=-EINVAL;
+  }
+  if (iResult>=0) iResult=OpenFiles();
+  if (iResult<0) {
+    fFileNames.Clear();
+  }
+  return iResult;
+}
+
+int AliHLTFilePublisher::ScanArgument(int argc, const char** argv)
+{
+  // see header file for class documentation
+
+  // there are no other arguments than the standard ones
+  if (argc==0 && argv==NULL) {
+    // this is just to get rid of the warning "unused parameter"
+  }
+  return -EPROTO;
+}
+
+int AliHLTFilePublisher::OpenFiles()
+{
+  // see header file for class documentation
+  int iResult=0;
+  TObjLink *lnk=fFileNames.FirstLink();
+  while (lnk && iResult>=0) {
+    TObjString* pFileName=(TObjString*)lnk->GetObject();
+    if (pFileName) {
+      TString fullFN= pFileName->GetString() + "?filetype=raw";
+      TFile* pFile = new TFile(fullFN);
+      if (pFile) {
+       if (pFile->IsZombie()==0) {
+         fFiles.Add(pFile);
+         if (pFile->GetSize()>fMaxSize) fMaxSize=pFile->GetSize();
+       } else {
+         HLTError("can not open file %s", (pFileName->GetString()).Data());
+         fFiles.Clear();
+         iResult=-ENOENT;
+       }
+      }
+    }
+    lnk = lnk->Next();
+  }
+
+  return iResult;
+}
+
+int AliHLTFilePublisher::DoDeinit()
+{
+  // see header file for class documentation
+  int iResult=0;
+  fFileNames.Clear();
+  fFiles.Clear();
+  return iResult;
+}
+
+int AliHLTFilePublisher::GetEvent( const AliHLTComponentEventData& evtData,
+             AliHLTComponentTriggerData& trigData,
+             AliHLTUInt8_t* outputPtr, 
+             AliHLTUInt32_t& size,
+             vector<AliHLTComponentBlockData>& outputBlocks )
+{
+  int iResult=0;
+  TObjLink *lnk=NULL;
+  if (fpCurrent) lnk=fpCurrent->Next();
+  if (lnk==NULL) lnk=fFiles.FirstLink();
+  fpCurrent=lnk;
+  if (lnk) {
+    TFile* pFile=(TFile*)lnk->GetObject();
+    if (pFile) {
+      int iCopy=pFile->GetSize();
+      pFile->Seek(0);
+      if (iCopy>(int)size) {
+       iCopy=size;
+       HLTWarning("buffer to small, data of file %s truncated", pFile->GetName());
+      }
+      if (pFile->ReadBuffer((char*)outputPtr, iCopy)!=0) {
+       // ReadBuffer returns 1 in case of failure and 0 in case of success
+       iResult=-EIO;
+      } else {
+       AliHLTComponentBlockData bd;
+       FillBlockData(bd);
+       bd.fPtr=outputPtr;
+       bd.fOffset=0;
+       bd.fSize=iCopy;
+       bd.fDataType=fDataType;
+       bd.fSpecification=fSpecification;
+       outputBlocks.push_back(bd);
+       size=iCopy;
+      }
+    } else {
+      HLTError("no file available");
+      iResult=-EFAULT;
+    }
+  } else {
+    iResult=-ENOENT;
+  }
+  if (evtData.fStructSize==0 && trigData.fStructSize==0) {
+    // this is just to get rid of the warning "unused parameter"
+  }
+  return iResult;
+}
+
+AliHLTComponentDataType AliHLTFilePublisher::GetCurrentDataType() const
+{
+  return fDataType;
+}
+
+AliHLTUInt32_t          AliHLTFilePublisher::GetCurrentSpecification() const
+{
+  return fSpecification;
+}
diff --git a/HLT/BASE/util/AliHLTRootFilePublisherComponent.cxx b/HLT/BASE/util/AliHLTRootFilePublisherComponent.cxx
new file mode 100644 (file)
index 0000000..6123736
--- /dev/null
@@ -0,0 +1,138 @@
+// $Id$
+
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
+ *          for The ALICE Off-line Project.                               *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/** @file   AliHLTRootFilePublisherComponent.cxx
+    @author Matthias Richter
+    @date   
+    @brief  HLT file publisher component implementation. */
+
+#include "AliHLTRootFilePublisherComponent.h"
+//#include <TObjString.h>
+//#include <TMath.h>
+//#include <TFile.h>
+
+// temporary
+#include "TH1F.h"
+
+/** the global object for component registration */
+AliHLTRootFilePublisherComponent gAliHLTRootFilePublisherComponent;
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTRootFilePublisherComponent)
+
+AliHLTRootFilePublisherComponent::AliHLTRootFilePublisherComponent()
+  :
+  AliHLTFilePublisher()
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+
+}
+
+AliHLTRootFilePublisherComponent::AliHLTRootFilePublisherComponent(const AliHLTRootFilePublisherComponent&)
+  :
+  AliHLTFilePublisher()
+{
+  // see header file for class documentation
+  HLTFatal("copy constructor untested");
+}
+
+AliHLTRootFilePublisherComponent& AliHLTRootFilePublisherComponent::operator=(const AliHLTRootFilePublisherComponent&)
+{ 
+  // see header file for class documentation
+  HLTFatal("assignment operator untested");
+  return *this;
+}
+
+AliHLTRootFilePublisherComponent::~AliHLTRootFilePublisherComponent()
+{
+  // see header file for class documentation
+
+  // file list and file name list are owner of their objects and
+  // delete all the objects
+}
+
+const char* AliHLTRootFilePublisherComponent::GetComponentID()
+{
+  // see header file for class documentation
+  return "ROOTFilePublisher";
+}
+
+AliHLTComponentDataType AliHLTRootFilePublisherComponent::GetOutputDataType()
+{
+  // see header file for class documentation
+  AliHLTComponentDataType dt =
+    {sizeof(AliHLTComponentDataType),
+     kAliHLTVoidDataTypeID,
+     kAliHLTVoidDataOrigin};
+  return dt;
+}
+
+void AliHLTRootFilePublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+{
+  // see header file for class documentation
+  constBase=10000;
+  inputMultiplier=1.0;
+}
+
+AliHLTComponent* AliHLTRootFilePublisherComponent::Spawn()
+{
+  // see header file for class documentation
+  return new AliHLTRootFilePublisherComponent;
+}
+
+int AliHLTRootFilePublisherComponent::ScanArgument(int argc, const char** argv)
+{
+  // see header file for class documentation
+
+  // there are no other arguments than the standard ones
+  if (argc==0 && argv==NULL) {
+    // this is just to get rid of the warning "unused parameter"
+  }
+  int iResult=-EPROTO;
+  return iResult;
+}
+
+int AliHLTRootFilePublisherComponent::OpenFiles()
+{
+  // see header file for class documentation
+  int iResult=0;
+  return iResult;
+}
+
+int AliHLTRootFilePublisherComponent::GetEvent( const AliHLTComponentEventData& evtData,
+             AliHLTComponentTriggerData& trigData,
+             AliHLTUInt8_t* outputPtr, 
+             AliHLTUInt32_t& size,
+             vector<AliHLTComponentBlockData>& outputBlocks )
+{
+  int iResult=0;
+  if (GetCurrentSpecification()==0) {
+    TH1F *hpx = new TH1F("hpx","px distribution",100,-4,4);
+    hpx->FillRandom("gaus",1000);
+    PushBack(hpx, "TH1F", "ROOT");
+  } else {
+    TH1F *hpy = new TH1F("hpy","py distribution",100,-10,10);
+    hpy->FillRandom("gaus",10000);
+    PushBack(hpy, "TH1F", "ROOT");
+  }
+
+  return iResult;
+}
diff --git a/HLT/BASE/util/AliHLTRootFilePublisherComponent.h b/HLT/BASE/util/AliHLTRootFilePublisherComponent.h
new file mode 100644 (file)
index 0000000..66b2d5e
--- /dev/null
@@ -0,0 +1,97 @@
+// -*- Mode: C++ -*-
+// @(#) $Id$
+
+#ifndef ALIHLTROOTFILEPUBLISHERCOMPONENT_H
+#define ALIHLTROOTFILEPUBLISHERCOMPONENT_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/** @file   AliHLTRootFilePublisherComponent.h
+    @author Matthias Richter
+    @date   
+    @brief  component for publishing of Root objects from a root file.
+    @note   The class is used in Offline (AliRoot) context
+*/
+
+#include "AliHLTFilePublisher.h"
+#include <TList.h>
+
+/**
+ * @class AliHLTRootFilePublisherComponent
+ * An HLT data source component which publishes data from one or a sequence
+ * of files.<br>
+ *
+ * Component ID: \b RootFilePublisherComponent <br>
+ * Library: \b libHLTBase (in order to use the component from the external
+ * interface, it might be necessary to specify a dummy library with the
+ * \em -componentlibrary argument).
+ *
+ * Mandatory arguments: <br>
+ *
+ * Optional arguments:<br>
+ *
+ * @see AliHLTFilePublisher for default arguments
+ * @ingroup alihlt_component
+ */
+class AliHLTRootFilePublisherComponent : public AliHLTFilePublisher  {
+ public:
+  /** standard constructor */
+  AliHLTRootFilePublisherComponent();
+  /** not a valid copy constructor, defined according to effective C++ style */
+  AliHLTRootFilePublisherComponent(const AliHLTRootFilePublisherComponent&);
+  /** not a valid assignment op, but defined according to effective C++ style */
+  AliHLTRootFilePublisherComponent& operator=(const AliHLTRootFilePublisherComponent&);
+  /** destructor */
+  virtual ~AliHLTRootFilePublisherComponent();
+
+  const char* GetComponentID();
+  AliHLTComponentDataType GetOutputDataType();
+  void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+  AliHLTComponent* Spawn();
+
+  /**
+   * Open all files.
+   * Opens all files from the file name list @ref fFileNames and adds TFile
+   * opjects to the TFiles list.
+   */
+  int OpenFiles();
+
+ protected:
+  /**
+   * Data processing method for the component.
+   * The component uses the @ref alihltcomponent-high-level-interface
+   * to put serialized Root object into the output stream. Despite of that it
+   * implements the lox-level DumpEvent method in order to allow child classes
+   * to use the low-level method.
+   * @param evtData       event data structure
+   * @param trigData     trigger data structure
+   * @param outputPtr    pointer to target buffer
+   * @param size         <i>input</i>: size of target buffer
+   *                     <i>output</i>:size of produced data
+   * @param outputBlocks  list to receive output block descriptors
+   * @return
+   */
+  int GetEvent( const AliHLTComponentEventData& evtData,
+               AliHLTComponentTriggerData& trigData,
+               AliHLTUInt8_t* outputPtr, 
+               AliHLTUInt32_t& size,
+               vector<AliHLTComponentBlockData>& outputBlocks );
+
+  /**
+   * Scan one argument and adjacent parameters.
+   * Can be overloaded by child classes in order to add additional arguments
+   * beyond the standard arguments of the file publisher. The method is called
+   * whenever a non-standard argument is recognized.
+   * @param argc           size of the argument array
+   * @param argv           agument array for component initialization
+   * @return number of processed members of the argv <br>
+   *         -EINVAL unknown argument <br>
+   *         -EPROTO parameter for argument missing <br>
+   */
+  virtual int ScanArgument(int argc, const char** argv);
+
+ private:
+
+  ClassDef(AliHLTRootFilePublisherComponent, 0)
+};
+#endif
diff --git a/HLT/BASE/util/AliHLTRootFileWriterComponent.cxx b/HLT/BASE/util/AliHLTRootFileWriterComponent.cxx
new file mode 100644 (file)
index 0000000..87146df
--- /dev/null
@@ -0,0 +1,138 @@
+// @(#) $Id$
+
+/** @file   AliHLTRootFileWriterComponent.cxx
+    @author Matthias Richter
+    @date   
+    @brief  Base class for writer components to store data in a ROOT file
+
+                                                                          */
+
+#include "AliHLTRootFileWriterComponent.h"
+#include "TFile.h"
+#include "TString.h"
+
+/** the global object for component registration */
+AliHLTRootFileWriterComponent gAliHLTRootFileWriterComponent;
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTRootFileWriterComponent)
+
+AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent()
+  :
+  AliHLTFileWriter(),
+  fEventID(kAliHLTVoidEventID),
+  fCurrentFile(NULL)
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+
+  // all blocks of one event go into the same file
+  SetMode(kConcatenateBlocks);
+}
+
+AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent(const AliHLTRootFileWriterComponent&)
+  :
+  AliHLTFileWriter(),
+  fEventID(kAliHLTVoidEventID),
+  fCurrentFile(NULL)
+{
+  // see header file for class documentation
+  HLTFatal("copy constructor untested");
+}
+
+AliHLTRootFileWriterComponent& AliHLTRootFileWriterComponent::operator=(const AliHLTRootFileWriterComponent&)
+{
+  // see header file for class documentation
+  HLTFatal("assignment operator untested");
+  return *this;
+}
+
+AliHLTRootFileWriterComponent::~AliHLTRootFileWriterComponent()
+{
+  // see header file for class documentation
+}
+
+int AliHLTRootFileWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData,
+                                           const AliHLTComponentBlockData* blocks, 
+                                           AliHLTComponentTriggerData& trigData )
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0) {
+    // this is just to get rid of the warning "unused parameter"
+  }
+  const TObject* pObj=GetFirstInputObject(kAliHLTAnyDataType);
+  HLTDebug("got first object %p", pObj);
+  int count=0;
+  while (pObj && iResult>=0) {
+    iResult=WriteObject(evtData.fEventID, pObj);
+    if (iResult) {
+      count++;
+      HLTDebug("wrote object of class %s, data type %s", pObj->ClassName(), (DataType2Text(GetDataType(pObj)).c_str())); 
+    }
+    pObj=GetNextInputObject();
+  }
+  HLTDebug("wrote %d of %d object(s) to file", count, GetNumberOfInputBlocks());
+  return iResult;
+}
+
+int AliHLTRootFileWriterComponent::ScanArgument(int argc, const char** argv)
+{
+  // see header file for class documentation
+  // no other arguments known
+  if (argc==0 && argv==NULL) {
+    // this is just to get rid of the warning "unused parameter"
+  }
+  int iResult=-EPROTO;
+  return iResult;
+}
+
+int AliHLTRootFileWriterComponent::WriteObject(const AliHLTEventID_t eventID, const TObject *pOb)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (pOb) {
+    HLTDebug("write object %p (%s)", pOb, pOb->GetName());
+    if (CheckMode(kConcatenateEvents) && eventID != fEventID &&
+       fCurrentFile!=NULL && eventID!=kAliHLTVoidEventID) {
+      TFile* pFile=fCurrentFile; fCurrentFile=NULL;
+      pFile->Close(); delete pFile;
+    }
+    if (fCurrentFile==NULL) {
+      fCurrentFile=OpenFile(eventID, 0);
+      if (fCurrentFile) fEventID=eventID;
+    }
+    if (fCurrentFile) {
+      fCurrentFile->cd();
+      pOb->Write();
+    } else {
+      iResult=-EBADF;
+    }
+  }
+  return iResult;
+}
+
+TFile* AliHLTRootFileWriterComponent::OpenFile(const AliHLTEventID_t eventID, const int blockID, const char* option)
+{
+  // see header file for class documentation
+  TFile* pFile=NULL;
+  TString filename("");
+  if ((BuildFileName(eventID, blockID, kAliHLTVoidDataType, filename))>=0 && filename.IsNull()==0) {
+    pFile=new TFile(filename, option);
+    if (pFile) {
+      if (pFile->IsZombie()) {
+       delete pFile;
+       pFile=NULL;
+       HLTError("can not open ROOT file %s", filename.Data());
+      }
+    } else {
+      HLTFatal("memory allocation failed");
+    }
+  } else {
+    HLTError("failed to build a new file name for event %#8x", eventID);
+  }
+  return pFile;
+}
diff --git a/HLT/BASE/util/AliHLTRootFileWriterComponent.h b/HLT/BASE/util/AliHLTRootFileWriterComponent.h
new file mode 100644 (file)
index 0000000..9f9a0ff
--- /dev/null
@@ -0,0 +1,109 @@
+// -*- Mode: C++ -*-
+// @(#) $Id$
+
+#ifndef ALIHLTROOTFILEWRITERCOMPONENT_H
+#define ALIHLTROOTFILEWRITERCOMPONENT_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/** @file   AliHLTRootFileWriterComponent.h
+    @author Matthias Richter
+    @date   
+    @brief  Base class for writer components to store data in a ROOT file
+
+                                                                          */
+#include "AliHLTFileWriter.h"
+#include "TObject.h" 
+
+class TFile;
+
+/**
+ * @class AliHLTRootFileWriterComponent
+ * The RootFileWriter provides a stand alone component to write incoming
+ * TObject like structures into a Root file. Furthermore it functions as
+ * base class for customized writers.
+ * @see AliHLTFileWriter for parameters
+ */
+class AliHLTRootFileWriterComponent : public AliHLTFileWriter
+{
+ public:
+  /** standard constructor */
+  AliHLTRootFileWriterComponent();
+  /** not a valid copy constructor, defined according to effective C++ style */
+  AliHLTRootFileWriterComponent(const AliHLTRootFileWriterComponent&);
+  /** not a valid assignment op, but defined according to effective C++ style */
+  AliHLTRootFileWriterComponent& operator=(const AliHLTRootFileWriterComponent&);
+  /** destructor */
+  ~AliHLTRootFileWriterComponent();
+
+  /**
+   * The id of the component.
+   * @return component id (string)
+   */
+  virtual const char* GetComponentID() {return "ROOTFileWriter";};
+
+  /**
+   * Spawn function.
+   * @return new class instance
+   */
+  virtual AliHLTComponent* Spawn() {return new AliHLTRootFileWriterComponent;}
+
+ protected:
+  /**
+   * Data processing method for the component.
+   * The function can be overloaded by specific ROOT file writer
+   * components. The RootFileWriter processes only TObject like data
+   * structures of the input blocks and uses the
+   * @ref alihltcomponent-high-level-interface. Despite of that it implements
+   * the lox-level DumpEvent method in order to allow child classes to use the
+   * low-level method.
+   * @param evtData       event data structure
+   * @param blocks        input data block descriptors
+   * @param trigData     trigger data structure
+   */
+  virtual int DumpEvent( const AliHLTComponentEventData& evtData,
+                        const AliHLTComponentBlockData* blocks, 
+                        AliHLTComponentTriggerData& trigData );
+
+  /**
+   * Scan one argument and adjacent parameters.
+   * \b IMPORTANT: if  overloaded by child class, call this function
+   * as the default from the cutomized switch, e.g.
+   * <pre>
+   * </pre>
+   * @param argc           size of the argument array
+   * @param argv           agument array for component initialization
+   * @return number of processed members of the argv <br>
+   *         -EINVAL unknown argument <br>
+   *         -EPROTO parameter for argument missing <br>
+   */
+  virtual int ScanArgument(int argc, const char** argv);
+
+  /**
+   * Write ROOT object to current file.
+   * @param eventID    ID of the current event
+   * @param pOb        pointer to ROOT object
+   * @return neg. error code if failed
+   */
+  int WriteObject(const AliHLTEventID_t eventID, const TObject *pOb);
+
+  /**
+   * Open a ROOT file.
+   * The function calls @ref AliHLTFileWriter::BuildFileName in order to
+   * create a file name and opens it as a root file.
+   * @param eventID    ID of the current event
+   * @param blockID    ID of the current block
+   * @param option     option as specified in TFile
+   * @return pointer to TFile object, the called has to clean-up the object after use.
+   */
+  TFile* OpenFile(const AliHLTEventID_t eventID, const int blockID=-1, const char* option="recreate");
+
+  /** the event ID associated with the current file */
+  AliHLTEventID_t fEventID; // see above
+
+  /** the name of the current file */
+  TFile* fCurrentFile; //! transient value
+
+  ClassDef(AliHLTRootFileWriterComponent, 0)
+};
+#endif