| 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 | // $Id: G4SDManager.cc,v 1.4 2006/06/29 18:05:50 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: HEAD $
|
|---|
| 29 | //
|
|---|
| 30 |
|
|---|
| 31 | #include "G4SDManager.hh"
|
|---|
| 32 | #include "G4SDmessenger.hh"
|
|---|
| 33 | #include "G4HCofThisEvent.hh"
|
|---|
| 34 | #include "G4VHitsCollection.hh"
|
|---|
| 35 | #include "G4VSensitiveDetector.hh"
|
|---|
| 36 | #include "G4ios.hh"
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | G4SDManager* G4SDManager::fSDManager = 0;
|
|---|
| 40 |
|
|---|
| 41 | G4SDManager* G4SDManager::GetSDMpointer()
|
|---|
| 42 | {
|
|---|
| 43 | if(!fSDManager)
|
|---|
| 44 | {
|
|---|
| 45 | fSDManager = new G4SDManager;
|
|---|
| 46 | }
|
|---|
| 47 | return fSDManager;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | G4SDManager* G4SDManager::GetSDMpointerIfExist()
|
|---|
| 51 | { return fSDManager; }
|
|---|
| 52 |
|
|---|
| 53 | G4SDManager::G4SDManager():verboseLevel(0)
|
|---|
| 54 | {
|
|---|
| 55 | G4String topName = "/";
|
|---|
| 56 | treeTop = new G4SDStructure(topName);
|
|---|
| 57 | theMessenger = new G4SDmessenger(this);
|
|---|
| 58 | HCtable = new G4HCtable;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | G4SDManager::~G4SDManager()
|
|---|
| 62 | {
|
|---|
| 63 | delete theMessenger;
|
|---|
| 64 | delete HCtable;
|
|---|
| 65 | delete treeTop;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | void G4SDManager::AddNewDetector(G4VSensitiveDetector*aSD)
|
|---|
| 69 | {
|
|---|
| 70 | G4int numberOfCollections = aSD->GetNumberOfCollections();
|
|---|
| 71 | G4String pathName = aSD->GetPathName();
|
|---|
| 72 | if( pathName(0) != '/' ) pathName.prepend("/");
|
|---|
| 73 | if( pathName(pathName.length()-1) != '/' ) pathName += "/";
|
|---|
| 74 | treeTop->AddNewDetector(aSD,pathName);
|
|---|
| 75 | if(numberOfCollections<1) return;
|
|---|
| 76 | for(G4int i=0;i<numberOfCollections;i++)
|
|---|
| 77 | {
|
|---|
| 78 | G4String SDname = aSD->GetName();
|
|---|
| 79 | G4String DCname = aSD->GetCollectionName(i);
|
|---|
| 80 | AddNewCollection(SDname,DCname);
|
|---|
| 81 | }
|
|---|
| 82 | if( verboseLevel > 0 )
|
|---|
| 83 | {
|
|---|
| 84 | G4cout << "New sensitive detector <" << aSD->GetName()
|
|---|
| 85 | << "> is registored at " << pathName << G4endl;
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | void G4SDManager::AddNewCollection(G4String SDname,G4String DCname)
|
|---|
| 90 | {
|
|---|
| 91 | G4int i = HCtable->Registor(SDname,DCname);
|
|---|
| 92 | if(verboseLevel>0)
|
|---|
| 93 | {
|
|---|
| 94 | if(i<0) G4cerr << "G4SDManager::AddNewCollection : the collection <"
|
|---|
| 95 | << SDname << "/" << DCname << "> has already been reginstered." << G4endl;
|
|---|
| 96 | else G4cout << "G4SDManager::AddNewCollection : the collection <"
|
|---|
| 97 | << SDname << "/" << DCname << "> is registered at " << i << G4endl;
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | G4HCofThisEvent* G4SDManager::PrepareNewEvent()
|
|---|
| 102 | {
|
|---|
| 103 | G4HCofThisEvent* HCE = new G4HCofThisEvent(HCtable->entries());
|
|---|
| 104 | treeTop->Initialize(HCE);
|
|---|
| 105 | return HCE;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | void G4SDManager::TerminateCurrentEvent(G4HCofThisEvent* HCE)
|
|---|
| 109 | {
|
|---|
| 110 | treeTop->Terminate(HCE);
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | void G4SDManager::Activate(G4String dName, G4bool activeFlag)
|
|---|
| 114 | {
|
|---|
| 115 | G4String pathName = dName;
|
|---|
| 116 | if( pathName(0) != '/' ) pathName.prepend("/");
|
|---|
| 117 | treeTop->Activate(pathName,activeFlag);
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | G4VSensitiveDetector* G4SDManager::FindSensitiveDetector(G4String dName, G4bool warning)
|
|---|
| 121 | {
|
|---|
| 122 | G4String pathName = dName;
|
|---|
| 123 | if( pathName(0) != '/' ) pathName.prepend("/");
|
|---|
| 124 | return treeTop->FindSensitiveDetector(pathName, warning);
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | G4int G4SDManager::GetCollectionID(G4String colName)
|
|---|
| 128 | {
|
|---|
| 129 | G4int id = HCtable->GetCollectionID(colName);
|
|---|
| 130 | if(id==-1)
|
|---|
| 131 | { G4cout << "<" << colName << "> is not found." << G4endl; }
|
|---|
| 132 | else if(id==-2)
|
|---|
| 133 | { G4cout << "<" << colName << "> is ambiguous." << G4endl; }
|
|---|
| 134 | return id;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | G4int G4SDManager::GetCollectionID(G4VHitsCollection* aHC)
|
|---|
| 138 | {
|
|---|
| 139 | G4String HCname = aHC->GetSDname();
|
|---|
| 140 | HCname += "/";
|
|---|
| 141 | HCname += aHC->GetName();
|
|---|
| 142 | return GetCollectionID(HCname);
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|