BLCMDplace Class Reference

Inheritance diagram for BLCMDplace:

BLCommand

List of all members.


Detailed Description

class BLCMDplace implements the place command.

Public Member Functions

 BLCMDplace ()
G4String commandName ()
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
void defineNamedArgs ()
int handleNamedArgs (BLArgumentMap &namedArgs)
 special version of handleNamedArgs().

Private Attributes

G4double x
G4double y
G4double z
G4String parent
G4String rename
G4String rotation
G4String coordinates
G4int copies
G4int front
BLElementelement

Constructor & Destructor Documentation

BLCMDplace::BLCMDplace (  ) 

References BLCMDTYPE_PLACE, coordinates, copies, element, front, parent, BLCommand::registerCommand(), rename, rotation, BLCommand::setDescription(), BLCommand::setSynopsis(), x, y, and z.

00059 {
00060         registerCommand(BLCMDTYPE_PLACE);
00061         setSynopsis("places an element into the current group (or world).");
00062         setDescription("Every element can be placed multiple times into the\n"
00063                 "beamline. For most elements the geometrical centerpoint is\n"
00064                 "placed; for polycone the local x=y=z=0 point is placed. "
00065                 "If front is nonzero then the front of the element is "
00066                 "placed.\n"
00067                 "If z is specified, then the element is placed\n"
00068                 "at that z position relative to the center of the enclosing\n"
00069                 "group. If z is not specified, then the element is placed\n"
00070                 "immediately downstream (higher z) of the previous element\n"
00071                 "in the group, or at the upstream edge of the group if this\n"
00072                 "is the first element in the group.\n\n"
00073                 "The 'rename' argument can be used to change the name of the "
00074                 "element (applies to traces and other uses of object names, "
00075                 "such as the NTuple name of a virtualdetector). When placing "
00076                 "into a group or other object, the rename argument should "
00077                 "normally begin with '+' to include the parent's name; "
00078                 "otherwise multiple placements of the parent will generate "
00079                 "multiple objects with identical names -- that should "
00080                 "be avoided for output objects like virtualdetector. "
00081                 "Without a rename argument, the parent's name is included "
00082                 "automatically.\n\n"
00083                 "When multiple copies are placed, z refers to the first, and "
00084                 "the rest are placed sequentially along z.\n"
00085                 "When placing an element into the World group, Centerline\n"
00086                 "coordinates are used unless coordinates=global is present.\n"
00087                 "When centerline coordinates are used, the parameter 'Zcl' is "
00088                 "set to the highest Z value used; this is normally the Z value "
00089                 "for the front of the next element when placed sequentially "
00090                 "(i.e. with no z value given).\n"
00091                 "\nRotations:\n"
00092                 "The rotation parameter can be used to rotate this element \n"
00093                 "relative to "
00094                 "the enclosing group. The object is rotated, not the axes.\n"
00095                 "Rotations are specified as a comma-separated list of axes\n"
00096                 "and angles (in degrees): rotate=Z90,X45 rotates first by 90\n"
00097                 "degrees around Z and then by 45 degrees around X. The axes\n"
00098                 "are the local X,Y,Z coordinate axes of the enclosing group\n"
00099                 "(centerline or global coordinate axes for the World group);\n"
00100                 "groups can be rotated when placed, and are rotated as a\n"
00101                 "rigid unit (including children).\n\n"
00102                 "If parent=name is present, then the name must be an element\n"
00103                 "that accepts children, and it is used as the enclosing group;\n"
00104                 "in this case the size of the group is implied by the size\n"
00105                 "of the parent element, and z must be given (defaults to 0).\n"
00106                 "Note that a given element cannot be the parent of any other\n"
00107                 "element once it has been placed, so you must place children\n"
00108                 "into their parent before placing their parent.\n\n"
00109                 "If the special element 'OFFSET' is given, x, y, and z\n"
00110                 "specify offsets for every following place command into the\n"
00111                 "current group (incl. World), that gives a z position.");
00112         x = 0.0;
00113         y = 0.0;
00114         z = 0.0;
00115         parent = "";
00116         rename = "";
00117         rotation = "";
00118         coordinates = "Centerline";
00119         copies = 1;
00120         front = 0;
00121         element = 0;
00122 }


Member Function Documentation

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

Implements BLCommand.

00046 { return "place"; }

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

Implements BLCommand.

References BLAssert, BLCOORD_CENTERLINE, BLCOORD_GLOBAL, coordinates, copies, element, BLGroupElement::find(), BLElement::find(), front, BLCoordinates::getCoordinateType(), BLGroup::getCurrent(), BLElement::getLength(), BLGroup::getOffset(), BLElement::getPlacedFlag(), BLGroup::getWorld(), handleNamedArgs(), NO_RENAME(), parent, BLGroupElement::placeChild(), BLGroup::placeElement(), BLCommand::printError(), rename, rotation, BLGroup::setOffset(), BLElement::setPlacedFlag(), BLCommand::stringToRotationMatrix(), UNDETERMINED, x, y, and z.

00125 {
00126         if(argv.size() != 1) {
00127                 printError("Invalid place command -- need one element name");
00128                 return -1;
00129         }
00130 
00131         // handle offsets in x, y, and z
00132         if(argv[0] == "OFFSET") {
00133                 x = 0.0;
00134                 y = 0.0;
00135                 z = 0.0;
00136                 handleNamedArgs(namedArgs);
00137                 G4ThreeVector offset(x,y,z);
00138                 BLGroup::getCurrent()->setOffset(offset);
00139                 return 0;
00140         }
00141 
00142         element = BLElement::find(argv[0]);
00143         if(!element) {
00144                 printError("place: cannot find element '%s'",argv[0].c_str());
00145                 return -1;
00146         }
00147 
00148         // clear previous values
00149         x = UNDETERMINED;
00150         y = UNDETERMINED;
00151         z = UNDETERMINED;
00152         parent = "";
00153         rename = NO_RENAME;
00154         copies = 1;
00155         rotation = "";
00156         coordinates = "Centerline";
00157         front = 0;
00158 
00159         handleNamedArgs(namedArgs);
00160 
00161         if(z != UNDETERMINED && front != 0)  {
00162                 double len = element->getLength();
00163                 if(len <= 0.0)
00164                         printError("place: element length is <= 0 -- cannot use front=1");
00165                 z += len/2.0;
00166         }
00167 
00168         if(rename != NO_RENAME && rename.find_first_of('+') != 0) {
00169                 if(BLGroup::getCurrent() != BLGroup::getWorld())
00170                         G4Exception("place command","No rename",JustWarning,
00171                           "Multiple placements of the enclosing group "
00172                           "will create multiple objects with identical names.");
00173                 else if(parent != "")
00174                         G4Exception("place command","No rename",JustWarning,
00175                           "Multiple placements of the parent "
00176                           "will create multiple objects with identical names.");
00177         }
00178 
00179         if(parent != "") {
00180                 BLGroupElement *ge = BLGroupElement::find(parent);
00181                 if(!ge) {
00182                         if(BLElement::find(parent) != 0) {
00183                                 printError("place: parent '%s' cannot have children",
00184                                         parent.c_str());
00185                         } else {
00186                                 printError("place: cannot find parent '%s'",
00187                                         parent.c_str());
00188                         }
00189                         return -1;
00190                 }
00191                 if(ge->getPlacedFlag()) {
00192                         printError("place: parent '%s' has already been placed",
00193                                         parent.c_str());
00194                         return -1;
00195                 }
00196                 if(z == UNDETERMINED && element->getLength() == 0) {
00197                         printError("place: element length is <= 0 -- cannot be placed sequentially");
00198                 }
00199                 if(x == UNDETERMINED) x = 0.0;
00200                 if(y == UNDETERMINED) y = 0.0;
00201                 if(z == UNDETERMINED) z = 0.0;
00202                 G4ThreeVector offset(x,y,z);
00203                 G4RotationMatrix *rot = 0;
00204                 if(rotation != "")
00205                         rot = stringToRotationMatrix(rotation);
00206                 for(int i=0; i<copies; ++i) {
00207                     ge->placeChild(element,rot,offset,rename);
00208                     offset[2] += element->getLength();
00209                 }
00210                 printf("place   %-7s parent=%s copies=%d x=%.1f y=%.1f z=%.1f ",
00211                                 argv[0].c_str(),parent.c_str(),copies,x,y,z);
00212                 if(rename != NO_RENAME)
00213                         printf("rename='%s'",rename.c_str());
00214                 if(rotation != "")
00215                         printf("rotation='%s'",rotation.c_str());
00216                 printf("\n");
00217                 element->setPlacedFlag();
00218                 return 0;
00219         }
00220 
00221         BLCoordinateType coordType = 
00222                                 BLCoordinates::getCoordinateType(coordinates);
00223         BLAssert(coordType==BLCOORD_GLOBAL || coordType==BLCOORD_CENTERLINE);
00224 
00225         // if placing into a group, indent by 2 spaces
00226         const char *p;
00227         if(BLGroup::getCurrent() == BLGroup::getWorld())
00228                 p = "place  ";
00229         else
00230                 p = "  place";
00231 
00232         if(z == UNDETERMINED) {
00233                 if(rotation != "")
00234                         printError("place without z being given, rotation is"
00235                                         " ignored");
00236                 if(x != UNDETERMINED || y != UNDETERMINED)
00237                         printError("place without z being given, x and y are"
00238                                                 " ignored");
00239                 if(element->getLength() == 0) {
00240                         printError("place: element length is <= 0 -- cannot be placed sequentially");
00241                 }
00242                 for(int i=0; i<copies; ++i)
00243                         BLGroup::getCurrent()->placeElement(element,rename,
00244                                                 coordType==BLCOORD_GLOBAL);
00245                 printf("%-7s %-7s copies=%d sequentially along z; ",
00246                                 p,argv[0].c_str(),copies);
00247                 if(rename != NO_RENAME)
00248                         printf("rename='%s'",rename.c_str());
00249         } else {
00250                 if(x == UNDETERMINED) x = 0.0;
00251                 if(y == UNDETERMINED) y = 0.0;
00252                 G4ThreeVector offset(x,y,z);
00253                 offset += BLGroup::getCurrent()->getOffset();
00254                 G4RotationMatrix *rot = 0;
00255                 if(rotation != "")
00256                         rot = stringToRotationMatrix(rotation);
00257                 for(int i=0; i<copies; ++i) {
00258                     BLGroup::getCurrent()->placeElement(element,rot,offset,
00259                                         rename, coordType==BLCOORD_GLOBAL);
00260                     offset[2] += element->getLength();
00261                 }
00262                 printf("%-7s %-7s copies=%d x=%.1f y=%.1f z=%.1f ",
00263                                 p,argv[0].c_str(),copies,x,y,z);
00264                 if(rename != NO_RENAME)
00265                         printf("rename='%s'",rename.c_str());
00266                 if(rotation != "")
00267                         printf("rotation='%s'",rotation.c_str());
00268         }
00269         printf("\n");
00270 
00271         element->setPlacedFlag();
00272 
00273         return 0;
00274 }

void BLCMDplace::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argString(), coordinates, copies, front, parent, rename, rotation, x, y, and z.

Referenced by handleNamedArgs().

00277 {
00278         argDouble(z,"z","Z position of element's center relative to the "
00279                 "center of the enclosing group (mm).");
00280         argDouble(x,"x","X position of element's center [default=0] (mm)");
00281         argDouble(y,"y","Y position of element's center [default=0] (mm)");
00282         argString(parent,"parent","Parent element name (must accept children).");
00283         argString(rename,"rename","Name to use for this placement; '#' will "
00284                 "be substituted by the number of placements. If the value "
00285                 "begins with '+', it is replaced with the parent's name.");
00286         argInt(copies,"copies","Number of copies (placed sequentially along z).");
00287         argInt(front,"front","Nonzero to specify z for the front, not the center.");
00288         argString(rotation,"rotation","Rotation of this object.");
00289         argString(coordinates,"coordinates","Coordinates: global or centerline (default=c).");
00290 }

int BLCMDplace::handleNamedArgs ( BLArgumentMap namedArgs  ) 

special version of handleNamedArgs().

Reimplemented from BLCommand.

References BLCommand::argChanged(), BLCommand::argFound, BLCommand::argMode, BLCommand::argName, BLCommand::argValue, BLCommand::CHANGE, BLElement::clone(), BLCommand::defineNamedArgs(), defineNamedArgs(), element, BLCommand::printError(), and BLCommand::PROCESS.

Referenced by command().

00293 {
00294         int retval = 0;
00295         argMode = PROCESS;
00296         bool isCloned = false;
00297 
00298         BLArgumentMap::iterator i;
00299         for(i=args.begin(); i!=args.end(); ++i) {
00300                 argName = i->first;
00301                 argValue = i->second;
00302                 argFound = false;
00303                 defineNamedArgs();
00304                 if(!argFound) {
00305                         // handle element args
00306                         if(!isCloned) {
00307                                 element = element->clone();
00308                                 isCloned = true;
00309                         }
00310                         element->argName = argName;
00311                         element->argValue = argValue;
00312                         element->argFound = false;
00313                         element->argMode = CHANGE;
00314                         element->defineNamedArgs();
00315                         if(!element->argFound) {
00316                                 printError("Invalid argument '%s' to place",
00317                                         argName.c_str());
00318                                 retval = -1;
00319                         }
00320                 }
00321         }
00322 
00323         if(isCloned) element->argChanged();
00324 
00325         return retval;
00326 }


Member Data Documentation

G4double BLCMDplace::x [private]

G4double BLCMDplace::y [private]

G4double BLCMDplace::z [private]

G4String BLCMDplace::parent [private]

G4String BLCMDplace::rename [private]

G4String BLCMDplace::rotation [private]

G4String BLCMDplace::coordinates [private]

G4int BLCMDplace::copies [private]

G4int BLCMDplace::front [private]


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