LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOLCParameters.cc
Go to the documentation of this file.
1 #include "SIO/SIOLCParameters.h"
2 
3 // -- sio headers
4 #include <sio/io_device.h>
5 #include <sio/version.h>
6 
7 namespace SIO {
8 
9  void SIOLCParameters::read( sio::read_device &device, EVENT::LCParameters& params, sio::version_type vers ) {
10  int nIntParameters ;
11  SIO_DATA( device , &nIntParameters , 1 ) ;
12  for(int i=0; i< nIntParameters ; i++ ) {
13  std::string key;
14  SIO_SDATA( device, key ) ;
15  int nInt ;
16  SIO_DATA( device , &nInt , 1 ) ;
17  EVENT::IntVec intVec(nInt) ;
18  for(int j=0; j< nInt ; j++ ) {
19  SIO_DATA( device , &intVec[j] , 1 ) ;
20  }
21  params.setValues( key , intVec ) ;
22  }
23  int nFloatParameters ;
24  SIO_DATA( device , &nFloatParameters , 1 ) ;
25  for(int i=0; i< nFloatParameters ; i++ ) {
26  std::string key;
27  SIO_SDATA( device, key ) ;
28  int nFloat ;
29  SIO_DATA( device , &nFloat , 1 ) ;
30  EVENT::FloatVec floatVec(nFloat) ;
31  for(int j=0; j< nFloat ; j++ ) {
32  SIO_DATA( device , &floatVec[j] , 1 ) ;
33  }
34  params.setValues( key , floatVec ) ;
35  }
36  if( vers > SIO_VERSION_ENCODE( 2, 16 ) ) {
37 
38  int nDoubleParameters ;
39  SIO_DATA( device , &nDoubleParameters , 1 ) ;
40  for(int i=0; i< nDoubleParameters ; i++ ) {
41  std::string key;
42  SIO_SDATA( device, key ) ;
43  int nDouble ;
44  SIO_DATA( device , &nDouble , 1 ) ;
45  EVENT::DoubleVec doubleVec(nDouble) ;
46  for(int j=0; j< nDouble ; j++ ) {
47  SIO_DATA( device , &doubleVec[j] , 1 ) ;
48  }
49  params.setValues( key , doubleVec ) ;
50  }
51  }
52  int nStringParameters ;
53  SIO_DATA( device , &nStringParameters , 1 ) ;
54  for(int i=0; i< nStringParameters ; i++ ) {
55  std::string key;
56  SIO_SDATA( device, key ) ;
57  int nString ;
58  SIO_DATA( device , &nString , 1 ) ;
59  EVENT::StringVec stringVec(nString) ;
60  for(int j=0; j< nString ; j++ ){
61  std::string val;
62  SIO_SDATA( device, val ) ;
63  stringVec[j] = val ;
64  }
65  params.setValues( key , stringVec ) ;
66  }
67  }
68 
69  void SIOLCParameters::write( sio::write_device &device, const EVENT::LCParameters& params ) {
70  EVENT::StringVec intKeys ;
71  int nIntParameters = params.getIntKeys( intKeys ).size() ;
72  SIO_DATA( device , &nIntParameters , 1 ) ;
73  for(int i=0; i< nIntParameters ; i++ ) {
74  EVENT::IntVec intVec ;
75  params.getIntVals( intKeys[i], intVec ) ;
76  int nInt = intVec.size() ;
77  SIO_SDATA( device, intKeys[i] ) ;
78  SIO_DATA( device , &nInt , 1 ) ;
79  for(int j=0; j< nInt ; j++ ) {
80  SIO_SDATA( device, intVec[j] ) ;
81  }
82  }
83  EVENT::StringVec floatKeys ;
84  int nFloatParameters = params.getFloatKeys( floatKeys ).size() ;
85  SIO_DATA( device , &nFloatParameters , 1 ) ;
86  for(int i=0; i< nFloatParameters ; i++ ) {
87  EVENT::FloatVec floatVec ;
88  params.getFloatVals( floatKeys[i], floatVec ) ;
89  int nFloat = floatVec.size() ; // = params.getNFloat( floatKeys[i] ) ;
90  SIO_SDATA( device, floatKeys[i] ) ;
91  SIO_DATA( device , &nFloat , 1 ) ;
92  for(int j=0; j< nFloat ; j++ ){
93  SIO_SDATA( device, floatVec[j] ) ;
94  }
95  }
96  EVENT::StringVec doubleKeys ;
97  int nDoubleParameters = params.getDoubleKeys( doubleKeys ).size() ;
98  SIO_DATA( device , &nDoubleParameters , 1 ) ;
99  for(int i=0; i< nDoubleParameters ; i++ ) {
100  EVENT::DoubleVec doubleVec ;
101  params.getDoubleVals( doubleKeys[i], doubleVec ) ;
102  int nDouble = doubleVec.size() ; // = params.getNDouble( doubleKeys[i] ) ;
103  SIO_SDATA( device, doubleKeys[i] ) ;
104  SIO_DATA( device , &nDouble , 1 ) ;
105  for(int j=0; j< nDouble ; j++ ){
106  SIO_SDATA( device, doubleVec[j] ) ;
107  }
108  }
109  EVENT::StringVec stringKeys ;
110  int nStringParameters = params.getStringKeys( stringKeys ).size() ;
111  SIO_DATA( device , &nStringParameters , 1 ) ;
112  for(int i=0; i< nStringParameters ; i++ ){
113  EVENT::StringVec stringVec ;
114  params.getStringVals( stringKeys[i], stringVec ) ;
115  int nString = stringVec.size() ;
116  SIO_SDATA( device, stringKeys[i] ) ;
117  SIO_DATA( device , &nString , 1 ) ;
118  for(int j=0; j< nString ; j++ ){
119  SIO_SDATA( device, stringVec[j] ) ;
120  }
121  }
122  }
123 
124 } // namespace
virtual DoubleVec & getDoubleVals(const std::string &key, DoubleVec &values) const =0
Adds all double values for the given key to values.
static void write(sio::write_device &device, const EVENT::LCParameters &params)
Writes lcio objects to an SIO stream.
virtual const StringVec & getIntKeys(StringVec &keys) const =0
Returns a list of all keys of integer parameters.
virtual const StringVec & getStringKeys(StringVec &keys) const =0
Returns a list of all keys of string parameters.
virtual const StringVec & getDoubleKeys(StringVec &keys) const =0
Returns a list of all keys of double parameters.
STL class.
Simple interface to store generic named parameters of type int, float and string. ...
Definition: LCParameters.h:28
virtual void setValues(const std::string &key, const IntVec &values)=0
Set integer values for the given key.
virtual const StringVec & getFloatKeys(StringVec &keys) const =0
Returns a list of all keys of float parameters.
T size(T...args)
virtual StringVec & getStringVals(const std::string &key, StringVec &values) const =0
Adds all string values for the given key to values.
static void read(sio::read_device &device, EVENT::LCParameters &params, sio::version_type vers)
Reads objects from an SIO stream.
virtual IntVec & getIntVals(const std::string &key, IntVec &values) const =0
Adds all integer values for the given key to values.
virtual FloatVec & getFloatVals(const std::string &key, FloatVec &values) const =0
Adds all float values for the given key to values.