BLCMDlist Class Reference

Inheritance diagram for BLCMDlist:

BLCommand

List of all members.


Detailed Description

class BLCMDlist implements the list command.

Public Member Functions

 BLCMDlist ()
G4String commandName ()
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
void defineNamedArgs ()
void listParticles ()
void listParticleDetails ()

Private Attributes

G4String particle

Constructor & Destructor Documentation

BLCMDlist::BLCMDlist (  ) 

References BLCMDTYPE_CONTROL, BLCommand::registerCommand(), BLCommand::setDescription(), and BLCommand::setSynopsis().

00047 {
00048         registerCommand(BLCMDTYPE_CONTROL);
00049         setSynopsis("provides interactive list of interesting internal tables.");
00050         setDescription("list with no arguments lists all lists except processes.\n"
00051                 "'list name' lists that specific one.\n"
00052                 "'list -exit name(s)' will exit after listing.\n"
00053                 "List names are:\n"
00054                 "    commands    all commands\n"
00055                 "    materials   currently known materials\n"
00056                 "    physics     all physics lists\n"
00057                 "    particles   currently known particles\n"
00058                 "    processes   currently known physics processes ***\n"
00059                 "NOTE: the particles and processes lists are "
00060                 "not populated until the physics list is selected (via "
00061                 "the physics command). Different physics lists use different "
00062                 "processes and particles.\n\n"
00063                 "***NOTE: listing processes will prevent any simulating, "
00064                 "as will a non-empty particle list.");
00065 }


Member Function Documentation

G4String BLCMDlist::commandName (  )  [inline, virtual]

Implements BLCommand.

00033 { return "list"; }

int BLCMDlist::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

Implements BLCommand.

References BLCommand::doCommand(), g4bl_exit(), BLManager::getObject(), BLManager::handleCallbacks(), BLCommand::handleNamedArgs(), BLManager::initialize(), BLManager::isInitialized(), listParticleDetails(), listParticles(), and particle.

00069 {
00070         bool exit = (argv.size() > 0 && argv[0] == "-exit");
00071         if(exit) argv.erase(argv.begin());
00072 
00073         handleNamedArgs(namedArgs);
00074 
00075         if((argv.size() == 0 || argv[0] == "*" || argv[0] == "all") &&
00076                                                 particle.size() == 0) {
00077                 argv.clear();
00078                 argv.push_back("commands");
00079                 argv.push_back("materials");
00080                 argv.push_back("physics");
00081                 argv.push_back("particles");
00082                 //argv.push_back("processes");
00083         }
00084 
00085         for(unsigned i=0; i<argv.size(); ++i) {
00086                 if(argv[i].compareTo("commands",G4String::ignoreCase) == 0) {
00087                         printf("\nCommands:\n---------\n");
00088                         G4String s("help");
00089                         doCommand(s);
00090                 } else if(argv[i].compareTo("particles",G4String::ignoreCase) == 0) {
00091                         printf("\nParticles:\n----------\n");
00092                         listParticles();
00093                 } else if(argv[i].compareTo("physics",G4String::ignoreCase) == 0) {
00094                         printf("\nPhysics lists:\n--------------\n");
00095                         G4String s("physics");
00096                         doCommand(s);
00097                 } else if(argv[i].compareTo("materials",G4String::ignoreCase) == 0) {
00098                         G4String s("material");
00099                         doCommand(s);
00100                 } else if(argv[i].compareTo("processes",G4String::ignoreCase) == 0) {
00101                         if(BLManager::getObject()->getPhysics() == 0) {
00102                                 printf("cannot list processes -- no physics registered.\n");
00103                                 return 0;
00104                         }
00105                         if(!BLManager::isInitialized()) {
00106                                 BLManager::getObject()->initialize();
00107                                 BLManager::getObject()->handleCallbacks(0);
00108                         }
00109                         printf("\nlist: Note that simulation will fail due to multiple initializations.\n");
00110                         printf("Physics processes:\n------------------\n");
00111                         G4String s("/process/list");
00112                         doCommand(s);
00113                 }
00114         }
00115 
00116         if(particle.size() > 0) {
00117                 printf("\nlist: Note that simulation will fail due to multiple initializations.\n");
00118                 printf("Particle details:\n----------------\n");
00119                 if(!BLManager::isInitialized()) {
00120                         BLManager::getObject()->initialize();
00121                         BLManager::getObject()->handleCallbacks(0);
00122                 }
00123                 listParticleDetails();
00124         }
00125 
00126         if(exit) {
00127                 fflush(stdout);
00128                 extern void g4bl_exit(int);
00129                 g4bl_exit(0);
00130         }
00131 
00132         particle = ""; // in case another list command is issued
00133 
00134         return 0;
00135 }

void BLCMDlist::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argString(), and particle.

00138 {
00139         argString(particle,"particle","Comma-separated list of particles for "
00140                                 "which details will be printed");
00141 }

void BLCMDlist::listParticles (  ) 

References BLManager::getObject().

Referenced by command().

00144 {
00145         if(BLManager::getObject()->getPhysics() == 0) {
00146                 printf("cannot list particles -- no physics registered.\n");
00147                 return;
00148         }
00149 
00150         G4ParticleTable::G4PTblDicIterator *i =
00151                         G4ParticleTable::GetParticleTable()->GetIterator();
00152         i->reset();
00153         int n=0;
00154         while((*i)()) {
00155                 G4ParticleDefinition *pd = i->value();
00156                 printf("%15s PDGid=%d\n", pd->GetParticleName().c_str(),
00157                          pd->GetPDGEncoding());
00158                 ++n;
00159         }
00160         if(n == 0)
00161                 printf("No particles listed -- select physics list first\n");
00162 }

void BLCMDlist::listParticleDetails (  ) 

References particle, BLCommand::printError(), BLCommand::splitString(), and BLCommand::wrapWords().

Referenced by command().

00165 {
00166         G4ParticleTable *table = G4ParticleTable::GetParticleTable();
00167         std::vector<G4String> v = splitString(particle,',');
00168         for(unsigned i=0; i<v.size(); ++i) {
00169                 G4ParticleDefinition *pd = table->FindParticle(v[i]);
00170                 if(!pd) {
00171                         printError("list: cannot find particle '%s'\n",
00172                                                                 v[i].c_str());
00173                         continue;
00174                 }
00175                 G4ProcessManager *pmgr = pd->GetProcessManager();
00176                 if(!pmgr) continue;
00177                 G4String line(v[i] + " ");
00178                 while(line.size() < 10) line += " ";
00179                 printf("%sPDGid=%d  mass=%.3f MeV/c^2\n",line.c_str(),
00180                         pd->GetPDGEncoding(),pd->GetPDGMass());
00181                 G4ProcessVector *pv = pmgr->GetProcessList();
00182                 line = "Processes: ";
00183                 for(int i=0; i<pv->size(); ++i) {
00184                         if(!pmgr->GetProcessActivation(i)) continue;
00185                         line += (*pv)[i]->GetProcessName() + " ";
00186                 }
00187                 printf("%s",wrapWords(line,"          ","                     ").c_str());
00188         }
00189 
00190 
00191 /*** 
00192         // add "bookends" to simplify the comparison
00193         G4String comma(",");
00194         particle = comma + particle + comma;
00195 
00196         G4ParticleTable::G4PTblDicIterator *theParticleIterator
00197                         = G4ParticleTable::GetParticleTable()->GetIterator();
00198         theParticleIterator->reset();
00199         while((*theParticleIterator)()) {
00200                 G4ParticleDefinition *pd = theParticleIterator->value();
00201                 G4ProcessManager *pmgr = pd->GetProcessManager();
00202                 if(!pmgr) continue;
00203                 G4String name = pd->GetParticleName();
00204                 if(particle.find(comma+name+comma) == particle.npos) continue;
00205                 G4String line(name + " ");
00206                 while(line.size() < 10) line += " ";
00207                 printf("%sPDGid=%d  mass=%.3f MeV/c^2\n",line.c_str(),
00208                         pd->GetPDGEncoding(),pd->GetPDGMass());
00209                 G4ProcessVector *pv = pmgr->GetProcessList();
00210                 line = "Processes: ";
00211                 for(int i=0; i<pv->size(); ++i) {
00212                         if(!pmgr->GetProcessActivation(i)) continue;
00213                         line += (*pv)[i]->GetProcessName() + " ";
00214                 }
00215                 printf("%s",wrapWords(line,"          ","                     ").c_str());
00216         }
00217 ***/
00218 }


Member Data Documentation

G4String BLCMDlist::particle [private]


The documentation for this class was generated from the following file:
g4beamline