Problem 1258

Summary: please fix G4THitsMap<T>::PrintAllHits
Product: Geant4 Reporter: andrea.di.simone
Component: digits_hits/hitsAssignee: asai
Status: RESOLVED FIXED    
Severity: trivial CC: andrea.di.simone
Priority: P5    
Version: 9.4   
Hardware: All   
OS: All   

Description andrea.di.simone 2011-10-25 12:52:31 CEST
Hi,

I am using in my application (SuperB) G4THitsMap<T>. Unfortunately, the present implementation of  G4THitsMap<T>::PrintAllHits restricts T to be something which can be added to a double:

template <typename T> void G4THitsMap<T>::PrintAllHits() 
 {
  G4cout << "G4THitsMap " << SDname << " / " << collectionName << " --- " << entries() << " entries" << G4endl;
  std::map<G4int,T*> * theHitsMap = GetMap();
  typename std::map<G4int, T*>::iterator itr = theHitsMap->begin();
  // THIS IS THE PROBLEM
  G4double sum = 0.;
  for(; itr != theHitsMap->end(); itr++) {
   ///////////////////////////////G4cout << "  " << itr->first << " : " << *(itr->second) << G4endl;
   sum += *(itr->second);
  }
  G4cout << "             Total : " << sum << G4endl;
 }

In my particular use case I want T to be a TVectorT<double>, since I need some binning in time. All of G4THitsMap works smoothly, but for this method.

Could this be modified to be more general? I do have a workaround in place (through template specialization) but it would be great if this worked out-of-the-box with any class for which operator+= is defined...

Thanks for your help,

Andrea.
Comment 1 asai 2011-10-31 17:10:28 CET
Thanks for reporting this.
I will temporary remove += operator for the coming release of 9.5, and investigate what we can do otherwise.
Comment 2 asai 2011-10-31 18:00:27 CET
I removed that part of the code for summing up and printing the sum.
This modification will be included in the v9.5 release, and it will be back
ported if we make patch release for v9.4.