Message: Re: Problem with XML file and long time for running? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: Problem with XML file and long time for running? 

Keywords: xml AIDA run-time
Forum: Analysis
Re: Question Problem with XML file and long time for running? (Shahrokh)
Date: 16 Mar, 2006
From: Guy Barrand <Guy Barrand>

  Hello Shahrokh

  The number one problem with the below is that you reread 
 all the file each time that you want to get something in the tuple !
 Moreover the GeneratePrimaries method does not do a "delete analysisFactory"
 so that at each event your recreate a new AIDA context !

  Below I join a corrected version of your program. 
 Mainly the tuple is read once in the constructor, and the
 GeneratePrimaries only jump at position in the in memory
 tuple to get the data.
  Since the number of particle and type is a constant, it is
 better to create the G4ParticleGun in the constructor too.

  In any case, the file format is the problem here. Your 3 Mbytes
 will be read once in the whole program. And reading 3 Mbytes 
 of XML should not be an issue. I think that you can stay with XML.

  The below should run as a swift...


#include "AIDA/AIDA.h"
#include "AIDA/IManagedObject.h"

using namespace AIDA;

#include "PrimaryGeneratorAction.hh"

#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "globals.hh"

#include "G4UnitsTable.hh"

   //GB : Have fAnalysisFactory as a field of your PrimaryGeneratoAction class.
   fAnalysisFactory = AIDA_createAnalysisFactory();

   ITreeFactory *treeFactory = analysisFactory->createTreeFactory();

   //GB : same for fTree.
   fTree = treeFactory->create("DataBaseOfPhoton.aida","xml",true, false);
   delete treeFactory;

   //GB : a local variable is sufficient.
   AIDA::IManagedObject* managedObject = tree->find("/tuples/tuplePhoton");
   // Put the below variable tuple as a field of your class.
   //GB : put fTuple as a field of the class.
   fTuple = dynamic_cast<AIDA::ITuple*> (managedObject);
   //int numberOfrows = fTuple->rows();
  //primary generator
  G4int n_particle = 1;
  //GB : create only one G4ParticleGun for the whole program.
  //     is the number of particle and kind is always the same.
  //     It will be more efficient.
  fParticleGun = new G4ParticleGun(n_particle);

  //setting type of particle
  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
  G4String particleName;
  xOfPostion = 0.0;
  yOfPostion = 0.0;
  zOfPostion = 0.0;
  xOfdirection = 0.0;
  yOfdirection = 0.0;
  zOfdirection = 0.0;
  energy = 0.0;

   delete fParticleGun;
   //delete tree;  //GB : the below delete fAnalysisFactory will do the job.
   //delete managedObject; //The same.
   delete fAnalysisFactory;

void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
   //get position of photon from DataBaseOfPhoton.aida file
   //get  movement direction of photon from DataBaseOfPhoton.aida file
   //get energy of photon from DataBaseOfPhoton.aida file
   //GB fTuple->reset();   //GB : noooooooooooooo ! It will clear all data in fTuple !
  //setting energy of photon
  G4cout << "energy of primary photon: " <<G4BestUnit( energy , "Energy" )<< G4endl;
  //setting postion of photon
  fParticleGun->SetParticlePosition(G4ThreeVector(xOfPostion*mm, yOfPostion*mm, zOfPostion*mm));
  G4cout<<"the position characteristics of primary photon: ("<<G4BestUnit( xOfPostion,"Length")<<", "<<G4BestUnit( yOfPostion,"Length")<<", "<<G4BestUnit( zOfPostion,"Length")<<" )"<<G4endl;
  //setting movement direction of photon
  G4ThreeVector v(xOfdirection, yOfdirection, zOfdirection);

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

 Add Message Add Message
to: "Re: Problem with XML file and long time for running?"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]