G4TrajectoriesModel.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // John Allison  26th August 1998.
00031 // Model which knows how to draw GEANT4 trajectories.
00032 
00033 #include "G4TrajectoriesModel.hh"
00034 
00035 #include "G4ModelingParameters.hh"
00036 #include "G4VGraphicsScene.hh"
00037 #include "G4Event.hh"
00038 #include "G4AttDefStore.hh"
00039 #include "G4AttValue.hh"
00040 #include "G4AttDef.hh"
00041 #include "G4AttCheck.hh"
00042 #include "G4UIcommand.hh"
00043 
00044 G4TrajectoriesModel::G4TrajectoriesModel ():
00045   fDrawingModeSet(false),
00046   fDrawingMode(0),
00047   fpCurrentTrajectory(0)
00048 {
00049   fType = "G4TrajectoriesModel";
00050   fGlobalTag = "G4TrajectoriesModel for all trajectories.";
00051   fGlobalDescription = fGlobalTag;
00052 }
00053 
00054 G4TrajectoriesModel::G4TrajectoriesModel (G4int drawingMode):
00055   fDrawingModeSet(true),
00056   fDrawingMode(drawingMode),
00057   fpCurrentTrajectory(0) {
00058   fGlobalTag = "G4TrajectoriesModel for all trajectories.";
00059   fGlobalDescription = fGlobalTag;
00060 }
00061 
00062 G4TrajectoriesModel::~G4TrajectoriesModel () {}
00063 
00064 void G4TrajectoriesModelDebugG4AttValues(const G4VTrajectory*);
00065 
00066 #include "G4VVisManager.hh"
00067 void G4TrajectoriesModel::DescribeYourselfTo (G4VGraphicsScene& sceneHandler)
00068 {
00069   const G4Event* event = fpMP->GetEvent();
00070   if (!event) return;
00071 
00072   G4TrajectoryContainer* TC = event -> GetTrajectoryContainer ();
00073   if (!TC) return;
00074 
00075   G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
00076   if (!pVVisManager) return;
00077   
00078   fEventID = event->GetEventID();
00079 
00080   pVVisManager->BeginDraw();
00081   // The use of Begin/EndDraw (optional methods to improve drawing
00082   // speed) assumes all trajectories are drawn with the same
00083   // transformation.  If not, a fatal exception with be raised in
00084   // G4VisManager::DrawT.
00085   for (G4int iT = 0; iT < TC->entries(); iT++) {
00086     fpCurrentTrajectory = (*TC) [iT];
00087     // Debug trajectory:
00088     // fpCurrentTrajectory->ShowTrajectory(); G4cout << G4endl;
00089     // Debug G4AttValues:
00090     // G4TrajectoriesModelDebugG4AttValues(fpCurrentTrajectory);
00091     if (fpCurrentTrajectory)
00092       sceneHandler.AddCompound (*fpCurrentTrajectory);
00093   }
00094   pVVisManager->EndDraw();
00095 }
00096 
00097 G4bool G4TrajectoriesModel::IsDrawingModeSet() const
00098 {
00099   return fDrawingModeSet;
00100 }
00101 
00102 G4int G4TrajectoriesModel::GetDrawingMode() const
00103 {
00104   if (fDrawingModeSet) return fDrawingMode;
00105   else {
00106     G4Exception
00107       ("G4TrajectoriesModel::GetDrawingMode",
00108        "modeling0010",
00109        FatalException,
00110        "Illegal attempt to obtain i_mode."
00111        "\n  i_mode is an old trajectories parameter that is DEPRECATED"
00112        "\n  and will be removed at the next major release."
00113        );
00114     return 0;
00115   }
00116 }
00117 
00118 void G4TrajectoriesModel::SetDrawingMode(G4int drawingMode)
00119 {
00120   if (fDrawingModeSet) fDrawingMode = drawingMode;
00121   else {
00122     G4Exception
00123       ("G4TrajectoriesModel::SetDrawingMode",
00124        "modeling0011",
00125        FatalException,
00126        "Illegal attempt to set i_mode."
00127        "\n  i_mode is an old trajectories parameter that is DEPRECATED"
00128        "\n  and will be removed at the next major release."
00129        );
00130   }
00131 }
00132 
00133 const std::map<G4String,G4AttDef>* G4TrajectoriesModel::GetAttDefs() const
00134 {
00135   G4bool isNew;
00136   std::map<G4String,G4AttDef>* store
00137   = G4AttDefStore::GetInstance("G4TrajectoriesModel", isNew);
00138   if (isNew) {
00139     (*store)["EventID"] =
00140     G4AttDef("EventID","Event ID","Physics","","G4int");
00141   }
00142   return store;
00143 }
00144 
00145 std::vector<G4AttValue>* G4TrajectoriesModel::CreateCurrentAttValues() const
00146 {
00147   std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
00148   values->push_back
00149   (G4AttValue("EventID",G4UIcommand::ConvertToString(fEventID),""));
00150   return values;
00151 }
00152 
00153 // Debug material...
00154 
00155 #include "G4VTrajectoryPoint.hh"
00156 
00157 void G4TrajectoriesModelDebugG4AttValues(const G4VTrajectory* pTraj)
00158 {
00159   // Trajectory attributes
00160   {  // Scope bracket - allows re-use of names without compiler warnings.
00161     std::vector<G4AttValue>* attValues = pTraj->CreateAttValues();
00162     if (attValues) {
00163       G4AttCheck attCheck(attValues, pTraj->GetAttDefs());
00164       G4cout << "\nProvided G4Atts:\n" << attCheck;
00165       if (attCheck.Check()) G4cout << "Error" << G4endl;
00166       else {
00167         std::vector<G4AttValue> standardValues;
00168         std::map<G4String,G4AttDef> standardDefinitions;
00169         attCheck.Standard(&standardValues, &standardDefinitions);
00170         G4cout << "\nStandard G4Atts:\n"
00171                << G4AttCheck(&standardValues, &standardDefinitions);
00172       }
00173       delete attValues;
00174     }
00175   }
00176   // Trajectory point attributes
00177   for (G4int i = 0; i < pTraj->GetPointEntries(); i++) {
00178     G4VTrajectoryPoint* aPoint = pTraj->GetPoint(i);
00179     std::vector<G4AttValue>* attValues = aPoint->CreateAttValues();
00180     if (attValues) {
00181       G4AttCheck attCheck(attValues, aPoint->GetAttDefs());
00182       G4cout << "\nProvided G4Atts:\n" << attCheck;
00183       if (attCheck.Check()) G4cout << "Error" << G4endl;
00184       else {
00185         std::vector<G4AttValue> standardValues;
00186         std::map<G4String,G4AttDef> standardDefinitions;
00187         attCheck.Standard(&standardValues, &standardDefinitions);
00188         G4cout << "\nStandard G4Atts:\n"
00189                << G4AttCheck(&standardValues, &standardDefinitions);
00190       }
00191       delete attValues;
00192     }
00193   }
00194 }

Generated on Mon May 27 17:50:01 2013 for Geant4 by  doxygen 1.4.7