Files
geant4/source/digits_hits/hits/src/G4HCofThisEvent.cc
T
2016-06-30 14:12:05 +02:00

90 lines
3.6 KiB
C++

//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * 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. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4HCofThisEvent.cc 94772 2015-12-09 09:46:45Z gcosmo $
//
#include "G4HCofThisEvent.hh"
G4ThreadLocal G4Allocator<G4HCofThisEvent> *anHCoTHAllocator_G4MT_TLS_ = 0;
G4HCofThisEvent::G4HCofThisEvent()
{ if (!anHCoTHAllocator_G4MT_TLS_) anHCoTHAllocator_G4MT_TLS_ = new G4Allocator<G4HCofThisEvent> ;
HC = new std::vector<G4VHitsCollection*>;
}
G4HCofThisEvent::G4HCofThisEvent(G4int cap)
{ if (!anHCoTHAllocator_G4MT_TLS_) anHCoTHAllocator_G4MT_TLS_ = new G4Allocator<G4HCofThisEvent> ;
HC = new std::vector<G4VHitsCollection*>;
for(G4int i=0;i<cap;i++)
{
HC->push_back((G4VHitsCollection*)0);
}
}
G4HCofThisEvent::~G4HCofThisEvent()
{ if (!anHCoTHAllocator_G4MT_TLS_) anHCoTHAllocator_G4MT_TLS_ = new G4Allocator<G4HCofThisEvent> ;
//HC->clearAndDestroy();
for(size_t i=0;i<HC->size();i++)
{ delete (*HC)[i]; }
HC->clear();
delete HC;
}
void G4HCofThisEvent::AddHitsCollection(G4int HCID,G4VHitsCollection * aHC)
{ if (!anHCoTHAllocator_G4MT_TLS_) anHCoTHAllocator_G4MT_TLS_ = new G4Allocator<G4HCofThisEvent> ;
if(HCID>=0 && HCID<G4int(HC->size()))
{
aHC->SetColID(HCID);
(*HC)[HCID] = aHC;
}
}
G4HCofThisEvent::G4HCofThisEvent(const G4HCofThisEvent& rhs)
{
if ( !anHCoTHAllocator_G4MT_TLS_ ) anHCoTHAllocator_G4MT_TLS_ = new G4Allocator<G4HCofThisEvent>;
HC = new std::vector<G4VHitsCollection*>(rhs.HC->size());
for ( unsigned int i = 0 ; i<rhs.HC->size() ; ++i)
*(HC->at(i)) = *(rhs.HC->at(i));
}
G4HCofThisEvent& G4HCofThisEvent::operator=(const G4HCofThisEvent& rhs)
{
if ( this == &rhs ) return *this;
if ( !anHCoTHAllocator_G4MT_TLS_ ) anHCoTHAllocator_G4MT_TLS_ = new G4Allocator<G4HCofThisEvent>;
for ( std::vector<G4VHitsCollection*>::const_iterator it = HC->begin() ;
it != HC->end() ; ++it )
{
delete *it;
}
HC->resize(rhs.HC->size());
for ( unsigned int i = 0 ; i<rhs.HC->size() ; ++i)
*(HC->at(i)) = *(rhs.HC->at(i));
return *this;
}