TVolumeViewIter.cxx

Go to the documentation of this file.
00001 // @(#)root/table:$Id: TVolumeViewIter.cxx 36269 2010-10-11 07:36:09Z brun $
00002 // Author: Valery Fine(fine@bnl.gov)   25/01/99
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TVolumeViewIter.h"
00013 #include "TObjArray.h"
00014 #include "TVolumeView.h"
00015 #include "TDataSetIter.h"
00016 #include "TGeometry.h"
00017 
00018 /////////////////////////////////////////////////////////////////////////////////
00019 //
00020 //   TVolumeViewIter is a special class-iterator to
00021 //   iterate over GEANT geometry dataset TVolumeView.
00022 //   Class should provide a "standard" well-known
00023 //   "TDataSetIter" interface to navigate and access
00024 //   the geometry information supplied by Tgeant_Maker
00025 //   as the TVolume object. Apart of the the base
00026 //   TDataSetIter this special class may supply
00027 //   not only pointer to the selected dataset but some
00028 //   "position" information (like translate vectors and
00029 //   rotation matrice).
00030 //
00031 /////////////////////////////////////////////////////////////////////////////////
00032 
00033 ClassImp(TVolumeViewIter)
00034 //______________________________________________________________________________
00035 TVolumeViewIter::TVolumeViewIter(TVolumeView *view, Int_t depth, Bool_t dir):
00036            TDataSetIter(view,depth,dir),fPositions(0)
00037 {
00038    //to be documented
00039 }
00040 
00041 //______________________________________________________________________________
00042 TVolumeViewIter::~TVolumeViewIter()
00043 {
00044    //to be documented
00045    if (fPositions) { fPositions->Delete(); delete fPositions; }
00046 }
00047 //______________________________________________________________________________
00048 const TVolumePosition *TVolumeViewIter::GetPosition(Int_t level) const
00049 {
00050    //to be documented
00051    const TVolumePosition *pos = 0;
00052    if (fPositions) {
00053       Int_t thisLevel = level;
00054       if (!thisLevel) thisLevel = fDepth;
00055       pos=(TVolumePosition *)fPositions->At(thisLevel);
00056    }
00057    return pos;
00058 }
00059 
00060 //______________________________________________________________________________
00061 TVolumePosition *TVolumeViewIter::operator[](Int_t level)
00062 {
00063    //to be documented
00064    const TVolumePosition *pos = GetPosition(level);
00065    if (pos) return new TVolumePosition(*pos);
00066    else {
00067       Error("operator[]"," GetPosition: %d %d 0x%lx", level,fDepth, (Long_t)fPositions);
00068       return 0;
00069    }
00070 }
00071 
00072 //______________________________________________________________________________
00073 void TVolumeViewIter::Notify(TDataSet *set)
00074 {
00075    //to be documented
00076    if (!set) return;
00077    TVolumeView     *view         = (TVolumeView *) set;
00078    TVolumePosition *position     = 0;
00079    position = view->GetPosition();
00080    UpdateTempMatrix(position);
00081 }
00082 
00083 //______________________________________________________________________________
00084 TVolumePosition *TVolumeViewIter::UpdateTempMatrix(TVolumePosition *curPosition)
00085 {
00086    // Pick the "old" position by pieces
00087    TVolumePosition *newPosition = 0;
00088    TVolume *curNode = 0;
00089    UInt_t curPositionId    = 0;
00090    if (curPosition) {
00091       curNode       = curPosition->GetNode();
00092       curPositionId = curPosition->GetId();
00093    } else {
00094       Error("UpdateTempMatrix","No position has been defined");
00095       return 0;
00096    }
00097    if (fDepth-1) {
00098       TVolumePosition *oldPosition = 0;
00099       const TRotMatrix *oldMatrix = 0;
00100       oldPosition = fPositions ? (TVolumePosition *)fPositions->At(fDepth-1):0;
00101       Double_t oldTranslation[] = { 0, 0, 0 };
00102       if (oldPosition) {
00103          oldMatrix         = oldPosition->GetMatrix();
00104          oldTranslation[0] = oldPosition->GetX();
00105          oldTranslation[1] = oldPosition->GetY();
00106          oldTranslation[2] = oldPosition->GetZ();
00107       }
00108 
00109       // Pick the "current" position by pieces
00110       const TRotMatrix *curMatrix        = curPosition->GetMatrix();
00111 
00112       // Create a new position
00113       Double_t newTranslation[3];
00114       Double_t newMatrix[9];
00115 
00116       if(oldMatrix) {
00117          TGeometry::UpdateTempMatrix(oldTranslation,((TRotMatrix *)oldMatrix)->GetMatrix()
00118                        ,curPosition->GetX(),curPosition->GetY(),curPosition->GetZ()
00119                        ,((TRotMatrix *)curMatrix)->GetMatrix()
00120                        ,newTranslation,newMatrix);
00121          Int_t num = gGeometry->GetListOfMatrices()->GetSize();
00122          Char_t anum[100];
00123          snprintf(anum,100,"%d",num+1);
00124          newPosition = SetPositionAt(curNode
00125                                 ,newTranslation[0],newTranslation[1],newTranslation[2]
00126                                 ,new TRotMatrix(anum,"NodeView",newMatrix));
00127          newPosition->SetMatrixOwner();
00128       } else {
00129          newTranslation[0] = oldTranslation[0] + curPosition->GetX();
00130          newTranslation[1] = oldTranslation[1] + curPosition->GetY();
00131          newTranslation[2] = oldTranslation[2] + curPosition->GetZ();
00132          newPosition = SetPositionAt(curNode,newTranslation[0],newTranslation[1],newTranslation[2]);
00133          if (newPosition) {;} //intentionally not used         
00134       }
00135    } 
00136    newPosition =  SetPositionAt(*curPosition);
00137 //         printf(" new level %d %s\n",fDepth, curNode->GetName());
00138    if (newPosition) newPosition->SetId(curPositionId);
00139    return newPosition;
00140 }
00141 
00142 //______________________________________________________________________________
00143 void TVolumeViewIter::ResetPosition(Int_t level, TVolumePosition *newPosition)
00144 {
00145    //to be documented
00146    Int_t thisLevel = level;
00147    if (!thisLevel) thisLevel = fDepth;
00148    TVolumePosition *thisPosition  =  (TVolumePosition *) GetPosition(level);
00149    if (newPosition)
00150       *thisPosition =  *newPosition;
00151 }
00152 
00153 //______________________________________________________________________________
00154 void TVolumeViewIter::Reset(TDataSet *l,Int_t depth)
00155 {
00156    //to be documented
00157    TDataSetIter::Reset(l,depth);
00158 }
00159 
00160 //______________________________________________________________________________
00161 TVolumePosition *TVolumeViewIter::SetPositionAt(TVolume *node,Double_t x, Double_t y, Double_t z, TRotMatrix *matrix)
00162 {
00163    //to be documented
00164    if (!fPositions)  fPositions = new TObjArray(100);
00165    TVolumePosition *position =  (TVolumePosition *) fPositions->At(fDepth);
00166    if (position) position->Reset(node,x,y,z,matrix);
00167    else {
00168       position = new TVolumePosition(node,x,y,z,matrix);
00169       fPositions->AddAtAndExpand(position,fDepth);
00170    }
00171    return position;
00172 }
00173 
00174 //______________________________________________________________________________
00175 TVolumePosition *TVolumeViewIter::SetPositionAt(TVolumePosition &curPosition)
00176 {
00177    //to be documented
00178    if (!fPositions)  fPositions = new TObjArray(100);
00179    TVolumePosition *position =  (TVolumePosition *) fPositions->At(fDepth);
00180    if (position) *position = curPosition;
00181    else {
00182       position = new TVolumePosition(curPosition);
00183       fPositions->AddAtAndExpand(position,fDepth);
00184    }
00185    return position;
00186 }
00187 
00188 

Generated on Tue Jul 5 14:45:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1