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5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

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