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.

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


Member Function Documentation

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

Implements BLCommand.

00045 { return "place"; }

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

Implements BLCommand.

References 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.

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

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().

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

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().

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


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