Skip to content

Instantly share code, notes, and snippets.

@pgjones
Last active August 29, 2015 13:57
Show Gist options
  • Save pgjones/9662558 to your computer and use it in GitHub Desktop.
Save pgjones/9662558 to your computer and use it in GitHub Desktop.
////////////////////////////////////////////////////////////////////////
/// \class RAT::DS::DataCleaningFlags
///
/// \brief This class contains the data cleaning flags for an event
///
/// \author R Bonventre <[email protected]>\n
/// Phil G Jones <[email protected]>
///
/// REVISION HISTORY:\n
/// 2013-10-16: P G Jones - New ds refactor. \n
///
/// \detail The flags are indexed by key (or pass).
///
////////////////////////////////////////////////////////////////////////
#ifndef __RAT_DS_DataCleaningFlags__
#define __RAT_DS_DataCleaningFlags__
#include <TObject.h>
namespace RAT
{
namespace DS
{
class DataCleaningFlags : public TObject
{
public:
class BitMask : public TObject
{
public:
/// Set the flag at index to value
///
/// @param[in] index of the flag
/// @param[in] value of the flag defaults to true
inline void SetFlag( const size_t index, const Bool_t value=true );
/// Get the flag value at index
///
/// @param[in] index of the flag
/// @return value of the flag
inline Bool_t GetFlag( const size_t index ) const;
private:
std::vector<UChar_t> flags; /// < The data cleaning flags
};
/// Construct the DataCleaningFlags
DataCleaningFlags() : TObject() { }
virtual ~DataCleaningFlags() { }
/// Check on data cleaning cuts
///
/// @param[in] key data cleaning bit to check
/// @return boolean true if key is present
bool ExistFlags( const Int_t key ) const { return keyedFlags.count( key ) == 1; }
/// Get data cleaning flags for key
///
/// @param[in] key to return
/// @return data cleaning flag corresponding to key (returns NULL if not present)
/// @throws out_of_range if key is not present
BitMask& GetFlags( const Int_t key ) { return keyedFlags.at( key ); }
/// @copydoc GetFlags(Int_t)
const BitMask& GetFlags( const Int_t key ) const { return keyedFlags.at( key ); }
/// Set the data cleaning flags for key
///
/// Will override existing flags!
///
/// @param[in] key to set
/// @param[in] flags to set, BitMask type
void SetFlags( const Int_t key, const BitMask& mask ) { keyedFlags[key] = mask; }
ClassDef( DataCleaningFlags, 1 )
protected:
std::map<Int_t, BitMask> keyedFlags; /// < The flags indexed by key ​
};
inline void
DataCleaningFlags::BitMask::SetFlag( size_t index, const Bool_t value )
{
const size_t element = index / 8 + 1;
if( index * 8 > flags.size() ) // UChar_t is gauranteed to be 8 bits by ROOT
flags.resize( element );
index -= element * 8; // Index is now the bit in UChar_t element
if( value )
flags[element] |= ( 0x1 << index );
else
flags[element] &= ~( 0x1 << index );
}
inline Bool_t
DataCleaningFlags::BitMask::GetFlag( size_t index ) const
{
const size_t element = index / 8 + 1;
if( index * 8 > flags.size() ) // UChar_t is gauranteed to be 8 bits by ROOT
return false;
index -= element * 8;// Index is now the bit in UChar_t element
return static_cast<Bool_t>( flags[element] & ( 0x1 << index ) );
}
} // namespace DS
} // namespace RAT
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment