<commit_before>#ifndef CellIDEncoder_h
#define CellIDEncoder_h 1

#include "EVENT/LCCollection.h"
#include "UTIL/BitField64.h"
#include "lcio.h"
#include <string>

using namespace lcio ;

namespace EVENT{
  class SimCalorimeterHit ;
  class RawCalorimeterHit ;
  class TrackerData ;
  class TrackerPulse ;
  class TrackerRawData ;
}
namespace IMPL{
  class SimTrackerHitImpl ;
}

namespace UTIL{


  /** Convenient class for encoding cellIDs for various hit objects.
   *  It sets the proper collection parameter LCIO::CellIDEncoding and
   *  sets the proper flag bit for storing a second cellid if necessary.
   *  See UTIL::BitField64 for a description of the encoding string. 
   *  Example:<br>
   *  &nbsp;   CellIDEncoder<SimCalorimeterHitImpl> cd( "i:20,j:20,k:20" ,calVec )  ;<br>
   *  &nbsp;   for(int j=0;j<NHITS;j++){<br>
   *  &nbsp;&nbsp;  SimCalorimeterHitImpl* hit = new SimCalorimeterHitImpl ;<br>
   *  &nbsp;&nbsp;    cd["i"] = j ;<br>
   *  &nbsp;&nbsp;    cd["j"] = j + 100 ;<br>
   *  &nbsp;&nbsp;    cd["k"] = j + 200 ;<br>
   *  &nbsp;&nbsp;    cd.setCellID( hit ) ;<br>
   *  &nbsp;   } <br>
   * 
   *  @see BitField64
   *  @version $Id: CellIDEncoder.h,v 1.1 2006-03-22 17:38:22 gaede Exp $
   */
  template <class T> 
  class CellIDEncoder : public BitField64 {

  public:  
    
    /** Constructor reads encoding string from collection parameter LCIO::CellIDEncoding.
     */
    CellIDEncoder( const std::string& cellIDEncoding ,  LCCollection* col) :

      BitField64( cellIDEncoding  ),

      _col( col ) {
      
	_col->parameters().setValue( LCIO::CellIDEncoding , cellIDEncoding ) ;

	setCellIDFlag() ;
    }

    void setCellID( T* hit) {
      
      hit->setCellID0( lowWord()  ) ;
      
      hit->setCellID1( highWord() ) ;

    }

    /** Helper method that sets/unsets the proper bit for storing a second cellid word 
     */
    void setCellIDFlag() {
      
      int bit = cellID1Bit() ;
      
      if(  bit >= 0 ) {
	
	LCFlagImpl f( _col->getFlag() ) ;
	
	if( highestBit() > 31 ) {
	  
	  // 	  std::cout << " setting bit " <<  bit << std::endl ;
	  f.setBit( bit ) ;
	  
	} else {
	  // 	  std::cout << " unsetting bit " <<  bit << std::endl ;
	  f.unsetBit( bit ) ;
	}
	
	_col->setFlag( f.getFlag()  ) ;
      }
    }
    
  protected:
    
    int cellID1Bit() { return -1 ; }

 
    LCCollection* _col ;
    T* _oldHit ;
  } ; 
  
  /** Specialization for SimTrackerHits that have only one cellID */
  template<> void CellIDEncoder<IMPL::SimTrackerHitImpl>::setCellID( IMPL::SimTrackerHitImpl* hit) {
    hit->setCellID( lowWord()  ) ;
  }

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder<EVENT::SimCalorimeterHit>::cellID1Bit() {  return LCIO::CHBIT_ID1 ; }

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder<EVENT::RawCalorimeterHit>::cellID1Bit() {  return LCIO::RCHBIT_ID1 ; }

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder<EVENT::TrackerData>::cellID1Bit() {  return LCIO::TRAWBIT_ID1 ; }

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder<EVENT::TrackerPulse>::cellID1Bit() {  return LCIO::TRAWBIT_ID1 ; }

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder<EVENT::TrackerRawData>::cellID1Bit() {  return LCIO::TRAWBIT_ID1 ; }



} // namespace
#endif


<commit_msg>fixed problem with cellid1 bit template specializations<commit_after>#ifndef CellIDEncoder_h
#define CellIDEncoder_h 1

#include "EVENT/LCCollection.h"
#include "UTIL/BitField64.h"
#include "IMPL/SimTrackerHitImpl.h"
#include "IMPL/LCFlagImpl.h"
#include "lcio.h"
#include <string>

using namespace lcio ;

//forward declarations for template specializations 
namespace EVENT{
  class SimCalorimeterHit ;
  class RawCalorimeterHit ;
  class CalorimeterHit ;
  class TrackerData ;
  class TrackerPulse ;
  class TrackerRawData ;
}

namespace UTIL{


  /** Helper function that returns the bit for cellid1 through template specialization
   *  or -1 if no cellid1 exists. 
   */
  template <class T>
  int CellIDEncoder_cellID1Bit()  { return -1 ; } ;

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder_cellID1Bit<EVENT::SimCalorimeterHit>() {  return LCIO::CHBIT_ID1 ; }

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder_cellID1Bit<EVENT::RawCalorimeterHit>() {  return LCIO::RCHBIT_ID1 ; }

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder_cellID1Bit<EVENT::CalorimeterHit>() {  return LCIO::RCHBIT_ID1 ; }

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder_cellID1Bit<EVENT::TrackerData>() {  return LCIO::TRAWBIT_ID1 ; }

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder_cellID1Bit<EVENT::TrackerPulse>() {  return LCIO::TRAWBIT_ID1 ; }

  /** specialization that returns the proper bit for the second cellid */
  template<> int CellIDEncoder_cellID1Bit<EVENT::TrackerRawData>() {  return LCIO::TRAWBIT_ID1 ; }


  /** Convenient class for encoding cellIDs for various hit objects.
   *  It sets the proper collection parameter LCIO::CellIDEncoding and
   *  sets the proper flag bit for storing a second cellid if necessary.
   *  See UTIL::BitField64 for a description of the encoding string. 
   *  Example:<br>
   *  &nbsp;   CellIDEncoder<SimCalorimeterHitImpl> cd( "i:20,j:20,k:20" ,calVec )  ;<br>
   *  &nbsp;   for(int j=0;j<NHITS;j++){<br>
   *  &nbsp;&nbsp;  SimCalorimeterHitImpl* hit = new SimCalorimeterHitImpl ;<br>
   *  &nbsp;&nbsp;    cd["i"] = j ;<br>
   *  &nbsp;&nbsp;    cd["j"] = j + 100 ;<br>
   *  &nbsp;&nbsp;    cd["k"] = j + 200 ;<br>
   *  &nbsp;&nbsp;    cd.setCellID( hit ) ;<br>
   *  &nbsp;   } <br>
   * 
   *  @see BitField64
   *  @version $Id: CellIDEncoder.h,v 1.2 2007-02-01 10:43:23 gaede Exp $
   */
  template <class T> 
  class CellIDEncoder : public BitField64 {

  public:  
    
    /** Constructor reads encoding string from collection parameter LCIO::CellIDEncoding.
     */
    CellIDEncoder( const std::string& cellIDEncoding ,  LCCollection* col) :

      BitField64( cellIDEncoding  ),

      _col( col ) {
      
	_col->parameters().setValue( LCIO::CellIDEncoding , cellIDEncoding ) ;

	setCellIDFlag() ;
    }

    void setCellID( T* hit) {
      
      hit->setCellID0( lowWord()  ) ;
      
      hit->setCellID1( highWord() ) ;

    }

    /** Helper method that sets/unsets the proper bit for storing a second cellid word 
     */
    void setCellIDFlag() {
      
      int bit = CellIDEncoder_cellID1Bit<typename T::lcobject_type>() ;
      
      if(  bit >= 0 ) {
	
	LCFlagImpl f( _col->getFlag() ) ;
	
	if( highestBit() > 31 ) {
	  
	  // 	  std::cout << " setting bit " <<  bit << std::endl ;
	  f.setBit( bit ) ;
	  
	} else {
	  // 	  std::cout << " unsetting bit " <<  bit << std::endl ;
	  f.unsetBit( bit ) ;
	}
	
	_col->setFlag( f.getFlag()  ) ;
      }
    }
    
  protected:
    
    //    int cellID1Bit() { return -1 ; }

 
    LCCollection* _col ;
    T* _oldHit ;
  } ; 
  


  /** Specialization for SimTrackerHits that have only one cellID */
  template<> void CellIDEncoder<IMPL::SimTrackerHitImpl>::setCellID( IMPL::SimTrackerHitImpl* hit) {
    hit->setCellID( lowWord()  ) ;
  }



} // namespace
#endif



{'fraction_non_alphanumeric': 0.12547829528961604, 'fraction_numerical': 0.016360997493072963, 'mean_word_length': 3.1648351648351647, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5308140', 'n_tokens_mistral': 2714, 'n_tokens_neox': 2540, 'n_words': 655}