Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OrderedTable Class Reference

#include <G4OrderedTable.hh>

Inheritance diagram for G4OrderedTable:
Collaboration diagram for G4OrderedTable:

Public Member Functions

 G4OrderedTable ()
 
 G4OrderedTable (size_t cap)
 
virtual ~G4OrderedTable ()
 
void clearAndDestroy ()
 
G4bool Store (const G4String &filename, G4bool ascii=false)
 
G4bool Retrieve (const G4String &filename, G4bool ascii=false)
 

Friends

std::ostream & operator<< (std::ostream &out, G4OrderedTable &table)
 

Detailed Description

Definition at line 57 of file G4OrderedTable.hh.

Constructor & Destructor Documentation

G4OrderedTable::G4OrderedTable ( )

Definition at line 43 of file G4OrderedTable.cc.

44  : std::vector<G4DataVector*>()
45 {
46 }
G4OrderedTable::G4OrderedTable ( size_t  cap)
explicit

Definition at line 48 of file G4OrderedTable.cc.

49  : std::vector<G4DataVector*>(cap, (G4DataVector*)(0) )
50 {
51 }
G4OrderedTable::~G4OrderedTable ( )
virtual

Definition at line 53 of file G4OrderedTable.cc.

54 {
55 }

Member Function Documentation

void G4OrderedTable::clearAndDestroy ( )
inline

Definition at line 90 of file G4OrderedTable.hh.

91 {
92  G4DataVector* a = 0;
93  while (size()>0)
94  {
95  a = back();
96  pop_back();
97  for (iterator i=begin(); i!=end(); i++)
98  {
99  if (*i==a)
100  {
101  erase(i);
102  i--;
103  }
104  }
105  if ( a ) { delete a; }
106  }
107 }
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33

Here is the caller graph for this function:

G4bool G4OrderedTable::Retrieve ( const G4String filename,
G4bool  ascii = false 
)

Definition at line 110 of file G4OrderedTable.cc.

112 {
113  std::ifstream fIn;
114  // open input file //
115  if (ascii)
116  { fIn.open(fileName,std::ios::in|std::ios::binary); }
117  else
118  { fIn.open(fileName,std::ios::in); }
119 
120  // check if the file has been opened successfully
121  if (!fIn)
122  {
123 #ifdef G4VERBOSE
124  G4cerr << "G4OrderedTable::Retrieve():";
125  G4cerr << " Cannot open file: " << fileName << G4endl;
126 #endif
127  fIn.close();
128  return false;
129  }
130 
131  // clear
132  clearAndDestroy();
133 
134  // Number of elements
135  G4int tableSize=0;
136  if (!ascii)
137  {
138  fIn.read((char*)(&tableSize), sizeof tableSize);
139  }
140  else
141  {
142  fIn >> tableSize;
143  }
144  if (tableSize<=0)
145  {
146 #ifdef G4VERBOSE
147  G4cerr << "G4OrderedTable::Retrieve():";
148  G4cerr << " Invalid table size: " << tableSize << G4endl;
149 #endif
150  return false;
151  }
152  reserve(tableSize);
153 
154  // Physics Vector
155  for (G4int idx=0; idx<tableSize; ++idx)
156  {
157  G4int vType=0;
158  if (!ascii)
159  {
160  fIn.read( (char*)(&vType), sizeof vType);
161  }
162  else
163  {
164  fIn >> vType;
165  }
166  if (vType != G4DataVector::T_G4DataVector)
167  {
168 #ifdef G4VERBOSE
169  G4cerr << "G4OrderedTable::Retrieve():";
170  G4cerr << " Illegal Data Vector type: " << vType << " in ";
171  G4cerr << fileName << G4endl;
172 #endif
173  fIn.close();
174  return false;
175  }
176 
177  G4DataVector* pVec = new G4DataVector;
178 
179  if (! (pVec->Retrieve(fIn,ascii)) )
180  {
181 #ifdef G4VERBOSE
182  G4cerr << "G4OrderedTable::Retrieve(): ";
183  G4cerr << " Rrror in retreiving " << idx
184  << "-th Physics Vector from file: ";
185  G4cerr << fileName << G4endl;
186 #endif
187  fIn.close();
188  delete pVec;
189  return false;
190  }
191 
192  // add a PhysicsVector to this OrderedTable
193  push_back(pVec);
194  }
195  fIn.close();
196  return true;
197 }
void clearAndDestroy()
int G4int
Definition: G4Types.hh:78
G4bool Retrieve(std::ifstream &fIn, G4bool ascii=false)
Definition: G4DataVector.cc:86
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

G4bool G4OrderedTable::Store ( const G4String filename,
G4bool  ascii = false 
)

Definition at line 57 of file G4OrderedTable.cc.

59 {
60  std::ofstream fOut;
61 
62  // open output file //
63  if (!ascii)
64  { fOut.open(fileName, std::ios::out|std::ios::binary); }
65  else
66  { fOut.open(fileName, std::ios::out); }
67 
68  // check if the file has been opened successfully
69  if (!fOut)
70  {
71 #ifdef G4VERBOSE
72  G4cerr << "G4OrderedTable::::Store():";
73  G4cerr << " Cannot open file: " << fileName << G4endl;
74 #endif
75  fOut.close();
76  return false;
77  }
78 
79  // Number of elements
80  size_t tableSize = size();
81  if (!ascii)
82  {
83  fOut.write( (char*)(&tableSize), sizeof tableSize);
84  }
85  else
86  {
87  fOut << tableSize << G4endl;
88  }
89 
90  // Data Vector
92  for (G4OrderedTableIterator itr=begin(); itr!=end(); ++itr)
93  {
94  if (!ascii)
95  {
96  fOut.write( (char*)(&vType), sizeof vType);
97  }
98  else
99  {
100  fOut << vType << G4endl;
101  }
102  (*itr)->Store(fOut,ascii);
103  }
104  fOut.close();
105  return true;
106 }
int G4int
Definition: G4Types.hh:78
G4OrderedTable::iterator G4OrderedTableIterator
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
G4OrderedTable table 
)
friend

Definition at line 199 of file G4OrderedTable.cc.

201 {
202  // Printout Data Vector
203  size_t i=0;
204  for (G4OrderedTableIterator itr=right.begin(); itr!=right.end(); ++itr)
205  {
206  out << std::setw(8) << i << "-th Vector ";
207  out << ": Type " << G4DataVector::T_G4DataVector << G4endl;
208  out << *(*itr);
209  i +=1;
210  }
211  out << G4endl;
212  return out;
213 }
G4OrderedTable::iterator G4OrderedTableIterator
#define G4endl
Definition: G4ios.hh:61

The documentation for this class was generated from the following files: