Changeset 288 for snovis


Ignore:
Timestamp:
Sep 25, 2007, 12:24:08 PM (17 years ago)
Author:
barrand
Message:
 
Location:
snovis/trunk/source/G4Lab
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • snovis/trunk/source/G4Lab/DigitsCollectionAccessor.h

    r233 r288  
    1111class G4LogicalVolume;
    1212class G4Colour;
     13class G4RunManager;
    1314
    1415namespace Slash {namespace Core {class ISession;}}
     
    2930  virtual void visualize(Slash::Data::IAccessor::Data,void*);
    3031public:
    31   DigitsCollectionBaseAccessor(Slash::Core::ISession&,const std::string& = "");
     32  DigitsCollectionBaseAccessor(Slash::Core::ISession&,G4RunManager*,
     33                               const std::string& = "");
    3234  virtual ~DigitsCollectionBaseAccessor();
    3335  const std::string& DCName() const;
    3436protected:
    35   static G4VDigiCollection* getCollection(Slash::Core::IWriter&,const std::string&);
    3637  static G4LogicalVolume* digiLogicalVolume(const G4VDigi&);
    3738  static G4Transform3D* digiTransform3D(const G4VDigi&);
     
    3940  void setProperties(G4VDigi&);
    4041protected:
     42  G4VDigiCollection* getCollection(Slash::Core::IWriter&,const std::string&);
     43protected:
    4144  std::string fType;
     45  G4RunManager* fRunManager;
    4246  std::map<G4String,G4AttDef>* fAttDefs;
    4347  std::string fDC;
     
    8892  }
    8993public:
    90   DigitsCollectionAccessor(Slash::Core::ISession& aSession,const std::string& aName = "")
    91   :DigitsCollectionBaseAccessor(aSession,aName){}
     94  DigitsCollectionAccessor(Slash::Core::ISession& aSession,
     95                           G4RunManager* aRunManager,
     96                           const std::string& aName = "")
     97  :DigitsCollectionBaseAccessor(aSession,aRunManager,aName){}
    9298  virtual ~DigitsCollectionAccessor(){}
    9399};
  • snovis/trunk/source/G4Lab/HitsCollectionAccessor.h

    r233 r288  
    1111class G4LogicalVolume;
    1212class G4Colour;
     13class G4RunManager;
    1314
    1415namespace Slash {namespace Core {class ISession;}}
     
    3031  virtual void visualize(Slash::Data::IAccessor::Data,void*);
    3132public:
    32   HitsCollectionAccessor(Slash::Core::ISession&,const std::string& = "");
     33  HitsCollectionAccessor(Slash::Core::ISession&,G4RunManager*,
     34                         const std::string& = "");
    3335  virtual ~HitsCollectionAccessor();
    3436  const std::string& HCName() const;
     
    3739  static G4Transform3D* hitTransform3D(const G4VHit&);
    3840  static bool hitColor(const G4VHit&,G4Colour&);
    39   static G4VHitsCollection* getCollection(Slash::Core::IWriter&,const std::string&);
     41protected:
     42  G4VHitsCollection* getCollection(Slash::Core::IWriter&,const std::string&);
    4043private:
    4144  std::string fType;
     45  G4RunManager* fRunManager;
    4246  std::map<G4String,G4AttDef>* fAttDefs;
    4347  std::string fHC;
  • snovis/trunk/source/G4Lab/PhysicsTableAccessor.h

    r233 r288  
    1414namespace AIDA {class IAnalysisFactory;}
    1515
     16namespace G4Lab {class PhysicsTable;}
     17
     18class IGeant4Manager;
     19
    1620namespace G4Lab {
    17 
    18 class PhysicsTable;
    1921
    2022class PhysicsTableAccessor
    2123:public Lib::BaseAccessor
    22 ,public Slash::Data::IVisualizer
     24,public virtual Slash::Data::IVisualizer
    2325{
    2426public: //Slash::Data::IAccessor
     27  virtual void* cast(const std::string& aClass) const;
    2528  virtual std::string name() const;
    2629  virtual Slash::Data::IIterator* iterator();
     
    3134  virtual void endVisualize();
    3235public:
    33   PhysicsTableAccessor(Slash::Core::ISession&,AIDA::IAnalysisFactory*);
     36  PhysicsTableAccessor(Slash::Core::ISession&,
     37                       IGeant4Manager&,
     38                       AIDA::IAnalysisFactory*);
    3439  virtual ~PhysicsTableAccessor();
    3540private:
     41  bool buildProcessTables();
    3642  bool findProcessTables(G4ParticleDefinition*,
    3743                         G4VProcess*,
     
    4349  std::vector<PhysicsTable*> fTables;
    4450  AIDA::IAnalysisFactory* fAIDA;
     51  IGeant4Manager& fManager;
    4552};
    4653
  • snovis/trunk/source/G4Lab/SoG4RunManager.h

    r233 r288  
    22#define G4Lab_SoG4RunManager_h
    33
     4// Inheritance :
    45#include <Inventor/nodes/SoSubNode.h>
     6
    57#include <Inventor/fields/SoSFInt32.h>
     8
     9class G4RunManager;
    610
    711class SoG4RunManager : public SoNode {
     
    1115public:
    1216  SoG4RunManager();
     17  SoG4RunManager(G4RunManager*);
    1318public:
    1419  static void initClass();
     
    1722protected:
    1823  virtual ~SoG4RunManager();
     24private:
     25  G4RunManager* fRunManager;
    1926};
    2027
  • snovis/trunk/source/G4Lab/SoG4Trajectories.h

    r233 r288  
    1414
    1515class G4TrajectoryContainer;
     16class G4RunManager;
     17
    1618class SoSensor;
    1719class SoFieldSensor;
     
    4850public:
    4951  SoG4Trajectories();
     52  SoG4Trajectories(G4RunManager*);
    5053  virtual void generateAlternateRep();
    5154  virtual void clearAlternateRep();
     
    6366  void flush();
    6467  static void sensorCB(void*,SoSensor*);
    65   bool isG4LabTrajectories(G4TrajectoryContainer*);
    6668  void timeOrder(G4TrajectoryContainer*);
    6769private:
     70  G4RunManager* fRunManager;
    6871  G4TrajectoryContainer* fContainer;
    6972  std::vector< std::vector<PointIdentifier> > fTimeOrderedPoints;
  • snovis/trunk/source/G4Lab/Trajectory.h

    r233 r288  
    22#define G4Lab_Trajectory_h
    33
     4// Inheritance :
    45#include <G4Trajectory.hh>
     6#include <G4Lab/Interfaces/IGeant4Trajectory.h>
    57
    68#include <vector>
     
    810#include <Lib/Debug.h>
    911
     12//class G4VProcess;
     13
    1014namespace G4Lab {
    1115
    1216class TrajectoryPoint;
    1317
    14 class Trajectory : public G4Trajectory {
     18class Trajectory
     19:public G4Trajectory
     20,public virtual IGeant4Trajectory
     21{
     22public: // G4VTrajectory:
     23   virtual const std::map<G4String,G4AttDef>* GetAttDefs() const;
     24   virtual std::vector<G4AttValue>* CreateAttValues() const;
    1525public: // G4Trajectory:
    1626  virtual void ShowTrajectory(std::ostream& = G4cout) const;
     
    2030  virtual G4VTrajectoryPoint* GetPoint(G4int) const;
    2131  virtual void MergeTrajectory(G4VTrajectory*);
     32public: // IGeant4Trajectory:
     33  virtual double kineticEnergy() const;
     34  virtual double totalEnergy() const;
     35  virtual double globalTime() const;
     36  virtual unsigned int pointEntries() const;
     37  virtual double pointGlobalTime(unsigned int) const;
     38  virtual std::string creatorProcessName() const;
     39  virtual std::string creatorProcessType() const;
     40  virtual void setSave(bool);
     41  virtual bool save() const;
     42  virtual std::vector<double> stoppingPoint() const;
     43  virtual G4VPhysicalVolume* stoppingPhysicalVolume() const;
    2244public:
    2345  Trajectory(const G4Track*);
    2446  Trajectory(Trajectory&);
    2547  virtual ~Trajectory();
    26   /*inline*/ void* operator new(size_t);
    27   /*inline*/ void operator delete(void*);
    28   /*inline*/ int operator == (const Trajectory&) const;
    29   G4double GetKineticEnergy() const;
    30   G4double GetTotalEnergy() const;
    31   G4double GetGlobalTime() const;
    32   G4double GetPointGlobalTime(G4int) const;
     48  void* operator new(size_t);
     49  void operator delete(void*);
     50  int operator == (const Trajectory&) const;
    3351private:
    3452  std::vector<TrajectoryPoint*> fPoints;
     
    3654  G4double fTotalEnergy;
    3755  G4double fGlobalTime;
     56  const G4VProcess* fProcess;
     57  bool fSave;
     58  G4ThreeVector fStoppingPoint;
     59  G4VPhysicalVolume* fStoppingVolume;
    3860  Lib::Debug fDebug;
    3961};
  • snovis/trunk/source/G4Lab/TrajectoryAccessor.h

    r233 r288  
    1313class IOut;
    1414
     15class G4RunManager;
     16
     17#include <map>
     18#include <G4AttDef.hh>
     19#include <G4String.hh>
     20
    1521namespace G4Lab {
    1622
     
    2531  virtual void endVisualize();
    2632public:
    27   TrajectoryAccessor(Slash::Core::ISession&);
     33  TrajectoryAccessor(Slash::Core::ISession&,G4RunManager*);
    2834  virtual ~TrajectoryAccessor();
    2935private:
    3036  void addPolyline(SoGroup*,const SbName&,
    3137                   int,SbVec3f*,const SbColor&,const SbColor&,IOut&);
    32   bool isG4LabTrajectory();
     38  bool isIGeant4Trajectory();
     39  void addAttDefsProperties();
     40  Slash::Core::IValue* findAttDefsValue(Slash::Data::IAccessor::Data,
     41                                        const std::string&,void*);
    3342private:
    3443  std::string fType;
     44  G4RunManager* fRunManager;
     45  std::map<G4String,G4AttDef>* fAttDefs;
    3546  std::string fModeling;
    36   bool fG4Lab;
     47  bool fIGeant4Trajectory;
    3748  SoSeparator* fSeparator;
    3849  SoCoordinate3* fCoordinate;
  • snovis/trunk/source/G4Lab/TrajectoryContainerAccessor.h

    r233 r288  
    77namespace Slash {namespace Core {class ISession;}}
    88
     9class G4RunManager;
     10
    911namespace G4Lab {
    1012
     
    1315  virtual std::string name() const;
    1416  virtual Slash::Data::IIterator* iterator();
     17  virtual Slash::Core::IValue* findValue(Slash::Data::IAccessor::Data,const std::string&,void*);
    1518public: //Slash::Data::IVisualizer
    1619  virtual void beginVisualize();
     
    1821  virtual void endVisualize();
    1922public:
    20   TrajectoryContainerAccessor(Slash::Core::ISession&);
     23  TrajectoryContainerAccessor(Slash::Core::ISession&,G4RunManager*);
    2124  virtual ~TrajectoryContainerAccessor();
    2225private:
    2326  std::string fType;
     27  G4RunManager* fRunManager;
    2428};
    2529
  • snovis/trunk/source/G4Lab/Version.h

    r233 r288  
    33
    44#define G4LAB_MAJOR_VERSION 8
    5 #define G4LAB_MINOR_VERSION 0
     5#define G4LAB_MINOR_VERSION 1
    66#define G4LAB_PATCH_VERSION 0
    7 #define G4LAB_VERSION "8.0.0"
    8 #define G4LAB_VERSION_VRP "v8r0p0"
     7#define G4LAB_VERSION "8.1.0"
     8#define G4LAB_VERSION_VRP "v8r1p0"
    99
    1010#endif
  • snovis/trunk/source/G4Lab/cxx/DigitsCollectionAccessor.cxx

    r233 r288  
    4747G4Lab::DigitsCollectionBaseAccessor::DigitsCollectionBaseAccessor(
    4848 Slash::Core::ISession& aSession
     49,G4RunManager* aRunManager
    4950,const std::string& aDC
    5051)
    5152:OnX::InventorAccessor(aSession)
    5253,fType("DC")
     54,fRunManager(aRunManager)
    5355,fAttDefs(0)
    5456,fDC(aDC)
     
    277279//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    278280{
    279   G4RunManager* runManager = G4RunManager::GetRunManager();
    280   if(!runManager) {
     281  if(!fRunManager) {
    281282    Lib::Out out(aPrinter);
    282283    out << "No G4RunManager." << Lib::endl;
    283284    return 0;
    284285  }
    285   const G4Event* event = runManager->GetCurrentEvent();
     286  const G4Event* event = fRunManager->GetCurrentEvent();
    286287  if(!event) {
    287288    Lib::Out out(aPrinter);
  • snovis/trunk/source/G4Lab/cxx/HitsCollectionAccessor.cxx

    r233 r288  
    4444G4Lab::HitsCollectionAccessor::HitsCollectionAccessor(
    4545 Slash::Core::ISession& aSession
     46,G4RunManager* aRunManager
    4647,const std::string& aHC
    4748)
    4849:OnX::InventorAccessor(aSession)
    4950,fType("HC")
     51,fRunManager(aRunManager)
    5052,fAttDefs(0)
    5153,fHC(aHC)
     
    341343//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    342344{
    343   G4RunManager* runManager = G4RunManager::GetRunManager();
    344   if(!runManager) {
     345  if(!fRunManager) {
    345346    Lib::Out out(aPrinter);
    346347    out << "No G4RunManager." << Lib::endl;
    347348    return 0;
    348349  }
    349   const G4Event* event = runManager->GetCurrentEvent();
     350  const G4Event* event = fRunManager->GetCurrentEvent();
    350351  if(!event) {
    351352    Lib::Out out(aPrinter);
  • snovis/trunk/source/G4Lab/cxx/Manager.cxx

    r233 r288  
    174174  } else {
    175175    if(!accessorManager->findAccessor("PV")) {
     176      if(!fRunManager) {
     177        Lib::Out out(fSession.printer());
     178        out << "G4Lab::Manager::initialize :"
     179            << " no G4RunManager."
     180            << Lib::endl;   
     181      }
     182
    176183      accessorManager->addAccessor(new PhysicalVolumeAccessor(fSession));
    177       accessorManager->addAccessor(new TrajectoryContainerAccessor(fSession));
    178       accessorManager->addAccessor(new TrajectoryAccessor(fSession));
    179       accessorManager->addAccessor(new PhysicsTableAccessor(fSession,aida));
     184      accessorManager->addAccessor
     185        (new TrajectoryContainerAccessor(fSession,fRunManager));
     186      accessorManager->addAccessor
     187        (new TrajectoryAccessor(fSession,fRunManager));
     188      accessorManager->addAccessor
     189        (new PhysicsTableAccessor(fSession,*this,aida));
    180190
    181191      // Declare HitsCollections types :
     
    200210                G4String hcName = hcTable->GetHCname(index);
    201211                accessorManager->addAccessor
    202                   (new HitsCollectionAccessor(fSession,hcName));
     212                  (new HitsCollectionAccessor(fSession,fRunManager,hcName));
    203213                if(fSession.verboseLevel()) {
    204214                  Lib::Out out(fSession.printer());
     
    214224
    215225      //Declare the generic HitsCollection type :
    216       accessorManager->addAccessor(new HitsCollectionAccessor(fSession));
     226      accessorManager->addAccessor
     227        (new HitsCollectionAccessor(fSession,fRunManager));
    217228
    218229      // Should be initialized once after Inventor and HEPVis :
  • snovis/trunk/source/G4Lab/cxx/PhysicsTableAccessor.cxx

    r233 r288  
    2424#include <Slash/Data/IIterator.h>
    2525#include <Lib/Out.h>
     26#include <Lib/sout.h>
    2627#include <Lib/Value.h>
    2728#include <Lib/smanip.h>
    2829#include <Lib/fmanip.h>
    2930#include <Lib/dirmanip.h>
     31#include <Lib/Cast.h>
    3032#include <Lib/Debug.h>
    3133
     
    3941#include <AIDA/IFunctionFactory.h>
    4042#include <AIDA/IFunction.h>
     43
     44// G4Lab :
     45#include <G4Lab/Interfaces/IGeant4Manager.h>
    4146
    4247namespace G4Lab {
     
    7277G4Lab::PhysicsTableAccessor::PhysicsTableAccessor(
    7378 Slash::Core::ISession& aSession
     79,IGeant4Manager& aManager
    7480,AIDA::IAnalysisFactory* aAIDA
    7581)
    7682:Lib::BaseAccessor(aSession.printer())
    7783,fSession(aSession)
     84,fManager(aManager)
    7885,fType("PhysicsTable")
    7986,fAIDA(aAIDA)
     
    94101{
    95102  for(unsigned int index=0;index<fTables.size();index++) delete fTables[index];
     103}
     104//////////////////////////////////////////////////////////////////////////////
     105void* G4Lab::PhysicsTableAccessor::cast(
     106 const std::string& aClass
     107) const
     108//////////////////////////////////////////////////////////////////////////////
     109//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     110{
     111  if_Lib_SCast(Slash::Data::IVisualizer)
     112  else return Lib::BaseAccessor::cast(aClass);
    96113}
    97114//////////////////////////////////////////////////////////////////////////////
     
    129146//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    130147{
    131   if(!fTables.size() ) {
    132     G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
    133     if(particleTable) {
    134       G4ParticleTable::G4PTblDicIterator* particleTableIterator =
    135         particleTable->GetIterator();
    136       if(particleTableIterator) {
    137         particleTableIterator->reset();
    138         while( (*particleTableIterator)() ){
    139           G4ParticleDefinition* particle = particleTableIterator->value();
    140           if(particle) {
    141             G4String particleName = particle->GetParticleName();
    142             //Lib::Out out(fSession.printer());
    143             //out << "debug : Particle : " << particleName << Lib::endl;
    144             // Processes for this particle :
    145             G4ProcessManager* processManager = particle->GetProcessManager();
    146             if(processManager) {
    147               G4ProcessVector* processList = processManager->GetProcessList();
    148               if(processList) {
    149                 int number = processList->entries();
    150                 for (int index=0;index<number;index++){
    151                   G4VProcess* process = (*processList)(index);
    152                   std::vector<std::string> names;
    153                   std::vector<G4PhysicsTable*> tables;
    154                   if(findProcessTables(particle,
    155                                        process,
    156                                        names,
    157                                        tables)) {
    158                     for(unsigned int i=0;i<tables.size();i++) {
    159                       std::vector<std::string> words;
    160                       Lib::smanip::words(names[i],".",words);
    161                       if(words.size()==3) {
    162                         fTables.push_back(new PhysicsTable(words[0],
    163                                                            words[1],
    164                                                            words[2],
    165                                                            tables[i],
    166                                                            process,
    167                                                            particle));
    168                       }
    169                     }
    170                   }
    171                 }
    172               }
    173             }
    174           }
    175         }
    176       }
    177     }
    178   }
    179 
     148  if(!fTables.size()) {
     149    if(!buildProcessTables()) return 0;
     150  }
    180151  return new PhysicsTableIterator(fTables);
    181152}
     
    277248    G4PhysicsVector* physicsVector = (*(obj->fTable))[count];
    278249    size_t n = physicsVector->GetVectorLength();
    279     if(n>=2) {
    280       std::string name;
    281       Lib::smanip::printf(name,1024,"%s.%s.%s.%d",
    282                     obj->fTableName.c_str(),
    283                     obj->fProcessName.c_str(),
    284                     obj->fParticleName.c_str(),
    285                     count);
    286       std::vector<double> params;
    287       params.push_back(1); // Dimension of the grid (here one).
    288       params.push_back(n); // Number of entries for first grid axis.
    289       size_t i;
    290       for (i=0;i<n;i++) params.push_back(i); // Xs.
    291       for (i=0;i<n;i++) params.push_back((*physicsVector)[i]); //Values.
    292       AIDA::IFunction* function =
    293         functionFactory->createFunctionByName(name,"Grid1D");
    294       if(!function) {
    295         Lib::Out out(fSession.printer());
    296         out << "Can't create \"" << name << "\" function." << Lib::endl;
    297         break;
    298       }
    299       function->setParameters(params);
     250    if(n<2) {
     251      Lib::Out out(fSession.printer());
     252      out << "PhysicsVector with " << int(n) << " entries. Can't plot."
     253          << Lib::endl;
     254      continue;
     255    }
     256
     257    std::string name;
     258    Lib::smanip::printf(name,1024,"%s.%s.%s.%d",
     259                  obj->fTableName.c_str(),
     260                  obj->fProcessName.c_str(),
     261                  obj->fParticleName.c_str(),
     262                  count);
     263    std::vector<double> params;
     264    params.push_back(1); // Dimension of the grid (here one).
     265    params.push_back(n); // Number of entries for first grid axis.
     266    size_t i;
     267    for (i=0;i<n;i++) params.push_back(i); // Xs.
     268    for (i=0;i<n;i++) params.push_back((*physicsVector)[i]); //Values.
     269    AIDA::IFunction* function =
     270      functionFactory->createFunctionByName(name,"Grid1D");
     271    if(!function) {
     272      Lib::Out out(fSession.printer());
     273      out << "Can't create \"" << name << "\" function." << Lib::endl;
     274      break;
     275    }
     276    function->setParameters(params);
    300277     
    301       AIDA::IPlotterRegion& region = plotter->currentRegion();
    302 
    303       region.plot(*function);
    304       region.setParameter("plotter.xAxisAutomated","FALSE");
    305       std::string value1;
    306       Lib::smanip::printf(value1,32,"%g",0.);
    307       region.setParameter("plotter.xAxisMinimum",value1);
    308       std::string value2;
    309       Lib::smanip::printf(value2,32,"%g",(double)(n-1));
    310       region.setParameter("plotter.xAxisMaximum",value2);
    311       std::string value3;
    312       Lib::smanip::printf(value3,32,"%d",4 * n);
    313       region.setParameter("plotter.xNumberOfPoints",value3);
    314       /*
    315       fSession.out().println("debug : min : %s, max : %s, steps : %s\n.",
    316                              value1.c_str(),value2.c_str(),value3.c_str());
    317       */
    318 
    319       if(!superpose) plotter->next();
     278    AIDA::IPlotterRegion& region = plotter->currentRegion();
     279
     280    region.plot(*function);
     281    region.setParameter("plotter.xAxisAutomated","FALSE");
     282    std::string value1;
     283    Lib::smanip::printf(value1,32,"%g",0.);
     284    region.setParameter("plotter.xAxisMinimum",value1);
     285    std::string value2;
     286    Lib::smanip::printf(value2,32,"%g",(double)(n-1));
     287    region.setParameter("plotter.xAxisMaximum",value2);
     288    //std::string value3;
     289    //Lib::smanip::printf(value3,32,"%d",4 * n);
     290    //region.setParameter("plotter.xNumberOfPoints",value3);
     291    /*
     292    fSession.out().println("debug : min : %s, max : %s, steps : %s\n.",
     293                           value1.c_str(),value2.c_str(),value3.c_str());
     294    */
     295    if(!superpose) plotter->next();
    320296     
    321     }
    322297  }
    323298 
     
    335310}
    336311//////////////////////////////////////////////////////////////////////////////
     312bool G4Lab::PhysicsTableAccessor::buildProcessTables(
     313)
     314//////////////////////////////////////////////////////////////////////////////
     315//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     316{
     317  if(fTables.size()) return true; //done.
     318
     319  if(!fManager.isRunning()) {
     320    Lib::Out out(fSession.printer());
     321    out << "G4Lab::PhysicsTableAccessor::buildProcessTables :"
     322        << " It is needed to have started a run to get physics tables."
     323        << Lib::endl;
     324    return false;
     325  }
     326
     327  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
     328  if(!particleTable) {
     329    Lib::Out out(fSession.printer());
     330    out << "G4Lab::PhysicsTableAccessor::buildProcessTables :"
     331        << " Can't get particle table."
     332        << Lib::endl;
     333    return false;
     334  }
     335
     336  G4ParticleTable::G4PTblDicIterator* particleTableIterator =
     337    particleTable->GetIterator();
     338  if(!particleTableIterator) {
     339    Lib::Out out(fSession.printer());
     340    out << "G4Lab::PhysicsTableAccessor::buildProcessTables :"
     341        << " Can't get particle table iterator."
     342        << Lib::endl;
     343    return false;
     344  }
     345
     346  particleTableIterator->reset();
     347  while( (*particleTableIterator)() ){
     348    G4ParticleDefinition* particle = particleTableIterator->value();
     349    if(!particle) {
     350      Lib::Out out(fSession.printer());
     351      out << "G4Lab::PhysicsTableAccessor::buildProcessTables :"
     352          << " Can't get particle table particle."
     353          << Lib::endl;
     354      return false;
     355    }
     356    G4String particleName = particle->GetParticleName();
     357    //Lib::Out out(fSession.printer());
     358    //out << "debug : Particle : " << particleName << Lib::endl;
     359
     360    // Processes for this particle :
     361    G4ProcessManager* processManager = particle->GetProcessManager();
     362    if(!processManager) {
     363      Lib::Out out(fSession.printer());
     364      out << "G4Lab::PhysicsTableAccessor::buildProcessTables :"
     365          << " Can't get process manager of particle "
     366          << particleName << "."
     367          << Lib::endl;
     368      return false;
     369    }
     370
     371    G4ProcessVector* processList = processManager->GetProcessList();
     372    if(!processList) {
     373      Lib::Out out(fSession.printer());
     374      out << "G4Lab::PhysicsTableAccessor::buildProcessTables :"
     375          << " Can't get process list for process manager of particle "
     376          << particleName << "."
     377          << Lib::endl;
     378      return false;
     379    }
     380
     381    int number = processList->entries();
     382    for (int index=0;index<number;index++){
     383      G4VProcess* process = (*processList)(index);
     384      std::vector<std::string> names;
     385      std::vector<G4PhysicsTable*> tables;
     386      if(!findProcessTables(particle,process,names,tables)) {
     387        return false;
     388      }
     389
     390      for(unsigned int i=0;i<tables.size();i++) {
     391        std::vector<std::string> words;
     392        Lib::smanip::words(names[i],".",words);
     393        if(words.size()!=3) {
     394          Lib::Out out(fSession.printer());
     395          out << "G4Lab::PhysicsTableAccessor::buildProcessTables :"
     396              << " Three words separted with a dot expected in "
     397              << names[i] << " for particle " << particleName << "."
     398              << Lib::endl;
     399          return false;
     400        }
     401        fTables.push_back(new PhysicsTable(words[0],
     402                                           words[1],
     403                                           words[2],
     404                                           tables[i],
     405                                           process,
     406                                           particle));
     407      }
     408    }
     409  }
     410
     411  return true;
     412}
     413//////////////////////////////////////////////////////////////////////////////
    337414bool G4Lab::PhysicsTableAccessor::findProcessTables(
    338415 G4ParticleDefinition* aParticle
     
    364441#else
    365442  G4bool ascii = false;
     443  //G4bool ascii = true;
    366444#endif
    367   aProcess->StorePhysicsTable(aParticle,tmpName,ascii);
    368 
    369   // Analyse the content of the directory :
    370   std::vector<std::string> files;
    371   if(!Lib::dirmanip::entries(tmpName,files,false)) {
    372     Lib::Out out(fSession.printer());
    373     out << "Can't get files in \"" << tmpName << "\" directory." << Lib::endl;
     445
     446  if(!aProcess->StorePhysicsTable(aParticle,tmpName,ascii)) {
     447    Lib::Out out(fSession.printer());
     448    out << "Can't store physics table for particle "
     449        << aParticle->GetParticleName()
     450        << " and process " << aProcess->GetProcessName() << "."
     451        << Lib::endl;
     452    //return false;
    374453  } else {
    375     // Analyse files :
    376     Lib::smanip::remove(files,".");
    377     Lib::smanip::remove(files,"..");
    378     for(unsigned int index=0;index<files.size();index++) {
    379       std::vector<std::string> words;
    380       Lib::smanip::words(files[index],".",words);
    381       //Lib::Out out(fSession.printer());
    382       //out << "debug : Analyse \"" << files[index] << "\" ." << Lib::endl;
    383       if(words.size()==4) {
     454
     455    // Analyse the content of the directory :
     456    std::vector<std::string> files;
     457    if(!Lib::dirmanip::entries(tmpName,files,false)) {
     458      Lib::Out out(fSession.printer());
     459      out << "Can't get files in \"" << tmpName << "\" directory."
     460          << Lib::endl;
     461    } else {
     462      // Analyse files :
     463      Lib::smanip::remove(files,".");
     464      Lib::smanip::remove(files,"..");
     465/*
     466      if(!files.size()) {
     467        Lib::Out out(fSession.printer());
     468        out << "No files in \"" << tmpName << "\" directory for particle "
     469            << aParticle->GetParticleName()
     470            << " and process " << aProcess->GetProcessName() << "."
     471            << Lib::endl;
     472        //return false;
     473      }
     474*/
     475      for(unsigned int index=0;index<files.size();index++) {
     476        std::vector<std::string> words;
     477        Lib::smanip::words(files[index],".",words);
     478        //Lib::Out out(fSession.printer());
     479        //out << "debug : Analyse \"" << files[index] << "\" ." << Lib::endl;
     480        if(words.size()!=4) {
     481          Lib::Out out(fSession.printer());
     482          out << "Bad syntax in file name " << Lib::sout(files[index])
     483              << " for particle " << aParticle->GetParticleName()
     484              << " and process " << aProcess->GetProcessName() << "."
     485              << Lib::endl;
     486          //aTables.clear();
     487          //aPhysicsTables.clear();
     488          //return false;
     489          continue;
     490        }
    384491        std::string table = words[0];
    385492        std::string process = words[1];
     
    393500        G4PhysicsTable* physicsTable =
    394501          new G4PhysicsTable(G4Element::GetNumberOfElements());
    395         if(physicsTable) {
    396           G4bool status = physicsTable->RetrievePhysicsTable(filename,ascii);
    397           if(!status){
    398             Lib::Out out(fSession.printer());
    399             out << "Unable to read \"" << filename << "\" file." << Lib::endl;
    400             delete physicsTable;
    401             physicsTable = 0;
    402           }
     502        G4bool status = physicsTable->RetrievePhysicsTable(filename,ascii);
     503        if(!status){
     504          Lib::Out out(fSession.printer());
     505          out << "Unable to read \"" << filename << "\" file." << Lib::endl;
     506          delete physicsTable;
     507          physicsTable = 0;
    403508        }
    404509        if(physicsTable) {
     
    408513      }
    409514    }
     515
    410516  }
    411517
  • snovis/trunk/source/G4Lab/cxx/SoG4RunManager.cxx

    r233 r288  
    2727SoG4RunManager::SoG4RunManager(
    2828)
     29:fRunManager(0)
     30//////////////////////////////////////////////////////////////////////////////
     31//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     32{
     33  SO_NODE_CONSTRUCTOR(SoG4RunManager);
     34  SO_NODE_ADD_FIELD(numberOfEvents,(1));
     35}
     36//////////////////////////////////////////////////////////////////////////////
     37SoG4RunManager::SoG4RunManager(
     38 G4RunManager* aRunManager
     39)
     40:fRunManager(aRunManager)
    2941//////////////////////////////////////////////////////////////////////////////
    3042//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     
    4759//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    4860{
    49   G4RunManager* runManager = G4RunManager::GetRunManager();
    50   if(!runManager) return;
     61  if(!fRunManager) return;
    5162
    5263  G4Lab::SteppingAction* g4LabSteppingAction = 0;
    5364
    5465  G4UserSteppingAction* steppingAction =
    55     (G4UserSteppingAction*)runManager->GetUserSteppingAction();
     66    (G4UserSteppingAction*)fRunManager->GetUserSteppingAction();
    5667  if(steppingAction) {
    5768    g4LabSteppingAction = dynamic_cast<G4Lab::SteppingAction*>(steppingAction);
     
    6879  mb.sendFirst();
    6980
    70   runManager->BeamOn(numberOfEvents.getValue());
     81  fRunManager->BeamOn(numberOfEvents.getValue());
    7182
    7283  if(g4LabSteppingAction) g4LabSteppingAction->disable();
  • snovis/trunk/source/G4Lab/cxx/SoG4Trajectories.cxx

    r233 r288  
    2323// Geant4 :
    2424#include <G4RunManager.hh>
    25 #include <G4Trajectory.hh>
    2625
    2726// G4Lab :
     
    4746SoG4Trajectories::SoG4Trajectories(
    4847)
    49 :fContainer(0)
     48:fRunManager(0)
     49,fContainer(0)
    5050,fSensor(0)
    5151//////////////////////////////////////////////////////////////////////////////
     
    7878}
    7979//////////////////////////////////////////////////////////////////////////////
     80SoG4Trajectories::SoG4Trajectories(
     81 G4RunManager* aRunManager
     82)
     83:fRunManager(aRunManager)
     84,fContainer(0)
     85,fSensor(0)
     86//////////////////////////////////////////////////////////////////////////////
     87//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     88{
     89  SO_NODE_CONSTRUCTOR(SoG4Trajectories);
     90  SO_NODE_ADD_FIELD(model,(ALL));
     91  SO_NODE_ADD_FIELD(timeStart,(0));
     92  SO_NODE_ADD_FIELD(timeInterval,(0.05F));
     93  SO_NODE_ADD_FIELD(timeSteps,(100));
     94  SO_NODE_ADD_FIELD(timeIndex,(0));
     95
     96  SO_NODE_ADD_FIELD(timeMin,(0));
     97  SO_NODE_ADD_FIELD(timeMax,(0));
     98  SO_NODE_ADD_FIELD(verbose,(FALSE));
     99 
     100  SO_NODE_ADD_FIELD(alternateRep,(NULL));
     101
     102  SO_NODE_DEFINE_ENUM_VALUE(Model,ALL);
     103  SO_NODE_DEFINE_ENUM_VALUE(Model,TIMED);
     104 
     105  SO_NODE_SET_SF_ENUM_TYPE(model,Model);
     106
     107  fSensor = new SoFieldSensor(sensorCB,this);
     108  fSensor->attach(&timeInterval);
     109
     110  timeSteps.addAuditor(&timeInterval,SoNotRec::FIELD);
     111  timeStart.addAuditor(&timeInterval,SoNotRec::FIELD);
     112
     113}
     114//////////////////////////////////////////////////////////////////////////////
    80115SoG4Trajectories::~SoG4Trajectories(
    81116)
     
    94129//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    95130{
    96   G4RunManager* runManager = G4RunManager::GetRunManager();
    97   if(!runManager) return;
    98   const G4Event* event = runManager->GetCurrentEvent();
     131  if(!fRunManager) return;
     132  const G4Event* event = fRunManager->GetCurrentEvent();
    99133  if(!event) return;
    100134  G4TrajectoryContainer* trajectoryContainer = event->GetTrajectoryContainer();
     
    146180          int itraj = ids[i].fTrajectory;
    147181          int ipoint = ids[i].fPoint;
    148           G4Trajectory* trajectory =
    149             (G4Trajectory*)(*trajectoryContainer)[(size_t)itraj];
     182          G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)itraj];
    150183          int pointn = trajectory->GetPointEntries();
    151184          if( (pointn==1) || (ipoint==pointn-1) ) {
    152             G4TrajectoryPoint* tp =
    153               (G4TrajectoryPoint*)(trajectory->GetPoint(ipoint));
     185            G4VTrajectoryPoint* tp = trajectory->GetPoint(ipoint);
    154186            G4ThreeVector pos = tp->GetPosition();
    155187            glVertex3d(pos.x(),pos.y(),pos.z());
     
    163195          int itraj = ids[i].fTrajectory;
    164196          int ipoint = ids[i].fPoint;
    165           G4Trajectory* trajectory =
    166             (G4Trajectory*)(*trajectoryContainer)[(size_t)itraj];
     197          G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)itraj];
    167198          int pointn = trajectory->GetPointEntries();
    168199          if( (pointn==1) || (ipoint==pointn-1) ) {
    169200          } else {
    170             G4TrajectoryPoint* tp =
    171               (G4TrajectoryPoint*)(trajectory->GetPoint(ipoint));
     201            G4VTrajectoryPoint* tp = trajectory->GetPoint(ipoint);
    172202            G4ThreeVector pos = tp->GetPosition();
    173203            glVertex3d(pos.x(),pos.y(),pos.z());
    174             tp = (G4TrajectoryPoint*)(trajectory->GetPoint(ipoint+1));
     204            tp = trajectory->GetPoint(ipoint+1);
    175205            pos = tp->GetPosition();
    176206            glVertex3d(pos.x(),pos.y(),pos.z());
     
    185215    int number = trajectoryContainer->entries();
    186216    for(int index=0;index<number;index++) {
    187       G4Trajectory* trajectory =
    188         (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
     217      G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
    189218      int pointn = trajectory->GetPointEntries();
    190219      if(pointn==1) {
    191220        glBegin(GL_POINTS);
    192         G4TrajectoryPoint* tp = (G4TrajectoryPoint*)(trajectory->GetPoint(0));
     221        G4VTrajectoryPoint* tp = trajectory->GetPoint(0);
    193222        G4ThreeVector pos = tp->GetPosition();
    194223        glVertex3d(pos.x(),pos.y(),pos.z());
     
    197226        glBegin(GL_LINE_STRIP);
    198227        for (int i = 0; i < pointn ; i++) {
    199           G4TrajectoryPoint* tp =
    200             (G4TrajectoryPoint*)(trajectory->GetPoint(i));
     228          G4VTrajectoryPoint* tp = trajectory->GetPoint(i);
    201229          G4ThreeVector pos = tp->GetPosition();
    202230          glVertex3d(pos.x(),pos.y(),pos.z());
     
    224252  aAction->setObjectSpace();
    225253
    226   G4RunManager* runManager = G4RunManager::GetRunManager();
    227   if(runManager) {
    228     const G4Event* event = runManager->GetCurrentEvent();
     254  if(fRunManager) {
     255    const G4Event* event = fRunManager->GetCurrentEvent();
    229256    if(event) {
    230257      G4TrajectoryContainer* trajectoryContainer =
     
    233260        int number = trajectoryContainer->entries();
    234261        for(int index=0;index<number;index++) {
    235           G4Trajectory* trajectory =
    236             (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
     262          G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
    237263          int pointn = trajectory->GetPointEntries();
    238264          if(!pointn) continue;
    239           G4TrajectoryPoint* tp =
    240             (G4TrajectoryPoint*)(trajectory->GetPoint(0));
     265          G4VTrajectoryPoint* tp = trajectory->GetPoint(0);
    241266          G4ThreeVector pos = tp->GetPosition();
    242267          SbVec3f v0;
    243268          v0.setValue((float)pos.x(),(float)pos.y(),(float)pos.z());
    244269          for (int i = 1; i < pointn ; i++) {
    245             tp = (G4TrajectoryPoint*)(trajectory->GetPoint(i));
     270            tp = trajectory->GetPoint(i);
    246271            pos = tp->GetPosition();
    247272            SbVec3f v1((float)pos.x(),(float)pos.y(),(float)pos.z());
     
    271296//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    272297{
    273   G4RunManager* runManager = G4RunManager::GetRunManager();
    274   if(runManager) {
    275     const G4Event* event = runManager->GetCurrentEvent();
     298  if(fRunManager) {
     299    const G4Event* event = fRunManager->GetCurrentEvent();
    276300    if(event) {
    277301      G4TrajectoryContainer* trajectoryContainer =
     
    287311        bool first = true;
    288312        for(int index=0;index<number;index++) {
    289           G4Trajectory* trajectory =
    290             (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
     313          G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
    291314          int pointn = trajectory->GetPointEntries();
    292315          for (int i = 0; i < pointn ; i++) {
    293             G4TrajectoryPoint* tp =
    294               (G4TrajectoryPoint*)(trajectory->GetPoint(i));
     316            G4VTrajectoryPoint* tp = trajectory->GetPoint(i);
    295317            G4ThreeVector pos = tp->GetPosition();
    296318            if(first) {
     
    336358}
    337359//////////////////////////////////////////////////////////////////////////////
    338 bool SoG4Trajectories::isG4LabTrajectories(
    339  G4TrajectoryContainer* aContainer
    340 )
    341 //////////////////////////////////////////////////////////////////////////////
    342 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    343 {
    344   if(!aContainer) return false;
    345 
    346   int number = aContainer->entries();
    347   if(number<=0) return false;
    348 
    349   // Check if G4Trajectory is a G4Lab::Trajectory :
    350   G4Lab::Trajectory* trajectory =
    351     dynamic_cast<G4Lab::Trajectory*>((G4Trajectory*)(*aContainer)[(size_t)0]);
    352 
    353   return (trajectory ? true : false);
    354 }
    355 //////////////////////////////////////////////////////////////////////////////
    356360void SoG4Trajectories::timeOrder(
    357361 G4TrajectoryContainer* aContainer
     
    366370
    367371  if(!aContainer) return;
    368 
    369   if(!isG4LabTrajectories(aContainer)) return;
    370372
    371373  int number = aContainer->entries();
     
    377379  int numberOfPoints = 0;
    378380  for(int index=0;index<number;index++) {
    379     G4Lab::Trajectory* trajectory =
    380       (G4Lab::Trajectory*)(*aContainer)[(size_t)index];
    381     int pointn = trajectory->GetPointEntries();
    382     for (int i = 0; i < pointn ; i++) {
    383       double globalTime = trajectory->GetPointGlobalTime(i);
     381    IGeant4Trajectory* trajectory =
     382      dynamic_cast<IGeant4Trajectory*>((*aContainer)[(size_t)index]);
     383    if(!trajectory) {
     384      fTimeOrderedPoints.clear();
     385      return;
     386    }
     387    unsigned int pointn = trajectory->pointEntries();
     388    for (unsigned int i = 0; i < pointn ; i++) {
     389      double globalTime = trajectory->pointGlobalTime(i);
    384390      if(numberOfPoints==0) {
    385391        minTime = globalTime;
     
    392398    }
    393399  }   
     400
     401
     402
    394403  SbBool flag = enableNotify(FALSE);
    395404  timeMin.setValue((float)minTime);
     
    409418      double tmax = tmin + deltaTime;
    410419      for(int index=0;index<number;index++) {
    411         G4Lab::Trajectory* trajectory =
    412           (G4Lab::Trajectory*)(*aContainer)[(size_t)index];
    413         int pointn = trajectory->GetPointEntries();
    414         for (int i = 0; i < pointn ; i++) {
    415           double globalTime = trajectory->GetPointGlobalTime(i);
     420        IGeant4Trajectory* trajectory =
     421          dynamic_cast<IGeant4Trajectory*>((*aContainer)[(size_t)index]);
     422        unsigned int pointn = trajectory->pointEntries();
     423        for (unsigned int i = 0; i < pointn ; i++) {
     424          double globalTime = trajectory->pointGlobalTime(i);
    416425          if((tmin<=globalTime) && (globalTime<tmax)) {
    417426            ids.push_back(PointIdentifier(index,i));
     
    446455//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    447456{
    448   G4RunManager* runManager = G4RunManager::GetRunManager();
    449   if(!runManager) return;
    450   const G4Event* event = runManager->GetCurrentEvent();
     457  SoG4Trajectories* This = (SoG4Trajectories*)aData;
     458
     459  if(!This->fRunManager) return;
     460  const G4Event* event = This->fRunManager->GetCurrentEvent();
    451461  if(!event) return;
     462
    452463  G4TrajectoryContainer* trajectoryContainer =
    453464    event->GetTrajectoryContainer();
    454465  if(!trajectoryContainer) return;
    455 
    456   SoG4Trajectories* This = (SoG4Trajectories*)aData;
    457466
    458467  This->timeOrder(trajectoryContainer);
     
    470479//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    471480{
    472   G4RunManager* runManager = G4RunManager::GetRunManager();
    473   if(!runManager) return;
    474   const G4Event* event = runManager->GetCurrentEvent();
     481  if(!fRunManager) return;
     482  const G4Event* event = fRunManager->GetCurrentEvent();
    475483  if(!event) return;
    476484  G4TrajectoryContainer* trajectoryContainer = event->GetTrajectoryContainer();
     
    480488  int number = trajectoryContainer->entries();
    481489  for(int index=0;index<number;index++) {
    482     G4Trajectory* trajectory =
    483       (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
     490    G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
    484491    int pointn = trajectory->GetPointEntries();
    485492    if(pointn>=1) {
    486493      SbVec3f* points = new SbVec3f[pointn];
    487494      for (int i = 0; i < pointn ; i++) {
    488         G4TrajectoryPoint* tp =
    489           (G4TrajectoryPoint*)(trajectory->GetPoint(i));
     495        G4VTrajectoryPoint* tp = trajectory->GetPoint(i);
    490496        G4ThreeVector pos = tp->GetPosition();
    491497        points[i].setValue((float)pos.x(),(float)pos.y(),(float)pos.z());
     
    513519 {int number = trajectoryContainer->entries();
    514520  for(int index=0;index<number;index++) {
    515     G4Trajectory* trajectory =
    516       (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
     521    G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
    517522    int pointn = trajectory->GetPointEntries();
    518523    if(pointn>=1) {
     
    531536  int number = trajectoryContainer->entries();
    532537  for(int index=0;index<number;index++) {
    533     G4Trajectory* trajectory =
    534       (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
     538    G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
    535539    int pointn = trajectory->GetPointEntries();
    536540    if(pointn>=1) {
    537541      for (int i = 0; i < pointn ; i++) {
    538         G4TrajectoryPoint* tp =
    539           (G4TrajectoryPoint*)(trajectory->GetPoint(i));
     542        G4VTrajectoryPoint* tp = trajectory->GetPoint(i);
    540543        G4ThreeVector pos = tp->GetPosition();
    541544        points[ipoint].setValue((float)pos.x(),(float)pos.y(),(float)pos.z());
  • snovis/trunk/source/G4Lab/cxx/Trajectory.cxx

    r233 r288  
    88// Geant4 :
    99#include <G4Track.hh>
     10#include <G4VProcess.hh>
    1011
    1112static G4Allocator<G4Lab::Trajectory> sTrajectoryAllocator; // Beurk.
     
    3132)
    3233:G4Trajectory(aTrack)
     34,fProcess(0)
     35,fSave(false)
     36,fStoppingVolume(0)
    3337//////////////////////////////////////////////////////////////////////////////
    3438//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     
    3741  fTotalEnergy = aTrack->GetTotalEnergy();
    3842  fGlobalTime = aTrack->GetGlobalTime();
     43  fProcess = aTrack->GetCreatorProcess();
     44
     45  fStoppingPoint  = aTrack->GetPosition();
     46  fStoppingVolume = aTrack->GetVolume();
     47
    3948  /*
    4049  printf("debug : G4Lab::Trajectory : \"%s\", kineticEnergy : %g, totalEnergy : %g, globalTime : %g\n",
     
    4756     aTrack->GetGlobalTime());
    4857  fPoints.push_back(tp);
     58
    4959}
    5060//////////////////////////////////////////////////////////////////////////////
    5161G4Lab::Trajectory::Trajectory(
    52  Trajectory& aRight
    53 )
    54 :G4Trajectory(aRight)
    55 //////////////////////////////////////////////////////////////////////////////
    56 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    57 {
    58   fKineticEnergy = aRight.fKineticEnergy;
    59   fTotalEnergy = aRight.fTotalEnergy;
    60   fGlobalTime = aRight.fGlobalTime;
    61 
    62   size_t number = aRight.fPoints.size();
     62 Trajectory& aFrom
     63)
     64:G4Trajectory(aFrom)
     65//,IGeant4Trajectory(aFrom)
     66//////////////////////////////////////////////////////////////////////////////
     67//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     68{
     69  fKineticEnergy = aFrom.fKineticEnergy;
     70  fTotalEnergy = aFrom.fTotalEnergy;
     71  fGlobalTime = aFrom.fGlobalTime;
     72  fProcess = aFrom.fProcess;
     73  fSave = aFrom.fSave;
     74
     75  size_t number = aFrom.fPoints.size();
    6376  for(size_t index=0;index<number;index++) {
    64     G4TrajectoryPoint* point = aRight.fPoints[index]->point();
     77    G4TrajectoryPoint* point = aFrom.fPoints[index]->point();
    6578    TrajectoryPoint* tp =
    66       new TrajectoryPoint(new G4TrajectoryPoint(*point),aRight.fGlobalTime);
     79      new TrajectoryPoint(new G4TrajectoryPoint(*point),aFrom.fGlobalTime);
    6780    fPoints.push_back(tp);
    6881  }
     
    8295}
    8396//////////////////////////////////////////////////////////////////////////////
    84 G4double G4Lab::Trajectory::GetKineticEnergy(
     97//////////////////////////////////////////////////////////////////////////////
     98//////////////////////////////////////////////////////////////////////////////
     99//////////////////////////////////////////////////////////////////////////////
     100double G4Lab::Trajectory::kineticEnergy(
    85101) const
    86102//////////////////////////////////////////////////////////////////////////////
     
    90106}
    91107//////////////////////////////////////////////////////////////////////////////
    92 G4double G4Lab::Trajectory::GetTotalEnergy(
     108double G4Lab::Trajectory::totalEnergy(
    93109) const
    94110//////////////////////////////////////////////////////////////////////////////
     
    98114}
    99115//////////////////////////////////////////////////////////////////////////////
    100 G4double G4Lab::Trajectory::GetGlobalTime(
     116double G4Lab::Trajectory::globalTime(
    101117) const
    102118//////////////////////////////////////////////////////////////////////////////
     
    106122}
    107123//////////////////////////////////////////////////////////////////////////////
    108 /*inline*/ void* G4Lab::Trajectory::operator new(
     124unsigned int G4Lab::Trajectory::pointEntries(
     125) const
     126//////////////////////////////////////////////////////////////////////////////
     127//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     128{
     129  return fPoints.size();
     130}
     131//////////////////////////////////////////////////////////////////////////////
     132double G4Lab::Trajectory::pointGlobalTime(
     133 unsigned int aIndex
     134) const
     135//////////////////////////////////////////////////////////////////////////////
     136//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     137{
     138  return fPoints[aIndex]->globalTime();
     139}
     140//////////////////////////////////////////////////////////////////////////////
     141std::string G4Lab::Trajectory::creatorProcessName(
     142) const
     143//////////////////////////////////////////////////////////////////////////////
     144//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     145{
     146  if(!fProcess) return "";
     147  return fProcess->GetProcessName();
     148}
     149//////////////////////////////////////////////////////////////////////////////
     150std::string G4Lab::Trajectory::creatorProcessType(
     151) const
     152//////////////////////////////////////////////////////////////////////////////
     153//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     154{
     155  if(!fProcess) return "NotDefined";
     156  switch(fProcess->GetProcessType()){
     157  case fNotDefined: return "NotDefined";
     158  case fTransportation: return "Transportation";
     159  case fElectromagnetic: return "Electromagnetic";
     160  case fOptical: return "Optical";
     161  case fHadronic: return "Hadronic";
     162  case fPhotolepton_hadron: return "Photolepton_hadron";
     163  case fDecay: return "Decay";
     164  case fGeneral: return "General";
     165  case fParameterisation: return "Parameterisation";
     166  case fUserDefined: return "UserDefined";
     167  };
     168  return "NotDefined";
     169}
     170//////////////////////////////////////////////////////////////////////////////
     171void G4Lab::Trajectory::setSave(
     172 bool aFlag
     173)
     174//////////////////////////////////////////////////////////////////////////////
     175//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     176{
     177  fSave = aFlag;
     178}
     179//////////////////////////////////////////////////////////////////////////////
     180bool G4Lab::Trajectory::save(
     181) const
     182//////////////////////////////////////////////////////////////////////////////
     183//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     184{
     185  return fSave;
     186}
     187//////////////////////////////////////////////////////////////////////////////
     188std::vector<double> G4Lab::Trajectory::stoppingPoint(
     189) const
     190//////////////////////////////////////////////////////////////////////////////
     191//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     192{
     193  std::vector<double> v(3);
     194  v[0] = fStoppingPoint.x();
     195  v[1] = fStoppingPoint.y();
     196  v[2] = fStoppingPoint.z();
     197  return v;
     198}
     199//////////////////////////////////////////////////////////////////////////////
     200G4VPhysicalVolume* G4Lab::Trajectory::stoppingPhysicalVolume(
     201) const
     202//////////////////////////////////////////////////////////////////////////////
     203//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     204{
     205  return fStoppingVolume;
     206}
     207//////////////////////////////////////////////////////////////////////////////
     208//////////////////////////////////////////////////////////////////////////////
     209//////////////////////////////////////////////////////////////////////////////
     210void* G4Lab::Trajectory::operator new(
    109211 size_t
    110212
     
    115217}
    116218//////////////////////////////////////////////////////////////////////////////
    117 /*inline*/ void G4Lab::Trajectory::operator delete(
     219void G4Lab::Trajectory::operator delete(
    118220 void* aTrajectory
    119221)
     
    124226}
    125227//////////////////////////////////////////////////////////////////////////////
    126 /*inline*/ int G4Lab::Trajectory::operator == (
     228int G4Lab::Trajectory::operator == (
    127229 const G4Lab::Trajectory& aRight
    128230) const
     
    177279{
    178280  return fPoints[aIndex]->point();
    179 }
    180 //////////////////////////////////////////////////////////////////////////////
    181 G4double G4Lab::Trajectory::GetPointGlobalTime(
    182  G4int aIndex
    183 ) const
    184 //////////////////////////////////////////////////////////////////////////////
    185 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    186 {
    187   return fPoints[aIndex]->globalTime();
    188281}
    189282//////////////////////////////////////////////////////////////////////////////
     
    205298  tj->fPoints.clear();
    206299}
     300//////////////////////////////////////////////////////////////////////////////
     301const std::map<G4String,G4AttDef>* G4Lab::Trajectory::GetAttDefs() const
     302//////////////////////////////////////////////////////////////////////////////
     303//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     304{
     305  //return G4Trajectory::GetAttDefs();
     306  return 0;
     307}
     308//////////////////////////////////////////////////////////////////////////////
     309std::vector<G4AttValue>* G4Lab::Trajectory::CreateAttValues() const
     310//////////////////////////////////////////////////////////////////////////////
     311//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     312{
     313  //return G4Trajectory::CreateAttValues();
     314  return 0;
     315}
     316
  • snovis/trunk/source/G4Lab/cxx/TrajectoryAccessor.cxx

    r233 r288  
    2020// Geant4 :
    2121#include <G4RunManager.hh>
     22#include <G4VTrajectoryPoint.hh>
     23#include <G4AttValue.hh>
     24#include <G4UnitsTable.hh>
    2225
    2326// Slash :
     
    3033#include <Lib/Value.h>
    3134#include <Lib/smanip.h>
     35#include <Lib/sout.h>
    3236
    3337// G4Lab :
    34 #include <G4Lab/Trajectory.h>
     38#include <G4Lab/Interfaces/IGeant4Trajectory.h>
    3539#include <G4Lab/SoG4Trajectories.h>
     40#include <G4Lab/BestUnit.h>
    3641
    3742//////////////////////////////////////////////////////////////////////////////
    3843G4Lab::TrajectoryAccessor::TrajectoryAccessor(
    3944 Slash::Core::ISession& aSession
     45,G4RunManager* aRunManager
    4046)
    4147:OnX::InventorAccessor(aSession)
    4248,fType("Trajectory")
     49,fRunManager(aRunManager)
     50,fAttDefs(0)
    4351,fModeling("immediate_all")
    44 ,fG4Lab(false)
     52,fIGeant4Trajectory(false)
    4553,fSeparator(0)
    4654,fCoordinate(0)
     
    93101//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    94102{
    95   // Set properties here since a user G4Trajectory may
     103  // Set properties here since a user G4VTrajectory may
    96104  // had been declared very lately.
    97105  clearProperties();
    98   // G4Trajectory properties :
     106  // G4VTrajectory properties :
    99107  addProperty("particle",Lib::Property::STRING);
    100108  addProperty("track",Lib::Property::INTEGER);
    101109  addProperty("parent",Lib::Property::INTEGER);
    102110  addProperty("charge",Lib::Property::DOUBLE);
    103   if(isG4LabTrajectory()) {
     111  addProperty("pdg",Lib::Property::INTEGER);
     112  addProperty("px",Lib::Property::DOUBLE);
     113  addProperty("py",Lib::Property::DOUBLE);
     114  addProperty("pz",Lib::Property::DOUBLE);
     115
     116  fIGeant4Trajectory = isIGeant4Trajectory();
     117  if(fIGeant4Trajectory) {
    104118    // G4Lab::Trajectory properties :
    105119    addProperty("energy",Lib::Property::DOUBLE);
    106120    addProperty("totalEnergy",Lib::Property::DOUBLE);
    107121    addProperty("globalTime",Lib::Property::DOUBLE);
     122    addProperty("process",Lib::Property::STRING);
     123    addProperty("stopX",Lib::Property::DOUBLE);
     124    addProperty("stopY",Lib::Property::DOUBLE);
     125    addProperty("stopZ",Lib::Property::DOUBLE);
     126    addProperty("stopPV",Lib::Property::STRING);
    108127  }
    109128  //addProperty("id",Lib::Property::POINTER);
    110 
    111   G4RunManager* runManager = G4RunManager::GetRunManager();
    112   if(!runManager) return 0;
    113   const G4Event* event = runManager->GetCurrentEvent();
     129  addAttDefsProperties();
     130
     131  if(!fRunManager) {
     132    Lib::Out out(fSession.printer());
     133    out << "No G4RunManager." << Lib::endl;
     134    return 0;
     135  }
     136  const G4Event* event = fRunManager->GetCurrentEvent();
    114137  if(!event) {
    115138    Lib::Out out(fSession.printer());
     
    125148  }
    126149
    127   fG4Lab = isG4LabTrajectory();
    128 
    129150  return new TrajectoryIterator(*trajectoryContainer);
    130151}
     
    133154 Slash::Data::IAccessor::Data aData
    134155,const std::string& aName
    135 ,void*
    136 )
    137 //////////////////////////////////////////////////////////////////////////////
    138 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    139 {
    140   G4Trajectory* obj = (G4Trajectory*)aData;
     156,void* aTag
     157)
     158//////////////////////////////////////////////////////////////////////////////
     159//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     160{
     161  G4VTrajectory* obj = (G4VTrajectory*)aData;
     162  IGeant4Trajectory* iobj = dynamic_cast<IGeant4Trajectory*>(obj);
     163
    141164  //if(aName=="id") {
    142165    //return new Lib::Value((void*)obj);
    143166  //} else
     167  // G4VTrajectory data :
    144168  if(aName=="particle") {
    145169    return new Lib::Value(obj->GetParticleName());
     
    150174  } else if(aName=="charge") {
    151175    return new Lib::Value(obj->GetCharge());
    152   } else if(!fG4Lab) {
    153     return new Lib::Value();
    154   } else { // We have G4Lab::Trajectory objects :
    155     G4Lab::Trajectory* obj = (G4Lab::Trajectory*)aData;
     176  } else if(aName=="pdg") {
     177    return new Lib::Value(obj->GetPDGEncoding());
     178  } else if(aName=="px") {
     179    return new Lib::Value(obj->GetInitialMomentum().x());
     180  } else if(aName=="py") {
     181    return new Lib::Value(obj->GetInitialMomentum().y());
     182  } else if(aName=="pz") {
     183    return new Lib::Value(obj->GetInitialMomentum().z());
     184  } else if(iobj) {
    156185    if(aName=="energy") {
    157       return new Lib::Value(obj->GetKineticEnergy());
     186      return new Lib::Value(iobj->kineticEnergy());
    158187    } else if(aName=="totalEnergy") {
    159       return new Lib::Value(obj->GetTotalEnergy());
     188      return new Lib::Value(iobj->totalEnergy());
    160189    } else if(aName=="globalTime") {
    161       return new Lib::Value(obj->GetGlobalTime());
    162     } else {
    163       return new Lib::Value();
    164     }
    165   }
     190      return new Lib::Value(iobj->globalTime());
     191    } else if(aName=="process") {
     192      return new Lib::Value(iobj->creatorProcessName());
     193    } else if(aName=="stopX") {
     194      return new Lib::Value(iobj->stoppingPoint()[0]);
     195    } else if(aName=="stopY") {
     196      return new Lib::Value(iobj->stoppingPoint()[1]);
     197    } else if(aName=="stopZ") {
     198      return new Lib::Value(iobj->stoppingPoint()[2]);
     199    } else if(aName=="stopPV") {
     200      G4VPhysicalVolume* pv = iobj->stoppingPhysicalVolume();
     201      if(!pv) return new Lib::Value();
     202      return new Lib::Value(pv->GetName());
     203    }
     204  }
     205  return findAttDefsValue(aData,aName,aTag);
    166206}
    167207//////////////////////////////////////////////////////////////////////////////
     
    197237    separator->addChild(fSoGC.getLightModel());
    198238
    199     SoG4Trajectories* soG4Trajectories = new SoG4Trajectories;
     239    SoG4Trajectories* soG4Trajectories = new SoG4Trajectories(fRunManager);
    200240    separator->addChild(soG4Trajectories);
    201241
     
    233273  if(!fSeparator) return; // not in "pickable" mode.
    234274
    235   G4Trajectory* obj = (G4Trajectory*)aData;
     275  G4VTrajectory* obj = (G4VTrajectory*)aData;
    236276  if(!obj) return;
    237277
     
    242282  int32_t* coordIndex = new int32_t[pointn+1];
    243283
    244   G4TrajectoryPoint* tp;
    245   G4ThreeVector pos;
    246284  for (int i = 0; i < pointn ; i++) {
    247     tp = (G4TrajectoryPoint*)(obj->GetPoint(i)); //?
    248     pos = tp->GetPosition();
     285    G4VTrajectoryPoint* tp = obj->GetPoint(i); //?
     286    G4ThreeVector pos = tp->GetPosition();
    249287    points[i].setValue((float)pos.x(),(float)pos.y(),(float)pos.z());
    250288    coordIndex[i] = fIndex+i;
     
    307345}
    308346//////////////////////////////////////////////////////////////////////////////
    309 bool G4Lab::TrajectoryAccessor::isG4LabTrajectory(
     347bool G4Lab::TrajectoryAccessor::isIGeant4Trajectory(
    310348)
    311349//////////////////////////////////////////////////////////////////////////////
    312350//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    313351{
    314   G4RunManager* runManager = G4RunManager::GetRunManager();
    315   if(!runManager) return false;
    316   const G4Event* event = runManager->GetCurrentEvent();
     352  if(!fRunManager) return false;
     353  const G4Event* event = fRunManager->GetCurrentEvent();
    317354  if(!event) return false;
    318355  G4TrajectoryContainer* trajectoryContainer =
     
    321358  int number = trajectoryContainer->entries();
    322359  if(number<=0) return false;
    323   G4Lab::Trajectory* trajectory =
    324     dynamic_cast<G4Lab::Trajectory*>((G4Trajectory*)(*trajectoryContainer)[(size_t)0]);
     360  G4VTrajectory* vt = (*trajectoryContainer)[(size_t)0];
     361  IGeant4Trajectory* trajectory = dynamic_cast<IGeant4Trajectory*>(vt);
    325362  return (trajectory?true:false);
    326363}
     364//////////////////////////////////////////////////////////////////////////////
     365void G4Lab::TrajectoryAccessor::addAttDefsProperties(
     366)
     367//////////////////////////////////////////////////////////////////////////////
     368//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     369{
     370  fAttDefs = 0;
     371  if(!fRunManager) return;
     372  const G4Event* event = fRunManager->GetCurrentEvent();
     373  if(!event) return;
     374  G4TrajectoryContainer* trajectoryContainer =
     375    event->GetTrajectoryContainer();
     376  if(!trajectoryContainer) return;
     377  int number = trajectoryContainer->entries();
     378  if(number<=0) return;
     379  G4VTrajectory* vt = (*trajectoryContainer)[(size_t)0];
     380
     381  // AttDefs properties :
     382  fAttDefs = (std::map<G4String,G4AttDef>*)vt->GetAttDefs();
     383  if(!fAttDefs) return;
     384
     385  std::map<G4String,G4AttDef>::const_iterator it;
     386  for(it=fAttDefs->begin();it!=fAttDefs->end();++it) {
     387    const std::string& sname = (*it).second.GetName();
     388    const std::string& stype = (*it).second.GetValueType();   
     389
     390    if(sname=="Color") continue; //Do not put some AttDef as property.
     391
     392    //printf("debug : add %s %s\n",sname.c_str(),stype.c_str());
     393
     394    if( (stype=="int")   ||
     395        (stype=="G4int") ) {
     396      addProperty((*it).first,Lib::Property::INTEGER);
     397    } else if( (stype=="double")   ||
     398               (stype=="float")    ||
     399               (stype=="G4double") ||
     400               (stype=="G4float")  ) {
     401      addProperty((*it).first,Lib::Property::DOUBLE);
     402    } else if( (stype=="std::string")   ||
     403               (stype=="G4String")  ) {
     404      addProperty((*it).first,Lib::Property::STRING);
     405    } else if( (stype=="std::vector<double>")   ||
     406               (stype=="std::vector<float>")    ||
     407               (stype=="G4ThreeVector")         ||
     408               (stype=="std::vector<G4double>") ||
     409               (stype=="std::vector<G4float>")  ) {
     410      addProperty((*it).first,Lib::Property::VECTOR_DOUBLE);
     411    } else {
     412      addProperty((*it).first,Lib::Property::STRING);
     413    }
     414  }
     415}
     416//////////////////////////////////////////////////////////////////////////////
     417Slash::Core::IValue* G4Lab::TrajectoryAccessor::findAttDefsValue(
     418 Slash::Data::IAccessor::Data aData
     419,const std::string& aName
     420,void*
     421)
     422//////////////////////////////////////////////////////////////////////////////
     423//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     424{
     425  //printf("debug : find %s (%ld)...\n",aName.c_str(),fAttDefs);
     426
     427  if(!fAttDefs) return new Lib::Value();
     428
     429  G4VTrajectory* obj = (G4VTrajectory*)aData;
     430  std::vector<G4AttValue>* vec = obj->CreateAttValues();
     431  if(!vec) {
     432    Lib::Out out(printer());
     433    out << "G4Lab::TrajectoryAccessor::findAttDefsValue :"
     434        << " problem to get AttValues fot trajectory."
     435        << Lib::endl;
     436    return new Lib::Value();
     437  }
     438 
     439  unsigned int number = vec->size();
     440  for(unsigned int index=0;index<number;index++) {
     441    const G4AttValue& val = (*vec)[index];
     442    if(aName==val.GetName()) {
     443      const std::string& stype = (*fAttDefs)[val.GetName()].GetValueType();
     444      if( (stype=="int")   ||
     445          (stype=="G4int") ) {
     446        int v;
     447        if(!Lib::smanip::toint(val.GetValue(),v)) {
     448          Lib::Out out(printer());
     449          out << "G4Lab::TrajectoryAccessor::findAttDefsValue :"
     450              << " " << Lib::sout(val.GetValue()) << " not a G4int."
     451              << Lib::endl;
     452          delete vec;
     453          return new Lib::Value();
     454        }
     455        delete vec;
     456        return new Lib::Value(v);
     457      } else if( (stype=="double")   ||
     458                 (stype=="float")    ||
     459                 (stype=="G4double") ||
     460                 (stype=="G4float")  ) {
     461        double v = 0;
     462        if(!Lib::smanip::todouble(val.GetValue(),v)) {
     463          std::vector<double> vs;
     464          if(!BestUnit::toDoubles(printer(),val.GetValue(),vs)) {
     465            delete vec;
     466            return new Lib::Value();
     467          }
     468          if(vs.size()!=1) {
     469            Lib::Out out(printer());
     470            out << "G4Lab::TrajectoryAccessor::findAttDefsValue :"
     471                << " " << Lib::sout(val.GetValue()) << " not a double."
     472                << Lib::endl;
     473            delete vec;
     474            return new Lib::Value();
     475          }
     476          v = vs[0];
     477        }
     478        delete vec;
     479        return new Lib::Value(v);
     480      } else if( (stype=="std::string")   ||
     481                 (stype=="G4String")  ) {
     482        delete vec;
     483        return new Lib::Value(val.GetValue());
     484      } else if(stype=="G4ThreeVector") {
     485        std::vector<double> vs;
     486        if(!BestUnit::toDoubles(printer(),val.GetValue(),vs)) {
     487          delete vec;
     488          return new Lib::Value();
     489        }
     490        if(vs.size()!=3) {
     491          Lib::Out out(printer());
     492          out << "G4Lab::TrajectoryAccessor::findAttDefsValue :"
     493              << " " << Lib::sout(val.GetValue()) << " not a vector."
     494              << Lib::endl;
     495          delete vec;
     496          return new Lib::Value();
     497        }
     498        delete vec;
     499        return new Lib::Value(vs);
     500      } else if( (stype=="std::vector<float>")    ||
     501                 (stype=="std::vector<G4float>")  ) {
     502        void* p;
     503        if(!Lib::smanip::topointer(val.GetValue(),p)) {
     504          Lib::Out out(printer());
     505          out << "G4Lab::TrajectoryAccessor::findAttDefsValue :"
     506              << " " << Lib::sout(val.GetValue()) << " not a pointer."
     507              << Lib::endl;
     508          delete vec;
     509          return new Lib::Value();
     510        }
     511        std::vector<float>* vvec = (std::vector<float>*)p;
     512        unsigned int vn = vvec->size();
     513        std::vector<double> array(vn);
     514        for(unsigned int vi=0;vi<vn;vi++) array[vi] = double((*vvec)[vi]);
     515        delete vec;
     516        return new Lib::Value(array);
     517      } else if( (stype=="std::vector<double>")   ||
     518                 (stype=="std::vector<G4double>") ){
     519        void* p;
     520        if(!Lib::smanip::topointer(val.GetValue(),p)) {
     521          Lib::Out out(printer());
     522          out << "G4Lab::TrajectoryAccessor::findAttDefsValue :"
     523              << " " << Lib::sout(val.GetValue()) << " not a pointer."
     524              << Lib::endl;
     525          delete vec;
     526          return new Lib::Value();
     527        }
     528        std::vector<double>* vvec = (std::vector<double>*)p;
     529        delete vec;
     530        return new Lib::Value(*vvec);
     531      } else {
     532        delete vec;
     533        return new Lib::Value(val.GetValue());
     534      }
     535    }
     536  }
     537  Lib::Out out(printer());
     538  out << "G4Lab::TrajectoryAccessor::findAttDefsValue :"
     539      << " AttValue not found for property " << Lib::sout(aName) << "."
     540      << Lib::endl;
     541  delete vec;
     542  return new Lib::Value();
     543}
  • snovis/trunk/source/G4Lab/cxx/TrajectoryContainerAccessor.cxx

    r233 r288  
    2727G4Lab::TrajectoryContainerAccessor::TrajectoryContainerAccessor(
    2828 Slash::Core::ISession& aSession
     29,G4RunManager* aRunManager
    2930)
    3031:OnX::InventorAccessor(aSession)
    3132,fType("TrajectoryContainer")
     33,fRunManager(aRunManager)
    3234//////////////////////////////////////////////////////////////////////////////
    3335//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     
    7173}
    7274//////////////////////////////////////////////////////////////////////////////
     75Slash::Core::IValue* G4Lab::TrajectoryContainerAccessor::findValue(
     76 Slash::Data::IAccessor::Data aData
     77,const std::string& aName
     78,void* aTag
     79)
     80//////////////////////////////////////////////////////////////////////////////
     81//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
     82{
     83  return 0;
     84}
     85//////////////////////////////////////////////////////////////////////////////
    7386void G4Lab::TrajectoryContainerAccessor::beginVisualize(
    7487)
     
    102115    separator->addChild(fSoGC.getLightModel());
    103116
    104     SoG4RunManager* soG4RunManager = new SoG4RunManager();
     117    SoG4RunManager* soG4RunManager = new SoG4RunManager(fRunManager);
    105118    soG4RunManager->numberOfEvents.setValue(number);
    106119    separator->addChild(soG4RunManager);
Note: See TracChangeset for help on using the changeset viewer.