//
// ********************************************************************
// * 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.          *
// ********************************************************************
//
/// \file B02PVolumeStore.cc
/// \brief Implementation of the B02PVolumeStore class

// ----------------------------------------------------------------------
// GEANT 4 class source file
//
// B02PVolumeStore.cc
//
// ----------------------------------------------------------------------

#include "B02PVolumeStore.hh"

#include "G4VPhysicalVolume.hh"

#include <sstream>

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

B02PVolumeStore::B02PVolumeStore() {}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

B02PVolumeStore::~B02PVolumeStore() {}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void B02PVolumeStore::AddPVolume(const G4GeometryCell& cell)
{
  B02SetGeometryCell::iterator it = fSetGeometryCell.find(cell);
  if (it != fSetGeometryCell.end()) {
    G4cout << "B02PVolumeStore::AddPVolume: cell already stored" << G4endl;
    return;
  }

  fSetGeometryCell.insert(cell);
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

const G4VPhysicalVolume* B02PVolumeStore::GetPVolume(const G4String& name) const
{
  const G4VPhysicalVolume* pvol = 0;
  for (B02SetGeometryCell::const_iterator it = fSetGeometryCell.begin();
       it != fSetGeometryCell.end(); ++it)
  {
    const G4VPhysicalVolume& vol = it->GetPhysicalVolume();
    if (vol.GetName() == name) {
      pvol = &vol;
    }
  }
  if (!pvol) {
    G4cout << "B02PVolumeStore::GetPVolume: no physical volume named: " << name << ", found"
           << G4endl;
  }
  return pvol;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

G4String B02PVolumeStore::GetPNames() const
{
  G4String NameString;
  for (B02SetGeometryCell::const_iterator it = fSetGeometryCell.begin();
       it != fSetGeometryCell.end(); ++it)
  {
    const G4VPhysicalVolume& vol = it->GetPhysicalVolume();
    std::ostringstream os;
    os << vol.GetName() << "_" << it->GetReplicaNumber() << "\n";
    G4String cellname = os.str();

    //    G4String cellname(vol.GetName());
    //    cellname += G4String("_");
    //    cellname += std::str(it->GetReplicaNumber());

    NameString += cellname;
  }
  return NameString;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

G4int B02PVolumeStore::Size()
{
  return fSetGeometryCell.size();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
