]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
suporting bitsets; adding new helper interface functions
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 18 Sep 2011 10:35:30 +0000 (10:35 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 18 Sep 2011 10:35:30 +0000 (10:35 +0000)
HLT/BASE/AliHLTDataDeflater.cxx
HLT/BASE/AliHLTDataDeflater.h

index 291b9b0a95e0a8cf9c86d1c0a23526ba44f29e18..26506d6d6fa5105354708463a05459161d031ab4 100644 (file)
@@ -173,6 +173,39 @@ bool AliHLTDataDeflater::OutputBits( AliHLTUInt64_t const & value, UInt_t const
   return true;
 }
 
+bool AliHLTDataDeflater::OutputBits( std::bitset<64> const & value, UInt_t const & bitCount )
+{
+  // write bit pattern to the current byte and position
+  if ( bitCount>64 ) {
+    HLTFatal( "Internal error: Attempt to write more than 64 bits (%u)", (unsigned)bitCount );
+    return false;
+  }
+  static const std::bitset<64> mask8bit(255ul);
+  UInt_t bitsToWrite=bitCount;
+  UInt_t curBitCount;
+  while ( bitsToWrite>0 ) {
+    if ( fBitDataCurrentOutput>=fBitDataCurrentOutputEnd )
+      return false;
+    if ( bitsToWrite >= fBitDataCurrentPosInWord+1 )
+      curBitCount = fBitDataCurrentPosInWord+1;
+    else
+      curBitCount = bitsToWrite;
+    std::bitset<64> valwrite=(value >> (bitsToWrite-curBitCount)) & mask8bit;
+    fBitDataCurrentWord |= ( valwrite.to_ulong() & ((1<<curBitCount)-1) ) << (fBitDataCurrentPosInWord+1-curBitCount);
+    if ( fBitDataCurrentPosInWord < curBitCount )
+      {
+       *fBitDataCurrentOutput = fBitDataCurrentWord;
+       fBitDataCurrentPosInWord = 7;
+       fBitDataCurrentOutput++;
+       fBitDataCurrentWord = 0;
+      }
+    else
+      fBitDataCurrentPosInWord -= curBitCount;
+    bitsToWrite -= curBitCount;
+  }
+  return true;
+}
+
 void AliHLTDataDeflater::Pad8Bits()
 {
   // finish the current word
index b5d1e5ec91d5e3f37a2d4560c33bc4b8cb1a7848..c58391e8668bdfb19f1a7057434ce9cd6bbeded6 100644 (file)
@@ -15,6 +15,7 @@
 #include "AliHLTLogging.h"
 #include "AliHLTDataTypes.h"
 #include "AliHLTStdIncludes.h"
+#include <bitset>
 
 /**
  * @class AliHLTDataDeflater
@@ -85,6 +86,13 @@ public:
    */
   bool OutputBits( AliHLTUInt64_t const & value, UInt_t const & bitCount );
 
+  /** function to output bits from a bitset
+   * @param value     AliHLTUInt64_t const &
+   * @param bitCount  UInt_t const &
+   * @return zero upon success
+   */
+  bool OutputBits( std::bitset<64> const & value, UInt_t const & bitCount );
+
   /* function pad 8 bits */
   void Pad8Bits();
 
@@ -104,6 +112,12 @@ public:
   /// print info
   virtual void Print(ostream& out, Option_t *option="") const;
 
+  /// find object
+  virtual TObject *FindObject(const char */*name*/) const {return NULL;}
+
+  /// save data according to option
+  virtual void SaveAs(const char */*filename*/="",Option_t */*option*/="") const {}
+
   /// write bit pattern of a parameter to the current byte and position
   virtual bool OutputParameterBits( int parameterId, AliHLTUInt64_t const & value );