LCOV - code coverage report
Current view: top level - RAW/RAWDatasim - AliBitPacking.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 24 58.3 %
Date: 2016-06-14 17:26:59 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : ///////////////////////////////////////////////////////////////////////////////
      19             : ///
      20             : /// This is a service class for packing and unpacking bits in a 32 bit word.
      21             : ///
      22             : ///////////////////////////////////////////////////////////////////////////////
      23             : 
      24             : #include <TError.h>
      25             : 
      26             : #include "AliBitPacking.h"
      27             : 
      28             : 
      29         122 : ClassImp(AliBitPacking)
      30             : 
      31             : 
      32             : //_____________________________________________________________________________
      33             : Bool_t AliBitPacking::PackWord(UInt_t data, UInt_t &word, 
      34             :                                Int_t startBit, Int_t stopBit)
      35             : {
      36             : // Packs data into the word buffer from startBit bit up to stopBit bit
      37             : 
      38             :   // check that startBit and stopBit are reasonable
      39      893894 :   if (startBit > stopBit) {
      40           0 :     ::Error("AliBitPacking::PackWord", 
      41             :             "startBit is larger than stopBit");
      42           0 :     return kFALSE;
      43             :   }
      44      446947 :   if (stopBit > 31) {
      45           0 :     ::Error("AliBitPacking::PackWord", 
      46             :             "stopBit exceeds valid range of 32 bits");
      47           0 :     return kFALSE;
      48             :   }
      49             : 
      50             :   // create a word with the bits 0 to (stopBit-startBit) set
      51             :   UInt_t bits = 0xFFFFFFFF;
      52      893506 :   if (stopBit-startBit < 31) bits = (1 << (stopBit-startBit+1)) - 1;
      53             : 
      54             :   // check that the data fits into the given bit range
      55      446947 :   if (data > bits){
      56           0 :     ::Error("AliBitPacking::PackWord", 
      57             :             "Word to be filled is not within desired length");
      58           0 :     return kFALSE;
      59             :   }
      60             : 
      61             :   // clear the bits from startBit to stopBit
      62      446947 :   word &= (0xFFFFFFFF ^ (bits << startBit));
      63             : 
      64             :   // fill in the data bits
      65      446947 :   word |= (data << startBit);
      66             : 
      67      446947 :   return kTRUE;
      68      446947 : }
      69             : 
      70             : //_____________________________________________________________________________
      71             : UInt_t AliBitPacking::UnpackWord(UInt_t word, Int_t startBit, Int_t stopBit)
      72             : {
      73             : // Unpacks data of stopBit-startBit+1 bits from word buffer starting from 
      74             : // the position indicated by startBit
      75             : 
      76             :   // check that startBit and stopBit are reasonable
      77      110068 :   if (startBit > stopBit) {
      78           0 :     ::Error("AliBitPacking::UnpackWord", 
      79             :             "startBit is larger than stopBit");
      80           0 :     return 0xFFFFFFFF;
      81             :   }
      82       55034 :   if (stopBit > 31) {
      83           0 :     ::Error("AliBitPacking::UnpackWord", 
      84             :             "stopBit exceeds valid range of 32 bits");
      85           0 :     return 0xFFFFFFFF;
      86             :   }
      87             : 
      88             :   // create a word with the bits 0 to (stopBit-startBit) set
      89             :   UInt_t bits = 0xFFFFFFFF;
      90      110068 :   if (stopBit-startBit < 31) bits = (1 << (stopBit-startBit+1)) - 1;
      91             : 
      92             :   // pick out the requested bits
      93       55034 :   return ((word >> startBit) & bits);
      94       55034 : }

Generated by: LCOV version 1.11