Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DataVector Class Reference

#include <G4DataVector.hh>

+ Inheritance diagram for G4DataVector:

Public Types

enum  { T_G4DataVector = 100 }
 

Public Member Functions

 G4DataVector ()
 
 G4DataVector (size_t cap)
 
 G4DataVector (size_t cap, G4double value)
 
virtual ~G4DataVector ()
 
void insertAt (size_t, const G4double &)
 
size_t index (const G4double &)
 
G4bool contains (const G4double &) const
 
G4bool remove (const G4double &)
 
size_t removeAll (const G4double &)
 
G4bool Store (std::ofstream &fOut, G4bool ascii=false)
 
G4bool Retrieve (std::ifstream &fIn, G4bool ascii=false)
 

Friends

std::ostream & operator<< (std::ostream &, const G4DataVector &)
 

Detailed Description

Definition at line 50 of file G4DataVector.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
T_G4DataVector 

Definition at line 83 of file G4DataVector.hh.

83{T_G4DataVector = 100};

Constructor & Destructor Documentation

◆ G4DataVector() [1/3]

G4DataVector::G4DataVector ( )

Definition at line 42 of file G4DataVector.cc.

43 : std::vector<G4double>()
44{
45}

◆ G4DataVector() [2/3]

G4DataVector::G4DataVector ( size_t  cap)
explicit

Definition at line 47 of file G4DataVector.cc.

48 : std::vector<G4double>(cap, 0.0)
49{
50}

◆ G4DataVector() [3/3]

G4DataVector::G4DataVector ( size_t  cap,
G4double  value 
)

Definition at line 52 of file G4DataVector.cc.

53 : std::vector<G4double>(cap, value)
54{
55}

◆ ~G4DataVector()

G4DataVector::~G4DataVector ( )
virtual

Definition at line 57 of file G4DataVector.cc.

58{
59}

Member Function Documentation

◆ contains()

G4bool G4DataVector::contains ( const G4double ) const
inline

◆ index()

size_t G4DataVector::index ( const G4double )
inline

◆ insertAt()

void G4DataVector::insertAt ( size_t  ,
const G4double  
)
inline

◆ remove()

G4bool G4DataVector::remove ( const G4double )
inline

◆ removeAll()

size_t G4DataVector::removeAll ( const G4double )
inline

◆ Retrieve()

G4bool G4DataVector::Retrieve ( std::ifstream &  fIn,
G4bool  ascii = false 
)

Definition at line 86 of file G4DataVector.cc.

87{
88 clear();
89 G4int sizeV=0;
90
91 // retrieve in ascii mode
92 if (ascii)
93 {
94 // contents
95 fIn >> sizeV;
96 if (fIn.fail()) { return false; }
97 if (sizeV<=0)
98 {
99#ifdef G4VERBOSE
100 G4cerr << "G4DataVector::Retrieve():";
101 G4cerr << " Invalid vector size: " << sizeV << G4endl;
102#endif
103 return false;
104 }
105
106 reserve(sizeV);
107 for(G4int i = 0; i < sizeV ; i++)
108 {
109 G4double vData=0.0;
110 fIn >> vData;
111 if (fIn.fail()) { return false; }
112 push_back(vData);
113 }
114 return true ;
115 }
116
117 // retrieve in binary mode
118 fIn.read((char*)(&sizeV), sizeof sizeV);
119
120 G4double* value = new G4double[sizeV];
121 fIn.read((char*)(value), sizeV*(sizeof(G4double)) );
122 if (G4int(fIn.gcount()) != G4int(sizeV*(sizeof(G4double))) )
123 {
124 delete [] value;
125 return false;
126 }
127
128 reserve(sizeV);
129 for(G4int i = 0; i < sizeV; i++)
130 {
131 push_back(value[i]);
132 }
133 delete [] value;
134 return true;
135}
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr

Referenced by G4OrderedTable::Retrieve().

◆ Store()

G4bool G4DataVector::Store ( std::ofstream &  fOut,
G4bool  ascii = false 
)

Definition at line 61 of file G4DataVector.cc.

62{
63 // Ascii mode
64 if (ascii)
65 {
66 fOut << *this;
67 return true;
68 }
69
70 // Binary Mode
71 size_t sizeV = size();
72 fOut.write((char*)(&sizeV), sizeof sizeV);
73
74 G4double* value = new G4double[sizeV];
75 size_t i=0;
76 for (const_iterator itr=begin(); itr!=end(); itr++, i++)
77 {
78 value[i] = *itr;
79 }
80 fOut.write((char*)(value), sizeV*(sizeof (G4double)) );
81 delete [] value;
82
83 return true;
84}

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const G4DataVector pv 
)
friend

Definition at line 137 of file G4DataVector.cc.

138{
139 out << pv.size() << std::setprecision(12) << G4endl;
140 for(size_t i = 0; i < pv.size(); i++)
141 {
142 out << pv[i] << G4endl;
143 }
144 out << std::setprecision(6);
145
146 return out;
147}

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