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(), 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                         printf("\nNote that simulation will fail due to multiple initializations.\n");
00108                         printf("Physics processes:\n------------------\n");
00109                         G4String s("/process/list");
00110                         doCommand(s);
00111                 }
00112         }
00113 
00114         if(particle.size() > 0) {
00115                 printf("\nNote that simulation will fail due to multiple initializations.\n");
00116                 printf("Particle details:\n----------------\n");
00117                 if(!BLManager::isInitialized())
00118                         BLManager::getObject()->initialize();
00119                 listParticleDetails();
00120         }
00121 
00122         if(exit) {
00123                 fflush(stdout);
00124                 extern void g4bl_exit(int);
00125                 g4bl_exit(0);
00126         }
00127 
00128         particle = ""; // in case another list command is issued
00129 
00130         return 0;
00131 }

void BLCMDlist::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argString(), and particle.

00134 {
00135         argString(particle,"particle","Comma-separated list of particles for "
00136                                 "which details will be printed");
00137 }

void BLCMDlist::listParticles (  ) 

References BLManager::getObject().

Referenced by command().

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

void BLCMDlist::listParticleDetails (  ) 

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

Referenced by command().

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


Member Data Documentation

G4String BLCMDlist::particle [private]


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