source: trunk/source/global/management/test/OrderedTableTest.cc@ 1340

Last change on this file since 1340 was 1315, checked in by garnier, 15 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 3.6 KB
RevLine 
[1199]1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: OrderedTableTest.cc,v 1.7 2006/06/29 19:04:58 gunter Exp $
[1315]28// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
[1199]29//
30//
31// ----------------------------------------------------------------------
32//
33// This program shows how to use the G4OrderedTable.
34//
35
36#include "G4ios.hh"
37#include "G4OrderedTable.hh"
38
39int main()
40{
41 size_t I, J;
42 const size_t Imax=10;
43 G4cout.precision(3);
44
45 //
46 // Create a G4OrderedTable object
47 //
48
49 G4OrderedTable aTable(Imax);
50 G4OrderedTable::iterator pl = aTable.begin();
51
52 for(I=0; I<Imax; I++)
53 {
54 G4DataVector* aVector = new G4DataVector();
55 *pl++ = aVector;
56 for(J=0; J<=I; J++)
57 aVector->push_back(G4double(J));
58 }
59
60 // Now access the data contained in the table
61
62 for (I=0; I<Imax; I++)
63 {
64 G4cout << G4endl << G4endl << " I= " << I << " Data= ";
65 for(J=0; J<=I; J++)
66 G4cout << (*aTable[I])[J] << " ";
67 }
68
69
70 // Store in file in ascii mode
71 aTable.Store("OrdTable.asc",true) ;
72
73 // clear Ordered Table
74 aTable.clear();
75
76 // Retrieve from file
77 aTable.Retrieve("OrdTable.asc",true) ;
78
79 // Print Out
80 G4cout << G4endl << G4endl;
81 G4cout << aTable ;
82
83 //
84 // Create a G4OrderedTable object by pointer
85 //
86
87 G4OrderedTable* aTablePtr = new G4OrderedTable(Imax);
88 pl = aTablePtr->begin();
89
90 for(I=0; I<Imax; I++)
91 {
92 G4DataVector* aVector = new G4DataVector(I+1);
93 *pl++ = aVector;
94 for(J=0; J<=I; J++)
95 (*aVector)[J]= G4double(J);
96 }
97
98 // Now access the data contained in the table
99
100 for (I=0; I<Imax; I++)
101 {
102 G4cout << G4endl << G4endl << " I= " << I << " Data= ";
103 for(J=0; J<=I; J++)
104 G4cout << (*(*aTablePtr)[I])[J] << " ";
105 }
106 G4cout << G4endl;
107
108 // Store in file in binary mode
109 aTablePtr->Store("OrdTable.dat") ;
110
111 aTablePtr->clearAndDestroy();
112
113 // Retrieve from file
114 aTablePtr->Retrieve("OrdTable.dat") ;
115
116 // Print Out
117 G4cout << G4endl << G4endl;
118 G4cout << *aTablePtr ;
119
120
121 aTable.clearAndDestroy();
122 aTablePtr->clearAndDestroy();
123
124 return EXIT_SUCCESS;
125}
Note: See TracBrowser for help on using the repository browser.