Problem 1258 - please fix G4THitsMap<T>::PrintAllHits
Summary: please fix G4THitsMap<T>::PrintAllHits
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: digits_hits/hits (show other problems)
Version: 9.4
Hardware: All All
: P5 trivial
Assignee: asai
URL:
Depends on:
Blocks:
 
Reported: 2011-10-25 12:52 CEST by andrea.di.simone
Modified: 2011-10-31 18:00 CET (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
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.