]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
added AliHLTTPCDigitPublisherComponent
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 20 Sep 2007 09:36:35 +0000 (09:36 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 20 Sep 2007 09:36:35 +0000 (09:36 +0000)
HLT/TPCLib/offline/AliHLTTPCDigitPublisherComponent.cxx [new file with mode: 0644]
HLT/TPCLib/offline/AliHLTTPCDigitPublisherComponent.h [new file with mode: 0644]

diff --git a/HLT/TPCLib/offline/AliHLTTPCDigitPublisherComponent.cxx b/HLT/TPCLib/offline/AliHLTTPCDigitPublisherComponent.cxx
new file mode 100644 (file)
index 0000000..2f0da5d
--- /dev/null
@@ -0,0 +1,212 @@
+// @(#) $Id$
+
+/**************************************************************************
+ * This file is property of and copyright by the ALICE HLT Project        * 
+ * ALICE Experiment at CERN, All rights reserved.                         *
+ *                                                                        *
+ * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
+ *                  for The ALICE HLT 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   AliHLTTPCDigitPublisherComponent.cxx
+    @author Matthias Richter
+    @date   
+    @brief  TPC digit publisher component (input from offline).
+*/
+
+#include "AliHLTTPCDigitPublisherComponent.h"
+#include "AliRunLoader.h"
+#include "AliLog.h"
+#include "TTree.h"
+#include "AliHLTTPCDigitData.h"
+#include "AliHLTTPCDefinitions.h"
+#include "AliHLTTPCFileHandler.h"
+
+/** global instance for agent registration */
+AliHLTTPCDigitPublisherComponent gAliHLTTPCDigitPublisherComponent;
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTTPCDigitPublisherComponent)
+
+AliHLTTPCDigitPublisherComponent::AliHLTTPCDigitPublisherComponent()
+  :
+  fMaxSize(200000), // just a number to start with
+  fMinSlice(0),
+  fMinPart(0),
+  fpFileHandler(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
+}
+
+AliHLTTPCDigitPublisherComponent::~AliHLTTPCDigitPublisherComponent()
+{
+  // see header file for class documentation
+  if (fpFileHandler) {
+    HLTWarning("improper state, de-initialization missing");
+    DoDeinit();
+  }
+}
+
+const char* AliHLTTPCDigitPublisherComponent::GetComponentID()
+{
+  // see header file for class documentation
+  return "TPCDigitPublisher";
+}
+
+AliHLTComponentDataType AliHLTTPCDigitPublisherComponent::GetOutputDataType()
+{
+  return AliHLTTPCDefinitions::fgkUnpackedRawDataType;
+}
+
+void AliHLTTPCDigitPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+{
+  constBase=fMaxSize;
+  inputMultiplier=1;
+}
+
+AliHLTComponent* AliHLTTPCDigitPublisherComponent::Spawn()
+{
+  // see header file for class documentation
+  return new AliHLTTPCDigitPublisherComponent;
+}
+
+int AliHLTTPCDigitPublisherComponent::DoInit( int argc, const char** argv )
+{
+  // see header file for class documentation
+  int iResult=0;
+
+  // scan arguments
+  TString argument="";
+  int bMissingParam=0;
+  for (int i=0; i<argc && iResult>=0; i++) {
+    argument=argv[i];
+    if (argument.IsNull()) continue;
+
+    // -slice
+    if (argument.CompareTo("-slice")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      TString parameter(argv[i]);
+      parameter.Remove(TString::kLeading, ' '); // remove all blanks
+      if (parameter.IsDigit()) {
+       fMinSlice=parameter.Atoi();
+      } else {
+       HLTError("wrong parameter for argument %s, number expected", argument.Data());
+       iResult=-EINVAL;
+      }
+      // -partition
+    } else if (argument.CompareTo("-partition")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      TString parameter(argv[i]);
+      parameter.Remove(TString::kLeading, ' '); // remove all blanks
+      if (parameter.IsDigit()) {
+       fMinPart=parameter.Atoi();
+      } else {
+       HLTError("wrong parameter for argument %s, number expected", argument.Data());
+       iResult=-EINVAL;
+      }
+    } else {
+      HLTError("unknown argument %s", argument.Data());
+      iResult=-EINVAL;
+    }
+  }
+  if (bMissingParam) {
+    HLTError("missing parameter for argument %s", argument.Data());
+    iResult=-EINVAL;
+  }
+
+  if (iResult<0) return iResult;
+
+  // fetch runLoader instance from interface
+  AliRunLoader* pRunLoader=GetRunLoader();
+  if (pRunLoader) {
+    fpFileHandler=new AliHLTTPCFileHandler;
+    if (fpFileHandler) {
+      fpFileHandler->Init(fMinSlice,fMinPart);    
+      fpFileHandler->SetAliInput(pRunLoader);
+    } else {
+      AliErrorStream() << "can not allocate file handler object" << endl;
+      iResult=-EFAULT;
+    }
+  } else {
+    AliErrorStream() << "can not get runLoader" << endl;
+    iResult=-EFAULT;
+  }
+  return iResult;
+}
+
+int AliHLTTPCDigitPublisherComponent::DoDeinit()
+{
+  // see header file for class documentation
+  int iResult=0;
+  try {
+    if (fpFileHandler) {
+      delete fpFileHandler;
+    }
+  }
+  catch (...) {
+    HLTFatal("exeption during object cleanup");
+    iResult=-EFAULT;
+  }
+  fpFileHandler=NULL;
+  return iResult;
+}
+
+int AliHLTTPCDigitPublisherComponent::GetEvent(const AliHLTComponentEventData& evtData,
+                                              AliHLTComponentTriggerData& trigData,
+                                              AliHLTUInt8_t* outputPtr, 
+                                              AliHLTUInt32_t& size,
+                                              vector<AliHLTComponentBlockData>& outputBlocks)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (outputPtr==NULL || size==0) {
+    HLTError("no target buffer provided");
+    return -EFAULT;
+  }
+
+  if (fpFileHandler) {
+    int event=GetEventCount();
+    AliHLTTPCUnpackedRawData* pTgt=reinterpret_cast<AliHLTTPCUnpackedRawData*>(outputPtr);
+    if (pTgt) {
+      UInt_t nrow=0;
+      UInt_t tgtSize=size-sizeof(AliHLTTPCUnpackedRawData);
+      AliHLTTPCDigitRowData* pData=fpFileHandler->AliDigits2Memory(nrow, event, reinterpret_cast<Byte_t*>(pTgt->fDigits), &tgtSize);
+      if (pData==NULL && tgtSize>0 && tgtSize>fMaxSize) {
+       HLTInfo("target buffer too small: %d byte required, %d available", tgtSize+sizeof(AliHLTTPCUnpackedRawData), size);
+       // indicate insufficient buffer size, on occasion the frameworks calls
+       // again with the corrected buffer 
+       fMaxSize=tgtSize;
+       iResult=-ENOSPC;
+      } else if (pData!=pTgt->fDigits) {
+       HLTError("can not read directly into output buffer");
+       try {delete pData;}
+       catch (...) {/* no action */}
+       iResult=-EIO;
+      } else {
+       size=tgtSize+sizeof(AliHLTTPCUnpackedRawData);
+       AliHLTComponentBlockData bd;
+       FillBlockData( bd );
+       bd.fOffset = 0;
+       bd.fSize = size;
+       bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(fMinSlice, fMinSlice, fMinPart, fMinPart);
+       outputBlocks.push_back( bd );
+      }
+    }
+  } else {
+    AliErrorStream() << "component not initialized" << endl;
+    iResult=-EFAULT;
+  }
+  return iResult;
+}
diff --git a/HLT/TPCLib/offline/AliHLTTPCDigitPublisherComponent.h b/HLT/TPCLib/offline/AliHLTTPCDigitPublisherComponent.h
new file mode 100644 (file)
index 0000000..25e539e
--- /dev/null
@@ -0,0 +1,127 @@
+//-*- Mode: C++ -*-
+// @(#) $Id$
+
+#ifndef ALIHLTTPCDIGITPUBLISHERCOMPONENT_H
+#define ALIHLTTPCDIGITPUBLISHERCOMPONENT_H
+/* This file is property of and copyright by the ALICE HLT Project        * 
+ * ALICE Experiment at CERN, All rights reserved.                         *
+ * See cxx source for full Copyright notice                               */
+
+/** @file   AliHLTTPCDigitPublisherComponent.h
+    @author Matthias Richter
+    @date   
+    @brief  TPC digit publisher component (input from offline).
+*/
+
+#include "AliHLTOfflineDataSource.h"
+
+class AliHLTTPCFileHandler;
+
+/**
+ * @class AliHLTTPCDigitPublisherComponent
+ * A digit publisher component for the TPC.
+ * 
+ * Component ID: \b TPCDigitPublisher <br>
+ * Library: \b libAliHLTTPC.
+ *
+ * Mandatory arguments: <br>
+ * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formating -->
+ * \li -slice     <i> no </i> <br>
+ *      TPC slice no (slice = inner + outer sector)
+ * \li -partition     <i> no </i> <br>
+ *      readout partition no
+ *
+ * Optional arguments:<br>
+ *
+ *
+ * @ingroup alihlt_system
+ */
+class AliHLTTPCDigitPublisherComponent : public AliHLTOfflineDataSource {
+ public:
+  /** standard constructor */
+  AliHLTTPCDigitPublisherComponent();
+  /** destructor */
+  virtual ~AliHLTTPCDigitPublisherComponent();
+
+  /**
+   * Get the id of the component.
+   * Each component is identified by a unique id.
+   * The function is pure virtual and must be implemented by the child class.
+   * @return component id (string)
+   */
+  const char* GetComponentID();
+
+  /**
+   * Get the output data type of the component.
+   * The function is pure virtual and must be implemented by the child class.
+   * @return output data type
+   */
+  AliHLTComponentDataType GetOutputDataType();
+
+  /**
+   * Get a ratio by how much the data volume is shrinked or enhanced.
+   * The function is pure virtual and must be implemented by the child class.
+   * @param constBase        <i>return</i>: additive part, independent of the
+   *                                   input data volume  
+   * @param inputMultiplier  <i>return</i>: multiplication ratio
+   * @return values in the reference variables
+   */
+  void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+
+  /**
+   * Spawn function.
+   * Each component must implement a spawn function to create a new instance of 
+   * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
+   * @return new class instance
+   */
+  virtual AliHLTComponent* Spawn();
+
+ protected:
+  /**
+   * Init method.
+   */
+  int DoInit( int argc, const char** argv );
+
+  /**
+   * Deinit method.
+   */
+  int DoDeinit();
+
+  /**
+   * Data source 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 neg. error code if failed
+   */
+  int GetEvent( const AliHLTComponentEventData& evtData,
+               AliHLTComponentTriggerData& trigData,
+               AliHLTUInt8_t* outputPtr, 
+               AliHLTUInt32_t& size,
+               vector<AliHLTComponentBlockData>& outputBlocks );
+
+ private:
+  /** copy constructor prohibited */
+  AliHLTTPCDigitPublisherComponent(const AliHLTTPCDigitPublisherComponent&);
+  /** assignment operator prohibited */
+  AliHLTTPCDigitPublisherComponent& operator=(const AliHLTTPCDigitPublisherComponent&);
+
+  /** max output block size, estimate during DoInit */
+  Int_t                   fMaxSize;                                //!transient
+
+  /** first slice (range of slices currently not implemented) */
+  int                     fMinSlice;                               //!transient
+
+  /** first partition (range of partitions currently not implemented) */
+  int                     fMinPart;                                //!transient
+
+  /** instance of the file handler */
+  AliHLTTPCFileHandler*   fpFileHandler;                           //!transient
+
+  ClassDef(AliHLTTPCDigitPublisherComponent, 0);
+};
+
+#endif