Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members
PisaServer.C
Go to the documentation of this file.00001 #include "PisaServer.h" 00002 00003 #include <cassert> 00004 #include <cstdlib> 00005 #include <iostream> 00006 00007 #include "TGeoManager.h" 00008 #include "TLorentzVector.h" 00009 #include "TMCVerbose.h" 00010 #include "TROOT.h" 00011 #include "TVirtualMC.h" 00012 00013 #include "PHCompositeNode.h" 00014 #include "PHIODataNode.h" 00015 #include "phool.h" 00016 00017 #include "PisaDevice.h" 00018 #include "PisaHelper.h" 00019 #include "PisaPhnxParv1.h" 00020 #include "PisaStackv1.h" 00021 00022 ClassImp(PisaServer) 00023 00024 namespace 00025 { 00026 std::string upperCase(const char* name) 00027 { 00028 std::string value = name; 00029 00030 std::transform(value.begin(), value.end(), value.begin(), 00031 (int(*)(int))std::toupper); 00032 return value; 00033 } 00034 } 00035 00036 //_____________________________________________________________________________ 00037 PisaServer* 00038 PisaServer::instance() 00039 { 00040 static PisaServer* ps = new PisaServer; 00041 return ps; 00042 } 00043 00044 //_____________________________________________________________________________ 00045 PisaServer::PisaServer() 00046 : TVirtualMCApplication("PisaServer","PISA VirtualMC Application"), 00047 fVerbose(new TMCVerbose(0)) 00048 { 00049 } 00050 00051 //_____________________________________________________________________________ 00052 PisaServer::~PisaServer() 00053 { 00054 delete fVerbose; 00055 for ( size_t i = 0; i < fDevices.size(); ++i ) 00056 { 00057 delete fDevices[i]; 00058 } 00059 } 00060 00061 //_____________________________________________________________________________ 00062 void 00063 PisaServer::makeStack(PHCompositeNode* pisanode) 00064 { 00065 PisaStack* stack = new PisaStackv1; 00066 00067 PHIODataNode<PisaStack>* stackNode = 00068 new PHIODataNode<PisaStack>(stack,"Stack"); 00069 00070 pisanode->addNode(stackNode); 00071 } 00072 00073 //_____________________________________________________________________________ 00074 bool 00075 PisaServer::hasSubsystem(const char* subsystemname) const 00076 { 00077 std::string name = upperCase(subsystemname); 00078 00079 for ( size_t i = 0; i < fDevices.size(); ++i ) 00080 { 00081 std::string dname = upperCase(fDevices[i]->subsystem()); 00082 if ( dname == name ) 00083 { 00084 return true; 00085 } 00086 } 00087 return false; 00088 } 00089 00090 //_____________________________________________________________________________ 00091 void 00092 PisaServer::Init(PHCompositeNode* topnode) 00093 { 00094 gROOT->LoadMacro("PISAConfig.C"); 00095 gROOT->ProcessLine("PISAConfig()"); 00096 00097 fVerbose->InitMC(); 00098 00099 fTopNode = topnode; 00100 00101 fTopNode->addNode(new PHCompositeNode("PISA")); 00102 00103 PHCompositeNode* pisanode = PisaHelper::getPisaNode(topnode); 00104 assert(pisanode!=0); 00105 00106 readPhnxPar(pisanode); 00107 00108 makeStack(pisanode); 00109 00110 gMC->Init(); // this will call ConstructGeometry 00111 00112 gMC->BuildPhysics(); 00113 } 00114 00115 //_____________________________________________________________________________ 00116 void 00117 PisaServer::FinishRun() 00118 { 00119 fVerbose->FinishRun(); 00120 00121 // write output to root/phool 00122 } 00123 00124 //_____________________________________________________________________________ 00125 void 00126 PisaServer::ConstructGeometry() 00127 { 00128 fVerbose->ConstructGeometry(); 00129 00130 std::cout << PHWHERE << "# of devices=" << fDevices.size() << std::endl; 00131 00132 // Ask this now so we insure we create *our* geometry manager, before 00133 // it gets created automatically by any call to TGeo*** (e.g. Material) 00134 // in some subsystem code. 00135 TGeoManager* gm = PisaHelper::getGeoManager(); 00136 00137 assert(gGeoManager!=0); 00138 00139 for ( size_t i = 0; i < fDevices.size(); ++i ) 00140 { 00141 fDevices[i]->createMaterials(fTopNode); 00142 fDevices[i]->createGeometry(fTopNode); 00143 } 00144 00145 TGeoVolume* top = gGeoManager->GetVolume("HALL"); 00146 if (!top) 00147 { 00148 std::cerr << PHWHERE << "Did not find HALL top mother volume." 00149 << "Something is seriously wrong. Aborting now." 00150 << std::endl; 00151 exit(1); 00152 } 00153 00154 // Set the top volume. 00155 gm->SetTopVolume(top); 00156 00157 // close geometry 00158 gm->CloseGeometry(); 00159 00160 // notify VMC about Root geometry 00161 gMC->SetRootGeometry(); 00162 std::cout << "I called SetRootGeometry" << std::endl; 00163 } 00164 00165 //_____________________________________________________________________________ 00166 void 00167 PisaServer::InitGeometry() 00168 { 00169 fVerbose->InitGeometry(); 00170 00171 //fCalorimeterSD->Initialize(); 00172 } 00173 00174 //_____________________________________________________________________________ 00175 void 00176 PisaServer::GeneratePrimaries() 00177 { 00178 // The generation of primaries is not done here. 00179 // It must have been done at an upper level, typically by 00180 // a SubsysReco and/or an InputManager which have to fill 00181 // the PISA/Stack node object. 00182 00183 fVerbose->GeneratePrimaries(); // Track ID (filled by stack) 00184 00185 PisaStack* stack = PisaHelper::getClass<PisaStack>(fTopNode,"Stack"); 00186 assert(stack!=0); 00187 assert(stack->stack()!=0); 00188 00189 gMC->SetStack(stack->stack()); 00190 00191 std::cout << PHWHERE << "Nprimary=" << stack->stack()->GetNprimary() 00192 << std::endl; 00193 } 00194 00195 //_____________________________________________________________________________ 00196 void 00197 PisaServer::BeginEvent() 00198 { 00199 fVerbose->BeginEvent(); 00200 00201 for ( size_t i = 0; i < fDevices.size(); ++i ) 00202 { 00203 fDevices[i]->beginEvent(fTopNode); 00204 } 00205 } 00206 00207 //_____________________________________________________________________________ 00208 void 00209 PisaServer::BeginPrimary() 00210 { 00211 fVerbose->BeginPrimary(); 00212 } 00213 00214 //_____________________________________________________________________________ 00215 void 00216 PisaServer::PostTrack() 00217 { 00218 fVerbose->PostTrack(); 00219 } 00220 00221 //_____________________________________________________________________________ 00222 void 00223 PisaServer::PreTrack() 00224 { 00225 fVerbose->PreTrack(); 00226 } 00227 00228 //_____________________________________________________________________________ 00229 void 00230 PisaServer::registerDevice(PisaDevice* device) 00231 { 00232 fDevices.push_back(device); 00233 } 00234 00235 //_____________________________________________________________________________ 00236 void 00237 PisaServer::process_event(PHCompositeNode* topnode) 00238 { 00239 fVerbose->RunMC(1); 00240 00241 assert(topnode==fTopNode); 00242 00243 gMC->ProcessRun(1); 00244 } 00245 00246 //_____________________________________________________________________________ 00247 void 00248 PisaServer::Stepping() 00249 { 00250 fVerbose->Stepping(); 00251 00252 for ( size_t i = 0; i < fDevices.size(); ++i ) 00253 { 00254 if ( fDevices[i]->isSensitive() ) 00255 { 00256 if ( fVerbosity ) 00257 { 00258 std::cout << "PisaServer::Stepping: Calling stepManager of " 00259 << fDevices[i]->name() 00260 << std::endl; 00261 } 00262 fDevices[i]->stepManager(); 00263 } 00264 else 00265 { 00266 if ( fVerbosity ) 00267 { 00268 std::cout << "PisaServer::Stepping: Skipping stepManager of " 00269 << fDevices[i]->name() 00270 << std::endl; 00271 } 00272 } 00273 } 00274 } 00275 00276 //_____________________________________________________________________________ 00277 void 00278 PisaServer::FinishPrimary() 00279 { 00280 fVerbose->FinishPrimary(); 00281 } 00282 00283 //_____________________________________________________________________________ 00284 void 00285 PisaServer::FinishEvent() 00286 { 00287 fVerbose->FinishEvent(); 00288 00289 for ( size_t i = 0; i < fDevices.size(); ++i ) 00290 { 00291 fDevices[i]->finishEvent(fTopNode); 00292 } 00293 } 00294 00295 //_____________________________________________________________________________ 00296 void 00297 PisaServer::Field(const Double_t*, Double_t* b) const 00298 { 00299 for (size_t i = 0; i < 3; ++i) 00300 { 00301 b[i] = 0.0; 00302 } 00303 } 00304 00305 //_____________________________________________________________________________ 00306 void 00307 PisaServer::readPhnxPar(PHCompositeNode* pisanode) 00308 { 00309 PisaPhnxPar* parfile = new PisaPhnxParv1("phnx.par"); 00310 00311 PHIODataNode<PisaPhnxPar>* phnxparNode = 00312 new PHIODataNode<PisaPhnxPar>(parfile, 00313 "PHNXPAR", 00314 "PHObject"); 00315 pisanode->addNode(phnxparNode); 00316 } 00317 00318 //_____________________________________________________________________________ 00319 int 00320 PisaServer::verbosity() const 00321 { 00322 return fVerbosity; 00323 } 00324 00325 //_____________________________________________________________________________ 00326 void 00327 PisaServer::verbosity(int verbosity) 00328 { 00329 fVerbose->SetLevel(verbosity); 00330 fVerbosity = verbosity; 00331 }