[807] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 27 | // File: CCalSensitiveDetectors.cc |
---|
| 28 | // Description: Provides a map of logicalvolume pointers which can be sensitive |
---|
| 29 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 30 | |
---|
| 31 | #include "CCalSensitiveDetectors.hh" |
---|
| 32 | |
---|
| 33 | //#define debug |
---|
| 34 | |
---|
| 35 | CCalSensitiveDetectors* CCalSensitiveDetectors::theInstance = 0; |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | CCalSensitiveDetectors* CCalSensitiveDetectors::getInstance() { |
---|
| 39 | if (!theInstance) theInstance = new CCalSensitiveDetectors; |
---|
| 40 | return theInstance; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | void CCalSensitiveDetectors::registerVolume (const G4String& string, |
---|
| 45 | G4LogicalVolume* logv) { |
---|
| 46 | |
---|
| 47 | theLVs.insert(mmslv::value_type(string, logv)); |
---|
| 48 | #ifdef debug |
---|
| 49 | G4cout << "CCalSensitiveDetectors : Register " << logv->GetName() |
---|
| 50 | << " in category " << string << G4endl; |
---|
| 51 | #endif |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | std::vector<G4LogicalVolume*> CCalSensitiveDetectors::getVolumes (const G4String& string, |
---|
| 55 | bool exist) { |
---|
| 56 | |
---|
| 57 | mmslv::const_iterator mmscite; |
---|
| 58 | std::pair<mmslv::iterator, mmslv::iterator> mmsdi; |
---|
| 59 | mmsdi = theLVs.equal_range(string); |
---|
| 60 | std::vector<G4LogicalVolume*> lvs; |
---|
| 61 | for (mmscite = mmsdi.first; mmscite != mmsdi.second; mmscite++ ) { |
---|
| 62 | lvs.push_back(const_cast<G4LogicalVolume*>((*mmscite).second)); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | if (exist) G4cout << "CCalSensitiveDetector : " << lvs.size() |
---|
| 66 | << " detectors for " << string << G4endl; |
---|
| 67 | |
---|
| 68 | return lvs; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | bool CCalSensitiveDetectors::setSensitive(const G4String& string, |
---|
| 73 | G4VSensitiveDetector* sens) { |
---|
| 74 | |
---|
| 75 | bool result=false; |
---|
| 76 | mmslv::const_iterator mmscite; |
---|
| 77 | std::pair<mmslv::iterator, mmslv::iterator> mmsdi; |
---|
| 78 | mmsdi = theLVs.equal_range(string); |
---|
| 79 | for (mmscite = mmsdi.first; mmscite != mmsdi.second; mmscite++ ) { |
---|
| 80 | G4LogicalVolume* lv = const_cast<G4LogicalVolume*>((*mmscite).second); |
---|
| 81 | lv ->SetSensitiveDetector(sens); |
---|
| 82 | result = true; |
---|
| 83 | #ifdef debug |
---|
| 84 | G4cout << " Associate SD " << sens->GetName() << " to " << lv->GetName() |
---|
| 85 | << G4endl; |
---|
| 86 | #endif |
---|
| 87 | } |
---|
| 88 | return result; |
---|
| 89 | |
---|
| 90 | } |
---|