| 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: G4DigiManager.cc,v 1.7 2006/06/29 21:13:04 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: HEAD $
|
|---|
| 29 | //
|
|---|
| 30 |
|
|---|
| 31 | #include "G4DigiManager.hh"
|
|---|
| 32 | #include "G4Event.hh"
|
|---|
| 33 | #include "G4VHitsCollection.hh"
|
|---|
| 34 | #include "G4VDigiCollection.hh"
|
|---|
| 35 | #include "G4DMmessenger.hh"
|
|---|
| 36 | #include "G4DCofThisEvent.hh"
|
|---|
| 37 | #include "G4RunManager.hh"
|
|---|
| 38 | #include "G4SDManager.hh"
|
|---|
| 39 | #include "G4ios.hh"
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | G4DigiManager* G4DigiManager::fDManager = 0;
|
|---|
| 43 |
|
|---|
| 44 | G4DigiManager* G4DigiManager::GetDMpointer()
|
|---|
| 45 | {
|
|---|
| 46 | if(!fDManager)
|
|---|
| 47 | {
|
|---|
| 48 | fDManager = new G4DigiManager;
|
|---|
| 49 | }
|
|---|
| 50 | return fDManager;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | G4DigiManager* G4DigiManager::GetDMpointerIfExist()
|
|---|
| 54 | { return fDManager; }
|
|---|
| 55 |
|
|---|
| 56 | G4DigiManager::G4DigiManager():verboseLevel(0)
|
|---|
| 57 | {
|
|---|
| 58 | theMessenger = new G4DMmessenger(this);
|
|---|
| 59 | runManager = G4RunManager::GetRunManager();
|
|---|
| 60 | SDManager = G4SDManager::GetSDMpointer();
|
|---|
| 61 | DCtable = new G4DCtable;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | G4DigiManager::~G4DigiManager()
|
|---|
| 65 | {
|
|---|
| 66 | //DMtable.clearAndDestroy();
|
|---|
| 67 | for(G4int i=0;i<int(DMtable.size());i++)
|
|---|
| 68 | { delete DMtable[i]; }
|
|---|
| 69 | DMtable.clear();
|
|---|
| 70 | delete DCtable;
|
|---|
| 71 | delete theMessenger;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | void G4DigiManager::AddNewModule(G4VDigitizerModule* DM)
|
|---|
| 75 | {
|
|---|
| 76 | G4String DMname = DM->GetName();
|
|---|
| 77 | for(int j=0;j<int(DMtable.size());j++)
|
|---|
| 78 | {
|
|---|
| 79 | if(DMtable[j]==DM)
|
|---|
| 80 | {
|
|---|
| 81 | G4cout << "<" << DMname << "> has already been registored." << G4endl;
|
|---|
| 82 | return;
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 | if( verboseLevel > 0 )
|
|---|
| 86 | {
|
|---|
| 87 | G4cout << "New DigitizerModule <" << DMname
|
|---|
| 88 | << "> is registored." << G4endl;
|
|---|
| 89 | }
|
|---|
| 90 | DMtable.push_back(DM);
|
|---|
| 91 |
|
|---|
| 92 | G4int numberOfCollections = DM->GetNumberOfCollections();
|
|---|
| 93 | for(int i=0;i<numberOfCollections;i++)
|
|---|
| 94 | {
|
|---|
| 95 | G4String DCname = DM->GetCollectionName(i);
|
|---|
| 96 | if( DCtable->Registor(DMname,DCname) < 0 )
|
|---|
| 97 | {
|
|---|
| 98 | G4cout << "DigiCollection <" << DCname
|
|---|
| 99 | << "> has already been registored with "
|
|---|
| 100 | << DMname << " DigitizerModule." << G4endl;
|
|---|
| 101 | }
|
|---|
| 102 | else if( verboseLevel > 0 )
|
|---|
| 103 | {
|
|---|
| 104 | G4cout << "DigiCollection " << DCname
|
|---|
| 105 | << " is registored. " << G4endl;
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | runManager->SetDCtable(DCtable);
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | void G4DigiManager::Digitize(G4String mName)
|
|---|
| 113 | {
|
|---|
| 114 | G4VDigitizerModule* aDM = FindDigitizerModule(mName);
|
|---|
| 115 | if(aDM)
|
|---|
| 116 | { aDM->Digitize(); }
|
|---|
| 117 | else
|
|---|
| 118 | { G4cout << "Unknown digitizer module <" << mName << ">. Digitize() ignored." << G4endl; }
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | G4VDigitizerModule* G4DigiManager::FindDigitizerModule(G4String mName)
|
|---|
| 122 | {
|
|---|
| 123 | for(G4int i=0;i<int(DMtable.size());i++)
|
|---|
| 124 | {
|
|---|
| 125 | if(DMtable[i]->GetName() == mName) return DMtable[i];
|
|---|
| 126 | }
|
|---|
| 127 | return NULL;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | const G4VHitsCollection* G4DigiManager::GetHitsCollection(G4int HCID,G4int eventID)
|
|---|
| 131 | {
|
|---|
| 132 | const G4Event* evt = NULL;
|
|---|
| 133 | if(eventID==0)
|
|---|
| 134 | { evt = runManager->GetCurrentEvent(); }
|
|---|
| 135 | else
|
|---|
| 136 | { evt = runManager->GetPreviousEvent(eventID); }
|
|---|
| 137 | if(evt==NULL) return NULL;
|
|---|
| 138 |
|
|---|
| 139 | G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
|
|---|
| 140 | if(HCE==NULL) return NULL;
|
|---|
| 141 |
|
|---|
| 142 | return HCE->GetHC(HCID);
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | const G4VDigiCollection* G4DigiManager::GetDigiCollection(G4int DCID,G4int eventID)
|
|---|
| 146 | {
|
|---|
| 147 | const G4Event* evt = NULL;
|
|---|
| 148 | if(eventID==0)
|
|---|
| 149 | { evt = runManager->GetCurrentEvent(); }
|
|---|
| 150 | else
|
|---|
| 151 | { evt = runManager->GetPreviousEvent(eventID); }
|
|---|
| 152 | if(evt==NULL) return NULL;
|
|---|
| 153 |
|
|---|
| 154 | G4DCofThisEvent* DCE = evt->GetDCofThisEvent();
|
|---|
| 155 | if(DCE==NULL) return NULL;
|
|---|
| 156 |
|
|---|
| 157 | return DCE->GetDC(DCID);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | G4int G4DigiManager::GetHitsCollectionID(G4String HCname)
|
|---|
| 161 | {
|
|---|
| 162 | return SDManager->GetCollectionID(HCname);
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | G4int G4DigiManager::GetDigiCollectionID(G4String DCname)
|
|---|
| 166 | {
|
|---|
| 167 | G4int i = DCtable->GetCollectionID(DCname);
|
|---|
| 168 | if(i==-2)
|
|---|
| 169 | { G4cout << "< " << DCname << "> is ambegious." << G4endl; }
|
|---|
| 170 | return i;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | void G4DigiManager::SetDigiCollection(G4int DCID,G4VDigiCollection* aDC)
|
|---|
| 174 | {
|
|---|
| 175 | const G4Event* consEvt = runManager->GetCurrentEvent();
|
|---|
| 176 | if(consEvt==NULL)
|
|---|
| 177 | {
|
|---|
| 178 | G4cout << "G4DigiManager::SetDigiCollection --- "
|
|---|
| 179 | << "Event object is not available." << G4endl;
|
|---|
| 180 | return;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | G4Event* evt = (G4Event*)consEvt;
|
|---|
| 184 | G4DCofThisEvent* DCE = evt->GetDCofThisEvent();
|
|---|
| 185 | if(DCE==NULL)
|
|---|
| 186 | {
|
|---|
| 187 | DCE = new G4DCofThisEvent(DCtable->entries());
|
|---|
| 188 | evt->SetDCofThisEvent(DCE);
|
|---|
| 189 | if(verboseLevel>0)
|
|---|
| 190 | { G4cout << "DCofThisEvent object is added to current G4Event." << G4endl; }
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | DCE->AddDigiCollection(DCID,aDC);
|
|---|
| 194 |
|
|---|
| 195 | if(verboseLevel>0)
|
|---|
| 196 | {
|
|---|
| 197 | G4cout << aDC->GetName() << " is stored at " << DCID
|
|---|
| 198 | << "-th slot of G4DCofThisEvent." << G4endl;
|
|---|
| 199 | }
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | void G4DigiManager::SetVerboseLevel(G4int val)
|
|---|
| 203 | {
|
|---|
| 204 | verboseLevel = val;
|
|---|
| 205 | for(G4int i=0;i<int(DMtable.size());i++)
|
|---|
| 206 | { DMtable[i]->SetVerboseLevel(val); }
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | void G4DigiManager::List() const
|
|---|
| 210 | {
|
|---|
| 211 | for(G4int i=0;i<int(DMtable.size());i++)
|
|---|
| 212 | { G4cout << " " << i << " : " << DMtable[i]->GetName() << G4endl; }
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|