// // ******************************************************************** // * DISCLAIMER * // * * // * The following disclaimer summarizes all the specific disclaimers * // * of contributors to this software. The specific disclaimers,which * // * govern, are listed with their locations in: * // * http://cern.ch/geant4/license * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. * // * * // * This code implementation is the intellectual property of the * // * GEANT4 collaboration. * // * By copying, distributing or modifying the Program (or any work * // * based on the Program) you indicate your acceptance of this * // * statement, and all its terms. * // ******************************************************************** // // $Id: ParExMarshaledHits.hh,v 1.1 2002/03/05 15:21:58 gcosmo Exp $ // GEANT4 tag $Name: geant4-05-02-patch-01 $ // // -------------------------------------------------------------------- // Parallel Library for Geant4 // // Gene Cooperman , 2001 // -------------------------------------------------------------------- #ifndef ParExMarshaledHits_h #define ParExMarshaledHits_h 1 #include "G4THitsCollection.hh" #include "ParMarshaledObj.hh" #include "G4SDManager.hh" #include "G4RunManager.hh" // Calling sequence: // MarshaledHCofThisEvent::MarshaledHCofThisEvent() // -> MarshaledHCofThisEvent::MarshalHitsCollection // (G4VHitsCollection * aBaseHC, G4String HCname) // -> TMarshaledHitsCollection::Marshal(G4VHitsCollection * aBaseHC) // -> TMarshaledHitsCollection::MarshalHit(T *aHit) // MarshaledHCofThisEvent::UnmarshalSlaveHCofThisEvent() // -> TMarshaledHitsCollection::UnmarshalSlaveHitsCollection // (G4String HCname, G4String SDname) // -> TMarshaledHitsCollection::Unmarshal(G4THitsCollection * aHC) // -> TMarshaledHitsCollection::UnmarshalHit(T * aHit) // class T derived from G4VHit template class TMarshaledHitsCollection : public MarshaledObj { public: inline void Marshal(G4VHitsCollection * aBaseHC); // Marshal hits of aBaseHC inline void UnmarshalSlaveHitsCollection(G4String & HCname, G4String & SDname); inline void Unmarshal(G4THitsCollection * aHC); // By default, we a hit of type T as a void pointer inline void MarshalHit( T *aHit ) { MarshaledObj::Marshal((void *)aHit, sizeof(*aHit)); } // Unmarshal hits into HC for T. By default assume it was marshaled // as a void pointer (ObjPtr) inline void UnmarshalHit(T * aHit) { if (isNewHitsCollection) *aHit = *(T *)MarshaledObj::UnmarshalAsSharedObjPtr(); else G4Exception( "Event Level Parallelism: Every hit collection sent to master" " should be new.\n Current hit collection, " + collectionName + ", is not new.\n" ); } protected: static G4bool isNewHitsCollection; static G4String collectionName; }; template G4bool TMarshaledHitsCollection::isNewHitsCollection = true; template G4String TMarshaledHitsCollection::collectionName = ""; template inline void TMarshaledHitsCollection::Marshal(G4VHitsCollection * aBaseHC) { G4THitsCollection *aHC = (G4THitsCollection *)aBaseHC; G4int numHits = aHC->entries(); MarshaledObj::Marshal( numHits ); #ifdef TOPC_DEBUG G4cout << "Marshaled numHits: " << numHits << G4endl; #endif for (int j = 0; j < numHits; j++) { T *aHit = (*aHC)[j]; MarshalHit( aHit ); } } template inline void TMarshaledHitsCollection::Unmarshal (G4THitsCollection * aHC) { G4int numHits; MarshaledObj::Unmarshal( numHits ); #ifdef TOPC_DEBUG G4cout << "numHits: " << numHits << G4endl; #endif for (int j = 0; j < numHits; j++) { T *aHit = new T; UnmarshalHit( aHit ); aHC->insert( aHit ); } } template inline void TMarshaledHitsCollection::UnmarshalSlaveHitsCollection (G4String & HCname, G4String & SDname) { G4HCofThisEvent *HCE = G4RunManager::GetRunManager()-> GetCurrentEvent()-> GetHCofThisEvent(); // Find or create HitsCollection, aHC, with name HCname G4THitsCollection *aHC; // HCname is unique. collectionName = HCname; G4int HCID = G4SDManager::GetSDMpointer()->GetCollectionID(HCname); if (HCID < 0) { aHC = new G4THitsCollection(SDname, HCname); HCID = G4SDManager::GetSDMpointer()->GetCollectionID(HCname); HCE->AddHitsCollection( HCID, aHC ); isNewHitsCollection = true; } else { aHC = (G4THitsCollection *)HCE->GetHC(HCID); isNewHitsCollection = ( aHC->entries() == 0 ? true : false ); } Unmarshal(aHC); }; #endif