Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4DigiManager.cc 80987 2014-05-19 10:50:22Z gcosmo $ 27 // 28 // 28 29 29 #include "G4DigiManager.hh" 30 #include "G4DigiManager.hh" 30 #include "G4Event.hh" 31 #include "G4Event.hh" 31 #include "G4VHitsCollection.hh" 32 #include "G4VHitsCollection.hh" 32 #include "G4VDigiCollection.hh" 33 #include "G4VDigiCollection.hh" 33 #include "G4DMmessenger.hh" 34 #include "G4DMmessenger.hh" 34 #include "G4DCofThisEvent.hh" 35 #include "G4DCofThisEvent.hh" 35 #include "G4RunManager.hh" 36 #include "G4RunManager.hh" 36 #include "G4SDManager.hh" 37 #include "G4SDManager.hh" 37 #include "G4ios.hh" 38 #include "G4ios.hh" 38 39 39 40 40 G4ThreadLocal G4DigiManager* G4DigiManager::fD 41 G4ThreadLocal G4DigiManager* G4DigiManager::fDManager = 0; 41 42 42 G4DigiManager* G4DigiManager::GetDMpointer() 43 G4DigiManager* G4DigiManager::GetDMpointer() 43 { 44 { 44 if(!fDManager) 45 if(!fDManager) 45 { 46 { 46 fDManager = new G4DigiManager; 47 fDManager = new G4DigiManager; 47 } 48 } 48 return fDManager; 49 return fDManager; 49 } 50 } 50 51 51 G4DigiManager* G4DigiManager::GetDMpointerIfEx 52 G4DigiManager* G4DigiManager::GetDMpointerIfExist() 52 { return fDManager; } 53 { return fDManager; } 53 54 54 G4DigiManager::G4DigiManager():verboseLevel(0) 55 G4DigiManager::G4DigiManager():verboseLevel(0) 55 { 56 { 56 theMessenger = new G4DMmessenger(this); 57 theMessenger = new G4DMmessenger(this); 57 runManager = G4RunManager::GetRunManager(); 58 runManager = G4RunManager::GetRunManager(); 58 SDManager = G4SDManager::GetSDMpointer(); 59 SDManager = G4SDManager::GetSDMpointer(); 59 DCtable = new G4DCtable; 60 DCtable = new G4DCtable; 60 } 61 } 61 62 62 G4DigiManager::~G4DigiManager() 63 G4DigiManager::~G4DigiManager() 63 { 64 { 64 //DMtable.clearAndDestroy(); 65 //DMtable.clearAndDestroy(); 65 for(G4int i=0;i<G4int(DMtable.size());++i) << 66 for(G4int i=0;i<int(DMtable.size());i++) 66 { delete DMtable[i]; } 67 { delete DMtable[i]; } 67 DMtable.clear(); 68 DMtable.clear(); 68 delete DCtable; 69 delete DCtable; 69 delete theMessenger; 70 delete theMessenger; 70 } 71 } 71 72 72 void G4DigiManager::AddNewModule(G4VDigitizerM 73 void G4DigiManager::AddNewModule(G4VDigitizerModule* DM) 73 { 74 { 74 G4String DMname = DM->GetName(); 75 G4String DMname = DM->GetName(); 75 for(G4int j=0;j<G4int(DMtable.size());++j) << 76 for(int j=0;j<int(DMtable.size());j++) 76 { 77 { 77 if(DMtable[j]==DM) 78 if(DMtable[j]==DM) 78 { 79 { 79 G4cout << "<" << DMname << "> has alread << 80 G4cout << "<" << DMname << "> has already been registored." << G4endl; 80 return; 81 return; 81 } 82 } 82 } 83 } 83 if( verboseLevel > 0 ) 84 if( verboseLevel > 0 ) 84 { 85 { 85 G4cout << "New DigitizerModule <" << DMnam 86 G4cout << "New DigitizerModule <" << DMname 86 << "> is registered." << G4endl; << 87 << "> is registored." << G4endl; 87 } 88 } 88 DMtable.push_back(DM); 89 DMtable.push_back(DM); 89 90 90 G4int numberOfCollections = DM->GetNumberOfC 91 G4int numberOfCollections = DM->GetNumberOfCollections(); 91 for(G4int i=0;i<numberOfCollections;++i) << 92 for(int i=0;i<numberOfCollections;i++) 92 { 93 { 93 G4String DCname = DM->GetCollectionName(i) 94 G4String DCname = DM->GetCollectionName(i); 94 if( DCtable->Registor(DMname,DCname) < 0 ) 95 if( DCtable->Registor(DMname,DCname) < 0 ) 95 { 96 { 96 G4cout << "DigiCollection <" << DCname 97 G4cout << "DigiCollection <" << DCname 97 << "> has already been registered w << 98 << "> has already been registored with " 98 << DMname << " DigitizerModule." << 99 << DMname << " DigitizerModule." << G4endl; 99 } 100 } 100 else if( verboseLevel > 0 ) 101 else if( verboseLevel > 0 ) 101 { 102 { 102 G4cout << "DigiCollection " << DCname 103 G4cout << "DigiCollection " << DCname 103 << " is registered. " << G4endl; << 104 << " is registored. " << G4endl; 104 } 105 } 105 } 106 } 106 107 107 runManager->SetDCtable(DCtable); 108 runManager->SetDCtable(DCtable); 108 } 109 } 109 110 110 void G4DigiManager::Digitize(const G4String& m << 111 void G4DigiManager::Digitize(G4String mName) 111 { 112 { 112 G4VDigitizerModule* aDM = FindDigitizerModul 113 G4VDigitizerModule* aDM = FindDigitizerModule(mName); 113 if(aDM) 114 if(aDM) 114 { aDM->Digitize(); } 115 { aDM->Digitize(); } 115 else 116 else 116 { G4cout << "Unknown digitizer module <" << 117 { G4cout << "Unknown digitizer module <" << mName << ">. Digitize() ignored." << G4endl; } 117 } 118 } 118 119 119 G4VDigitizerModule* G4DigiManager::FindDigitiz << 120 G4VDigitizerModule* G4DigiManager::FindDigitizerModule(G4String mName) 120 { 121 { 121 for(G4int i=0;i<G4int(DMtable.size());++i) << 122 for(G4int i=0;i<int(DMtable.size());i++) 122 { 123 { 123 if(DMtable[i]->GetName() == mName) return 124 if(DMtable[i]->GetName() == mName) return DMtable[i]; 124 } 125 } 125 return NULL; 126 return NULL; 126 } 127 } 127 128 128 const G4VHitsCollection* G4DigiManager::GetHit 129 const G4VHitsCollection* G4DigiManager::GetHitsCollection(G4int HCID,G4int eventID) 129 { 130 { 130 const G4Event* evt = NULL; 131 const G4Event* evt = NULL; 131 if(eventID==0) 132 if(eventID==0) 132 { evt = runManager->GetCurrentEvent(); } 133 { evt = runManager->GetCurrentEvent(); } 133 else 134 else 134 { evt = runManager->GetPreviousEvent(eventID 135 { evt = runManager->GetPreviousEvent(eventID); } 135 if(evt==NULL) return NULL; 136 if(evt==NULL) return NULL; 136 137 137 G4HCofThisEvent* HCE = evt->GetHCofThisEvent 138 G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); 138 if(HCE==NULL) return NULL; 139 if(HCE==NULL) return NULL; 139 140 140 return HCE->GetHC(HCID); 141 return HCE->GetHC(HCID); 141 } 142 } 142 143 143 const G4VDigiCollection* G4DigiManager::GetDig 144 const G4VDigiCollection* G4DigiManager::GetDigiCollection(G4int DCID,G4int eventID) 144 { 145 { 145 const G4Event* evt = NULL; 146 const G4Event* evt = NULL; 146 if(eventID==0) 147 if(eventID==0) 147 { evt = runManager->GetCurrentEvent(); } 148 { evt = runManager->GetCurrentEvent(); } 148 else 149 else 149 { evt = runManager->GetPreviousEvent(eventID 150 { evt = runManager->GetPreviousEvent(eventID); } 150 if(evt==NULL) return NULL; 151 if(evt==NULL) return NULL; 151 152 152 G4DCofThisEvent* DCE = evt->GetDCofThisEvent 153 G4DCofThisEvent* DCE = evt->GetDCofThisEvent(); 153 if(DCE==NULL) return NULL; 154 if(DCE==NULL) return NULL; 154 155 155 return DCE->GetDC(DCID); 156 return DCE->GetDC(DCID); 156 } 157 } 157 158 158 G4int G4DigiManager::GetHitsCollectionID(const << 159 G4int G4DigiManager::GetHitsCollectionID(G4String HCname) 159 { 160 { 160 return SDManager->GetCollectionID(HCname); 161 return SDManager->GetCollectionID(HCname); 161 } 162 } 162 163 163 G4int G4DigiManager::GetDigiCollectionID(const << 164 G4int G4DigiManager::GetDigiCollectionID(G4String DCname) 164 { 165 { 165 G4int i = DCtable->GetCollectionID(DCname); 166 G4int i = DCtable->GetCollectionID(DCname); 166 if(i==-2) 167 if(i==-2) 167 { G4cout << "< " << DCname << "> is ambegiou 168 { G4cout << "< " << DCname << "> is ambegious." << G4endl; } 168 return i; 169 return i; 169 } 170 } 170 171 171 void G4DigiManager::SetDigiCollection(G4int DC 172 void G4DigiManager::SetDigiCollection(G4int DCID,G4VDigiCollection* aDC) 172 { 173 { 173 const G4Event* consEvt = runManager->GetCurr 174 const G4Event* consEvt = runManager->GetCurrentEvent(); 174 if(consEvt==NULL) 175 if(consEvt==NULL) 175 { 176 { 176 G4cout << "G4DigiManager::SetDigiCollectio 177 G4cout << "G4DigiManager::SetDigiCollection --- " 177 << "Event object is not available." < 178 << "Event object is not available." << G4endl; 178 return; 179 return; 179 } 180 } 180 181 181 G4Event* evt = (G4Event*)consEvt; 182 G4Event* evt = (G4Event*)consEvt; 182 G4DCofThisEvent* DCE = evt->GetDCofThisEvent 183 G4DCofThisEvent* DCE = evt->GetDCofThisEvent(); 183 if(DCE==NULL) 184 if(DCE==NULL) 184 { 185 { 185 DCE = new G4DCofThisEvent(DCtable->entries 186 DCE = new G4DCofThisEvent(DCtable->entries()); 186 evt->SetDCofThisEvent(DCE); 187 evt->SetDCofThisEvent(DCE); 187 if(verboseLevel>0) 188 if(verboseLevel>0) 188 { G4cout << "DCofThisEvent object is added 189 { G4cout << "DCofThisEvent object is added to current G4Event." << G4endl; } 189 } 190 } 190 191 191 DCE->AddDigiCollection(DCID,aDC); 192 DCE->AddDigiCollection(DCID,aDC); 192 193 193 if(verboseLevel>0) 194 if(verboseLevel>0) 194 { 195 { 195 G4cout << aDC->GetName() << " is stored at 196 G4cout << aDC->GetName() << " is stored at " << DCID 196 << "-th slot of G4DCofThisEvent." << 197 << "-th slot of G4DCofThisEvent." << G4endl; 197 } 198 } 198 } 199 } 199 200 200 void G4DigiManager::SetVerboseLevel(G4int val) 201 void G4DigiManager::SetVerboseLevel(G4int val) 201 { 202 { 202 verboseLevel = val; 203 verboseLevel = val; 203 for(G4int i=0;i<G4int(DMtable.size());++i) << 204 for(G4int i=0;i<int(DMtable.size());i++) 204 { DMtable[i]->SetVerboseLevel(val); } 205 { DMtable[i]->SetVerboseLevel(val); } 205 } 206 } 206 207 207 void G4DigiManager::List() const 208 void G4DigiManager::List() const 208 { 209 { 209 for(G4int i=0;i<G4int(DMtable.size());++i) << 210 for(G4int i=0;i<int(DMtable.size());i++) 210 { G4cout << " " << i << " : " << DMtable[i 211 { G4cout << " " << i << " : " << DMtable[i]->GetName() << G4endl; } 211 } 212 } 212 213 213 214 214 215 215 216