G4ITBox.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id: G4ITBox.cc 64057 2012-10-30 15:04:49Z gcosmo $
00027 //
00028 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 
00029 //
00030 // History:
00031 // -----------
00032 // 10 Oct 2011 M.Karamitros created
00033 //
00034 // -------------------------------------------------------------------
00035 
00036 #include "G4ITBox.hh"
00037 
00038 G4ITBox::G4ITBox() : fNbIT(0), fpFirstIT(0), fpLastIT(0), fpPreviousBox(0), fpNextBox(0)
00039 {;}
00040 
00041 G4ITBox::~G4ITBox()
00042 {
00043     if( fNbIT != 0 )
00044     {
00045         G4IT * aIT = fpFirstIT;
00046         G4IT * nextIT;
00047 
00048         while( aIT != 0 )
00049         {
00050             nextIT = aIT->GetNext();
00051             delete aIT;
00052             aIT = nextIT;
00053         }
00054     }
00055 
00056     if(fpPreviousBox)    fpPreviousBox->SetNextBox(fpNextBox) ;
00057     if(fpNextBox)        fpNextBox->SetPreviousBox(fpPreviousBox);
00058 }
00059 
00060 const G4ITBox & G4ITBox::operator=(const G4ITBox &right)
00061 {
00062     fNbIT = right.fNbIT;
00063     fpFirstIT = right.fpFirstIT;
00064     fpLastIT = right.fpLastIT;
00065     fpPreviousBox = 0;
00066     fpNextBox = 0;
00067     return *this;
00068 }
00069 
00070 void G4ITBox::Push( G4IT * aIT )
00071 {
00072     if( fNbIT == 0 )
00073     {
00074         aIT->SetPrevious( 0 );
00075         fpFirstIT = aIT;
00076     }
00077     else
00078     {
00079         fpLastIT->SetNext( aIT );
00080         aIT->SetPrevious( fpLastIT );
00081     }
00082     fpLastIT = aIT;
00083     fNbIT++;
00084     aIT->SetITBox(this);
00085 }
00086 
00087 void G4ITBox::Extract( G4IT * aStackedIT )
00088 {
00089     if( aStackedIT == fpFirstIT )
00090     {
00091         fpFirstIT = aStackedIT->GetNext();
00092     }
00093     else  if( aStackedIT == fpLastIT )
00094     {
00095         fpLastIT = aStackedIT->GetPrevious();
00096 
00097     }
00098 
00099     if( aStackedIT->GetNext())
00100         aStackedIT->GetNext()->SetPrevious(aStackedIT->GetPrevious());
00101     if( aStackedIT->GetPrevious())
00102         aStackedIT->GetPrevious()->SetNext(aStackedIT->GetNext());
00103 
00104     aStackedIT->SetNext(0);
00105     aStackedIT->SetPrevious(0);
00106     aStackedIT->SetITBox(0);
00107     fNbIT--;
00108 }
00109 
00110 G4IT* G4ITBox::FindIT(const G4Track& track)
00111 {
00112     if( fNbIT == 0 ) return 0;
00113 
00114     G4IT * temp = fpLastIT;
00115     G4bool find = false;
00116 
00117     while(find == false && temp != 0)
00118     {
00119         if(temp-> GetTrack() == &track)
00120         {
00121             find = true;
00122             break;
00123         }
00124         temp = temp->GetPrevious();
00125     }
00126 
00127     return temp;
00128 }
00129 
00130 const G4IT* G4ITBox::FindIT(const G4Track& track) const
00131 {
00132     if( fNbIT == 0 ) return 0;
00133 
00134     const G4IT * temp = fpLastIT;
00135     G4bool find = false;
00136 
00137     while(find == false && temp != 0)
00138     {
00139         if(temp-> GetTrack() == &track)
00140         {
00141             find = true;
00142             break;
00143         }
00144         temp = temp->GetPrevious();
00145     }
00146 
00147     return temp;
00148 }
00149 
00150 void G4ITBox::TransferTo(G4ITBox * aStack)
00151 {
00152     G4IT * ITToTransfer = fpFirstIT;
00153     while(fNbIT)
00154     {
00155         Extract(ITToTransfer);
00156         aStack->Push(ITToTransfer);
00157         ITToTransfer = ITToTransfer->GetNext();
00158     }
00159 }

Generated on Mon May 27 17:48:41 2013 for Geant4 by  doxygen 1.4.7