BLCMDprobefield Class Reference

Inheritance diagram for BLCMDprobefield:

BLCommand BLCallback

List of all members.


Detailed Description

class BLCMDprobefield is a command to print fields at specified points


Public Member Functions

 BLCMDprobefield ()
 ~BLCMDprobefield ()
G4String commandName ()
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
void defineNamedArgs ()
void callback (int type)
 callback() from BLCallback.

Private Attributes

G4String file
FILE * in
G4int exit


Constructor & Destructor Documentation

BLCMDprobefield::BLCMDprobefield (  ) 

References BLCMDTYPE_DATA, exit, file, in, BLCommand::registerCommand(), BLCommand::setDescription(), and BLCommand::setSynopsis().

Referenced by command().

00057 {
00058         registerCommand(BLCMDTYPE_DATA);
00059         setSynopsis("Prints B and E fields at specified points.");
00060         setDescription("Intended primarily for debugging. Prints Bx,By,Bz "
00061                 "in Tesla, and Ex,Ey,Ez in MegaVolts/meter. "
00062                 "Each input line is x,y,z,t separated by spaces or commas; "
00063                 "omitted values are set to 0.0. "
00064                 "Runs after the reference particle is tracked. "
00065                 "Only global coordinates are used.");
00066         file = "-";
00067         in = 0;
00068         exit = 0;
00069 }

BLCMDprobefield::~BLCMDprobefield (  )  [inline]

00042 { }


Member Function Documentation

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

Implements BLCommand.

00044 { return "probefield"; }

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

Implements BLCommand.

References BLCMDprobefield(), file, BLManager::getObject(), BLCommand::handleNamedArgs(), in, BLCommand::printError(), and BLManager::registerCallback().

00072 {
00073         if(argv.size() > 0) {
00074                 printError("probefield: Invalid argument\n");
00075                 return -1;
00076         }
00077 
00078         BLCMDprobefield *p = new BLCMDprobefield(defaultProbeField);
00079         int retval = p->handleNamedArgs(namedArgs);
00080 
00081         if(p->file == "-") {
00082                 p->in = stdin;
00083         } else {
00084                 p->in = fopen(p->file.c_str(),"r");
00085                 if(!p->in)
00086                         printError("probefield cannot open '%s'",
00087                                                         p->file.c_str());
00088                 ++retval;
00089         }
00090 
00091         // register the object to be called back to do its print.
00092         // 1 => after reference particle is tracked.
00093         BLManager::getObject()->registerCallback(p,1);
00094 
00095         return retval;
00096 }

void BLCMDprobefield::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argInt(), BLCommand::argString(), exit, and file.

00099 {
00100         argString(file,"file","Filename for reading list of points (- = stdin)");
00101         argInt(exit,"exit","Set nonzero to exit after printing field");
00102 }

void BLCMDprobefield::callback ( int  type  )  [virtual]

callback() from BLCallback.

Reimplemented from BLCallback.

References exit, g4bl_exit(), BLGlobalField::GetFieldValue(), BLGlobalField::getObject(), and in.

00105 {
00106         BLGlobalField *gf = BLGlobalField::getObject();
00107 
00108         printf("probefield is printing field values:\n");
00109         printf("#x y z t Bx By Bz Ex Ey Ez\n");
00110         for(;;) {
00111                 if(in == stdin) fprintf(stderr,"point: ");
00112                 char line[1024];
00113                 if(!fgets(line,sizeof(line),in)) break;
00114                 for(;;) {
00115                         char *p = strchr(line,',');
00116                         if(!p) break;
00117                         *p = ' ';
00118                 }
00119                 G4double pos[4];
00120                 pos[0] = pos[1] = pos[2] = pos[3] = 0.0;
00121                 sscanf(line,"%lf %lf %lf %lf",&pos[0],&pos[1],&pos[2],&pos[3]); 
00122                 pos[0] *= mm; pos[1] *= mm; pos[2] *= mm; pos[3] *= ns;
00123                 G4double field[6];
00124                 gf->GetFieldValue(pos,field);
00125                 printf("%.3f %.3f %.3f %.3f  %.6f %.6f %.6f  %.6f %.6f %.6f\n",
00126                         pos[0]/mm,pos[1]/mm,pos[2]/mm,pos[3]/ns,
00127                         field[0]/tesla,field[1]/tesla,field[2]/tesla,
00128                         field[3]/(megavolt/meter),field[4]/(megavolt/meter),
00129                         field[5]/(megavolt/meter));
00130                 fflush(stdout);
00131         }
00132 
00133         if(exit) {
00134                 printf("probefield: exit\n");
00135                 fflush(stdout);
00136                 g4bl_exit(0);
00137         }
00138 }


Member Data Documentation

G4String BLCMDprobefield::file [private]

FILE* BLCMDprobefield::in [private]

Reimplemented from BLCommand.

Referenced by BLCMDprobefield(), callback(), and command().

G4int BLCMDprobefield::exit [private]


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