]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/util/AliHLTRootSchemaEvolutionComponent.h
minor code cleanup and coding rules
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTRootSchemaEvolutionComponent.h
index 5f3fc99aef2e6f77897d45ac79ee908beccfccbc..ac1cacc2ffd5480fdbd649d5b69a3e5212814eb1 100644 (file)
@@ -3,26 +3,36 @@
 
 #ifndef ALIHLTROOTSCHEMAEVOLUTIONCOMPONENT_H
 #define ALIHLTROOTSCHEMAEVOLUTIONCOMPONENT_H
-//* This file is property of and copyright by the ALICE HLT Project        * 
+//* This file is property of and copyright by the ALICE                    * 
 //* ALICE Experiment at CERN, All rights reserved.                         *
 //* See cxx source for full Copyright notice                               *
 
-/** @file   AliHLTRootSchemaEvolutionComponent.h
-    @author Matthias Richter
-    @date   2009-10-18
-    @brief  Handler component for ROOT schema evolution of streamed objects
-*/
+/// @file   AliHLTRootSchemaEvolutionComponent.h
+/// @author Matthias Richter
+/// @date   2009-10-18
+/// @brief  Handler component for ROOT schema evolution of streamed objects
+///
 
-#include "AliHLTProcessor.h"
+#include "AliHLTCalibrationProcessor.h"
+#include "TString.h"
+#include <vector>
 
 class TObjArray;
+class TObject;
+class TStopwatch;
+class AliHLTMessage;
 
 /**
  * @class AliHLTRootSchemaEvolutionComponent
+ * Collects streamer info for all input objects and produces the corresponding
+ * calibration object for reconstruction of HLT. The component runs with a
+ * configurable rate constraint and skips the processing of known data blocks
+ * for the sake of performance. New data blocks are always processed and added
+ * to the list.
  *
  * <h2>General properties:</h2>
  *
- * Component ID: \b ROOTFileWriter                                      <br>
+ * Component ID: \b ROOTSchemaEvolutionComponent                        <br>
  * Library: \b libAliHLTUtil.so                                                <br>
  * Input Data Types: ::kAliHLTAnyDataType                              <br>
  * Output Data Types: none                                             <br>
@@ -32,13 +42,19 @@ class TObjArray;
  *      
  * <h2>Optional arguments:</h2>
  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
- * \li -fxs<=off> <br>
+ * \li -fxs<=[n,off]> <br>
  *      push streamer info to FXS, fetched by Shuttle and store in the entry
- *      HLT/Calib/StreamerInfo
- *      default off
+ *      HLT/Calib/StreamerInfo                                          <br>
+ *      if a scalar greather then 0 is specified the calibration object is
+ *      pushed during the event processing with the specified scale down<br>
+ *      always pushed on EOR, default on
  * \li -hltout<=[all,first,eor,off]> <br>
  *      push streamer info to output, the streamer info is stored in the
  *      events in all, the first, and/or the EOR.
+ * \li -file=filename <br>
+ *      write to file at EOR
+ * \li -rate=hz <br>
+ *      required processing rate in Hz, default 2000Hz
  *
  * <h2>Configuration:</h2>
  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
@@ -48,7 +64,8 @@ class TObjArray;
  * The component loads no CDB entries.
  *
  * <h2>Performance:</h2>
- * The component does not process any event data.
+ * TODO: update performance requirements for unpacking ESDs and creating the
+ * streamer info
  *
  * <h2>Memory consumption:</h2>
  * The component does not process any event data.
@@ -58,7 +75,7 @@ class TObjArray;
  *
  * @ingroup alihlt_util_components
  */
-class AliHLTRootSchemaEvolutionComponent : public AliHLTProcessor
+class AliHLTRootSchemaEvolutionComponent : public AliHLTCalibrationProcessor
 {
  public:
   /// standard constructor
@@ -69,7 +86,7 @@ class AliHLTRootSchemaEvolutionComponent : public AliHLTProcessor
   /// inherited from AliHLTComponent: return id of the component.
   virtual const char* GetComponentID() {return "ROOTSchemaEvolutionComponent";};
   /// inherited from AliHLTComponent: input data types
-  virtual void GetInputDataTypes(AliHLTComponentDataTypeList&);
+  virtual void GetInputDataTypes(AliHLTComponentDataTypeList& list);
   /// inherited from AliHLTComponent: output data types
   virtual AliHLTComponentDataType GetOutputDataType();
   /// inherited from AliHLTComponent: output data size
@@ -96,17 +113,92 @@ class AliHLTRootSchemaEvolutionComponent : public AliHLTProcessor
   /// and adds if it is a new info. 
   int UpdateStreamerInfos(const TList* list, TObjArray* infos) const;
 
+  /// merge streamer info entries from source array to target array
+  /// add all existing infos if not existing in the current one, or having
+  /// different class version
+  /// return 1 if target array has been changed
+  static int MergeStreamerInfo(TObjArray* tgt, const TObjArray* src);
+
+  class AliHLTDataBlockItem
+  {
+  public:
+    AliHLTDataBlockItem(AliHLTComponentDataType dt=kAliHLTVoidDataType,
+                       AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
+    ~AliHLTDataBlockItem();
+
+    /// extract data block to root object, and update performance parameters
+    /// object needs to be deleted externally
+    TObject* Extract(const AliHLTComponentBlockData* bd);
+
+    /// stream object and update performance parameters
+    int Stream(const TObject* obj, AliHLTMessage& msg);
+
+    bool IsObject() const {return fIsObject;}
+    bool operator==(const AliHLTDataBlockItem& i) const {return fDt==i.fDt && fSpecification==i.fSpecification;}
+    bool operator==(AliHLTComponentDataType dt) const {return fDt==dt;}
+    bool operator==(AliHLTUInt32_t spec) const {return fSpecification==spec;}
+    operator const AliHLTComponentDataType&() const {return fDt;}
+    AliHLTUInt32_t GetSpecification() const {return fSpecification;}
+    
+    /// average extraction time in usec
+    AliHLTUInt32_t GetExtractionTime() const {return fNofExtractions>0?fExtractionTimeUsec/fNofExtractions:0;}
+    /// average streaming time in usec
+    AliHLTUInt32_t GetStreamingTime() const {return fNofStreamings>0?fStreamingTimeUsec/fNofStreamings:0;}
+    /// average total time in usec
+    AliHLTUInt32_t GetTotalTime() const {return GetExtractionTime() + GetStreamingTime();}
+
+    /// print status
+    void Print(const char* option) const;
+
+  private:
+    /// data type of the block
+    AliHLTComponentDataType fDt; //! transient
+    /// specification of the block
+    AliHLTUInt32_t fSpecification; //! transient
+    /// flag for TObject
+    bool fIsObject; //! transient
+
+    /// number of extractions
+    AliHLTUInt32_t fNofExtractions; //! transient
+    /// object extraction time in usec
+    AliHLTUInt32_t fExtractionTimeUsec; //! transient
+    /// timestamp of last extraction in usec
+    AliHLTUInt32_t fLastExtraction; //! transient
+    /// number of streamings
+    AliHLTUInt32_t fNofStreamings; //! transient
+    /// object streaming time in usec
+    AliHLTUInt32_t fStreamingTimeUsec; //! transient
+    /// timestamp of last streaming in usec
+    AliHLTUInt32_t fLastStreaming; // !transient
+  };
+
+  /// find item in the list
+  AliHLTDataBlockItem* FindItem(AliHLTComponentDataType dt,
+                               AliHLTUInt32_t spec);
+
  protected:
-  /// inherited from AliHLTComponent: custom initialization
-  int DoInit( int argc, const char** argv );
-  /// inherited from AliHLTComponent: cleanup
-  int DoDeinit();
-
-  /// inherited from AliHLTProcessor processing
-  virtual int DoEvent( const AliHLTComponentEventData& evtData,
-                      AliHLTComponentTriggerData& trigData );
+  /// inherited from AliHLTCalibrationProcessor: custom initialization
+  int InitCalibration();
+  /// inherited from AliHLTCalibrationProcessor: custom argument scan
+  /// the AliHLTCalibrationProcessor so far does not use the base class
+  /// methods for argument scan.
+  int ScanArgument( int argc, const char** argv ) {
+    int result=ScanConfigurationArgument(argc, argv); return result>0?result-1:result;
+  }
+  /// inherited from AliHLTCalibrationProcessor: cleanup
+  int DeinitCalibration();
+
+  /// inherited from AliHLTCalibrationProcessor processing
+  virtual int ProcessCalibration( const AliHLTComponentEventData& evtData,
+                                 AliHLTComponentTriggerData& trigData );
   
-  using AliHLTProcessor::DoEvent;
+  using AliHLTCalibrationProcessor::ProcessCalibration;
+
+  /// inherited from AliHLTCalibrationProcessor processing
+  int ShipDataToFXS( const AliHLTComponentEventData& evtData,
+                    AliHLTComponentTriggerData& trigData);
+
+  using AliHLTCalibrationProcessor::ShipDataToFXS;
 
   /**
    * Inherited from AliHLTComponent
@@ -115,9 +207,10 @@ class AliHLTRootSchemaEvolutionComponent : public AliHLTProcessor
    */
   virtual int ScanConfigurationArgument(int argc, const char** argv);
 
-  void SetBits(AliHLTUInt32_t b) {fFlags|=b;}
-  void ClearBits(AliHLTUInt32_t b) {fFlags&=~b;}
-  bool TestBits(AliHLTUInt32_t b) {return (fFlags&b) != 0;}
+  void SetBits(AliHLTUInt32_t b) {fPropertyFlags|=b;}
+  void ClearBits(AliHLTUInt32_t b) {fPropertyFlags&=~b;}
+  bool TestBits(AliHLTUInt32_t b) const {return (fPropertyFlags&b) != 0;}
+  int WriteToFile(const char* filename, const TObjArray* infos) const;
 
 private:
   /** copy constructor prohibited */
@@ -125,14 +218,22 @@ private:
   /** assignment operator prohibited */
   AliHLTRootSchemaEvolutionComponent& operator=(const AliHLTRootSchemaEvolutionComponent&);
 
-  AliHLTUInt32_t fFlags; //! property flags
+  vector<AliHLTDataBlockItem> fList; //! list of block properties
+
+  AliHLTUInt32_t fPropertyFlags; //! property flags
 
   TObjArray* fpStreamerInfos; //! array of streamer infos
+  TStopwatch* fpEventTimer; //! stopwatch for event processing
+  TStopwatch* fpCycleTimer; //! stopwatch for event cycle
+  AliHLTUInt32_t fMaxEventTime; //! required maximum processing time in usec
 
   AliHLTUInt32_t fFXSPrescaler; //! prescalar for the publishing to FXS
 
+  TString fFileName; //! file name for dump at EOR
+
   static const char* fgkConfigurationObject; //! configuration object
+  static const AliHLTUInt32_t fgkTimeScale; //! timescale base
 
-  ClassDef(AliHLTRootSchemaEvolutionComponent, 1) // ROOT schema evolution component
+  ClassDef(AliHLTRootSchemaEvolutionComponent, 0) // ROOT schema evolution component
 };
 #endif