#include <user_info.hh>
Inheritance diagram for user_info:

Public Member Functions | |
| void | dump_contents () |
| Method to dump all key & value contents in the storage map on the screen This is useful to check what's in the data interactively. | |
| user_info () | |
| Default constructor. | |
| user_info (const user_info &original) | |
| Default copy constructor to avoid memory leak in ROOT streamer. | |
| void | store (std::string key, double value) |
| setter for a single double variable | |
| void | store (std::string key, int value) |
| setter for a single int variable | |
| void | store (std::string key, std::string value) |
| setter for a single std::string variable | |
| void | store (std::string key, bool value) |
| setter for a single bool variable | |
| void | append (std::string key, double value) |
| method to add double value to a double array | |
| void | append (std::string key, int value) |
| method to add int value to an int array | |
| void | append (std::string key, std::string value) |
| method to add std::string value to an std::string array | |
| void | append (std::string key, bool value) |
| method to add bool value to an bool array | |
| double | get_double (std::string key) const |
| getter for a single double variable | |
| int | get_int (std::string key) const |
| getter for a single int variable | |
| std::string | get_string (std::string key) const |
| getter for a single std::string variable | |
| bool | get_bool (std::string key) const |
| getter for a single bool variable | |
| std::vector< double > * | get_darray (std::string key) |
| getter for a double array | |
| std::vector< int > * | get_iarray (std::string key) |
| getter for an int array | |
| std::vector< std::string > * | get_sarray (std::string key) |
| getter for a std::string array | |
| std::vector< bool > * | get_barray (std::string key) |
| getter for a bool array | |
| virtual | ~user_info () |
| Default destructor. | |
| virtual void | clear_data () |
| Clear method override. | |
Protected Attributes | |
| std::map< std::string, double > | _d_map |
| var. holder map of double | |
| std::map< std::string, int > | _i_map |
| var. holder map of int | |
| std::map< std::string, std::string > | _s_map |
| var. holder map of std::string | |
| std::map< std::string, bool > | _b_map |
| var. holder map of bool | |
| std::map< std::string, std::vector< double > > | _darray_map |
| var. holder map of double array | |
| std::map< std::string, std::vector< int > > | _iarray_map |
| var. holder map of int array | |
| std::map< std::string, std::vector< std::string > > | _sarray_map |
| var. holder map of std::string array | |
| std::map< std::string, std::vector< bool > > | _barray_map |
| var. holder map of bool array | |
What we mean by "on the fly"? It means you can define variable name and store it in the data w/o defining a dedicated data container class.
The supported variable type for storage includes double, int, std::string, bool, and vector of those types. The variable is stored as a pair of a specific std::string key and value, both provided by a user. The string is then used to retrieve a variable later. Note that each retrieval requires std::string comparison, hence is somewhat expensive (i.e. takes time). But it is a matter of micro-seconds for even very large map (i.e. large map = you store a lot of variables).
See user_collection class which is actually used in event loop.
Definition at line 35 of file user_info.hh.
| user_info::user_info | ( | ) | [inline] |
Default constructor.
Definition at line 45 of file user_info.hh.
References clear_data().
00045 : data_base() { clear_data(); };
| user_info::user_info | ( | const user_info & | original | ) |
Default copy constructor to avoid memory leak in ROOT streamer.
Definition at line 6 of file user_info.cc.
00006 : 00007 data_base(original), 00008 _d_map(original._d_map), 00009 _i_map(original._i_map), 00010 _s_map(original._s_map), 00011 _b_map(original._b_map), 00012 _darray_map(original._darray_map), 00013 _iarray_map(original._iarray_map), 00014 _sarray_map(original._sarray_map), 00015 _barray_map(original._barray_map) 00016 {};
| virtual user_info::~user_info | ( | ) | [inline, virtual] |
| void user_info::append | ( | std::string | key, | |
| bool | value | |||
| ) |
method to add bool value to an bool array
Definition at line 170 of file user_info.cc.
References _barray_map.
00170 { 00171 if(_barray_map.find(key)==_barray_map.end()) 00172 _barray_map[key]=std::vector<bool>(); 00173 _barray_map[key].push_back(value); 00174 }
| void user_info::append | ( | std::string | key, | |
| std::string | value | |||
| ) |
method to add std::string value to an std::string array
Definition at line 164 of file user_info.cc.
References _sarray_map.
00164 { 00165 if(_sarray_map.find(key)==_sarray_map.end()) 00166 _sarray_map[key]=std::vector<std::string>(); 00167 _sarray_map[key].push_back(value); 00168 }
| void user_info::append | ( | std::string | key, | |
| int | value | |||
| ) |
method to add int value to an int array
Definition at line 158 of file user_info.cc.
References _iarray_map.
00158 { 00159 if(_iarray_map.find(key)==_iarray_map.end()) 00160 _iarray_map[key]=std::vector<int>(); 00161 _iarray_map[key].push_back(value); 00162 }
| void user_info::append | ( | std::string | key, | |
| double | value | |||
| ) |
method to add double value to a double array
Definition at line 152 of file user_info.cc.
References _darray_map.
00152 { 00153 if(_darray_map.find(key)==_darray_map.end()) 00154 _darray_map[key]=std::vector<double>(); 00155 _darray_map[key].push_back(value); 00156 }
| void user_info::clear_data | ( | ) | [virtual] |
Clear method override.
Reimplemented from data_base.
Definition at line 18 of file user_info.cc.
References _b_map, _barray_map, _d_map, _darray_map, _i_map, _iarray_map, _s_map, and _sarray_map.
Referenced by user_info().
00018 { 00019 _d_map.clear(); 00020 _i_map.clear(); 00021 _s_map.clear(); 00022 _b_map.clear(); 00023 _darray_map.clear(); 00024 _iarray_map.clear(); 00025 _sarray_map.clear(); 00026 _barray_map.clear(); 00027 }
| void user_info::dump_contents | ( | ) |
Method to dump all key & value contents in the storage map on the screen This is useful to check what's in the data interactively.
Definition at line 29 of file user_info.cc.
References _b_map, _barray_map, _d_map, _darray_map, _i_map, _iarray_map, _s_map, _sarray_map, MSG::NORMAL, and Message::send().
00029 { 00030 00031 Message::send(MSG::NORMAL,__FUNCTION__," Start contents dump..."); 00032 std::string msg(""); 00033 00034 if(_d_map.size()){ 00035 msg ="Contents of double variables shown below.\n"; 00036 msg+=Form(" %-20s ... Value\n","Key"); 00037 for(std::map<std::string,double>::const_iterator iter(_d_map.begin()); 00038 iter!=_d_map.end(); 00039 ++iter) 00040 msg+=Form(" %-20s ... %g\n",(*iter).first.c_str(), (*iter).second); 00041 Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str()); 00042 } 00043 00044 if(_i_map.size()){ 00045 msg ="Contents of int variables shown below.\n"; 00046 msg+=Form(" %-20s ... Value\n","Key"); 00047 for(std::map<std::string,int>::const_iterator iter(_i_map.begin()); 00048 iter!=_i_map.end(); 00049 ++iter) 00050 msg+=Form(" %-20s ... %d\n",(*iter).first.c_str(), (*iter).second); 00051 Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str()); 00052 } 00053 00054 if(_s_map.size()){ 00055 msg ="Contents of std::string variables shown below.\n"; 00056 msg+=Form(" %-20s ... Value\n","Key"); 00057 for(std::map<std::string,std::string>::const_iterator iter(_s_map.begin()); 00058 iter!=_s_map.end(); 00059 ++iter) 00060 msg+=Form(" %-20s ... %s\n",(*iter).first.c_str(), (*iter).second.c_str()); 00061 Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str()); 00062 } 00063 00064 if(_b_map.size()){ 00065 msg ="Contents of bool variables shown below.\n"; 00066 msg+=Form(" %-20s ... Value\n","Key"); 00067 for(std::map<std::string,bool>::const_iterator iter(_b_map.begin()); 00068 iter!=_b_map.end(); 00069 ++iter) 00070 msg+=Form(" %-20s ... %d\n",(*iter).first.c_str(), (int)((*iter).second)); 00071 Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str()); 00072 } 00073 00074 if(_darray_map.size()){ 00075 msg ="Contents of double array shown below.\n"; 00076 for(std::map<std::string,std::vector<double> >::const_iterator iter(_darray_map.begin()); 00077 iter!=_darray_map.end(); 00078 ++iter){ 00079 msg+=Form(" Key=%-20s\n ",(*iter).first.c_str()); 00080 int ctr=1; 00081 for(std::vector<double>::const_iterator cont_iter((*iter).second.begin()); 00082 cont_iter!=(*iter).second.end(); 00083 ++cont_iter){ 00084 msg+=Form("%g ",(*cont_iter)); 00085 ctr++; 00086 if(ctr%8==0) 00087 msg+="\n "; 00088 } 00089 } 00090 Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str()); 00091 } 00092 00093 if(_iarray_map.size()){ 00094 msg ="Contents of int array shown below.\n"; 00095 for(std::map<std::string,std::vector<int> >::const_iterator iter(_iarray_map.begin()); 00096 iter!=_iarray_map.end(); 00097 ++iter){ 00098 msg+=Form(" Key=%-20s\n ",(*iter).first.c_str()); 00099 int ctr=1; 00100 for(std::vector<int>::const_iterator cont_iter((*iter).second.begin()); 00101 cont_iter!=(*iter).second.end(); 00102 ++cont_iter){ 00103 msg+=Form("%d ",(*cont_iter)); 00104 ctr++; 00105 if(ctr%8==0) 00106 msg+="\n "; 00107 } 00108 } 00109 Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str()); 00110 } 00111 00112 if(_sarray_map.size()){ 00113 msg ="Contents of std::string array shown below.\n"; 00114 for(std::map<std::string,std::vector<std::string> >::const_iterator iter(_sarray_map.begin()); 00115 iter!=_sarray_map.end(); 00116 ++iter){ 00117 msg+=Form(" Key=%-20s\n ",(*iter).first.c_str()); 00118 int ctr=1; 00119 for(std::vector<std::string>::const_iterator cont_iter((*iter).second.begin()); 00120 cont_iter!=(*iter).second.end(); 00121 ++cont_iter){ 00122 msg+=Form("%s ",(*cont_iter).c_str()); 00123 ctr++; 00124 if(ctr%8==0) 00125 msg+="\n "; 00126 } 00127 } 00128 Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str()); 00129 } 00130 00131 if(_barray_map.size()){ 00132 msg ="Contents of bool array shown below.\n"; 00133 for(std::map<std::string,std::vector<bool> >::const_iterator iter(_barray_map.begin()); 00134 iter!=_barray_map.end(); 00135 ++iter){ 00136 msg+=Form(" Key=%-20s\n ",(*iter).first.c_str()); 00137 int ctr=1; 00138 for(std::vector<bool>::const_iterator cont_iter((*iter).second.begin()); 00139 cont_iter!=(*iter).second.end(); 00140 ++cont_iter){ 00141 msg+=Form("%d ",(int)(*cont_iter)); 00142 ctr++; 00143 if(ctr%8==0) 00144 msg+="\n "; 00145 } 00146 } 00147 Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str()); 00148 } 00149 Message::send(MSG::NORMAL,__FUNCTION__," End of dump..."); 00150 }
| std::vector< bool > * user_info::get_barray | ( | std::string | key | ) |
getter for a bool array
Definition at line 240 of file user_info.cc.
References _barray_map, MSG::ERROR, and Message::send().
00240 { 00241 std::map<std::string,std::vector<bool> >::iterator item(_barray_map.find(key)); 00242 if(item==_barray_map.end()){ 00243 Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str())); 00244 return 0; 00245 } 00246 return &((*item).second); 00247 }
| bool user_info::get_bool | ( | std::string | key | ) | const |
getter for a single bool variable
Definition at line 204 of file user_info.cc.
References _b_map, MSG::ERROR, and Message::send().
00204 { 00205 std::map<std::string,bool>::const_iterator item(_b_map.find(key)); 00206 if(item==_b_map.end()){ 00207 Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str())); 00208 return 0; 00209 } 00210 return (*item).second; 00211 }
| std::vector< double > * user_info::get_darray | ( | std::string | key | ) |
getter for a double array
Definition at line 213 of file user_info.cc.
References _darray_map, MSG::ERROR, and Message::send().
00213 { 00214 std::map<std::string,std::vector<double> >::iterator item(_darray_map.find(key)); 00215 if(item==_darray_map.end()){ 00216 Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str())); 00217 return 0; 00218 } 00219 return &((*item).second); 00220 }
| double user_info::get_double | ( | std::string | key | ) | const |
getter for a single double variable
Definition at line 176 of file user_info.cc.
References _d_map, MSG::ERROR, and Message::send().
00176 { 00177 std::map<std::string,double>::const_iterator item(_d_map.find(key)); 00178 if(item==_d_map.end()){ 00179 Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str())); 00180 return 0; 00181 } 00182 return (*item).second; 00183 }
| std::vector< int > * user_info::get_iarray | ( | std::string | key | ) |
getter for an int array
Definition at line 222 of file user_info.cc.
References _iarray_map, MSG::ERROR, and Message::send().
00222 { 00223 std::map<std::string,std::vector<int> >::iterator item(_iarray_map.find(key)); 00224 if(item==_iarray_map.end()){ 00225 Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str())); 00226 return 0; 00227 } 00228 return &((*item).second); 00229 }
| int user_info::get_int | ( | std::string | key | ) | const |
getter for a single int variable
Definition at line 185 of file user_info.cc.
References _i_map, MSG::ERROR, and Message::send().
00185 { 00186 std::map<std::string,int>::const_iterator item(_i_map.find(key)); 00187 if(item==_i_map.end()){ 00188 Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str())); 00189 return 0; 00190 } 00191 return (*item).second; 00192 }
| std::vector< std::string > * user_info::get_sarray | ( | std::string | key | ) |
getter for a std::string array
Definition at line 231 of file user_info.cc.
References _sarray_map, MSG::ERROR, and Message::send().
00231 { 00232 std::map<std::string,std::vector<std::string> >::iterator item(_sarray_map.find(key)); 00233 if(item==_sarray_map.end()){ 00234 Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str())); 00235 return 0; 00236 } 00237 return &((*item).second); 00238 }
| std::string user_info::get_string | ( | std::string | key | ) | const |
getter for a single std::string variable
Definition at line 194 of file user_info.cc.
References _s_map, MSG::ERROR, and Message::send().
00194 { 00195 std::map<std::string,std::string>::const_iterator item(_s_map.find(key)); 00196 if(item==_s_map.end()){ 00197 Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str())); 00198 return 0; 00199 } 00200 return (*item).second; 00201 }
| void user_info::store | ( | std::string | key, | |
| bool | value | |||
| ) | [inline] |
setter for a single bool variable
Definition at line 57 of file user_info.hh.
References _b_map.
00057 {_b_map[key]=value;};
| void user_info::store | ( | std::string | key, | |
| std::string | value | |||
| ) | [inline] |
setter for a single std::string variable
Definition at line 55 of file user_info.hh.
References _s_map.
00055 {_s_map[key]=value;};
| void user_info::store | ( | std::string | key, | |
| int | value | |||
| ) | [inline] |
setter for a single int variable
Definition at line 53 of file user_info.hh.
References _i_map.
00053 {_i_map[key]=value;};
| void user_info::store | ( | std::string | key, | |
| double | value | |||
| ) | [inline] |
setter for a single double variable
Definition at line 51 of file user_info.hh.
References _d_map.
00051 {_d_map[key]=value;};
std::map<std::string,bool> user_info::_b_map [protected] |
var. holder map of bool
Definition at line 97 of file user_info.hh.
Referenced by clear_data(), dump_contents(), get_bool(), and store().
std::map<std::string,std::vector<bool> > user_info::_barray_map [protected] |
var. holder map of bool array
Definition at line 101 of file user_info.hh.
Referenced by append(), clear_data(), dump_contents(), and get_barray().
std::map<std::string,double> user_info::_d_map [protected] |
var. holder map of double
Definition at line 94 of file user_info.hh.
Referenced by clear_data(), dump_contents(), get_double(), and store().
std::map<std::string,std::vector<double> > user_info::_darray_map [protected] |
var. holder map of double array
Definition at line 98 of file user_info.hh.
Referenced by append(), clear_data(), dump_contents(), and get_darray().
std::map<std::string,int> user_info::_i_map [protected] |
var. holder map of int
Definition at line 95 of file user_info.hh.
Referenced by clear_data(), dump_contents(), get_int(), and store().
std::map<std::string,std::vector<int> > user_info::_iarray_map [protected] |
var. holder map of int array
Definition at line 99 of file user_info.hh.
Referenced by append(), clear_data(), dump_contents(), and get_iarray().
std::map<std::string,std::string> user_info::_s_map [protected] |
var. holder map of std::string
Definition at line 96 of file user_info.hh.
Referenced by clear_data(), dump_contents(), get_string(), and store().
std::map<std::string,std::vector<std::string> > user_info::_sarray_map [protected] |
var. holder map of std::string array
Definition at line 100 of file user_info.hh.
Referenced by append(), clear_data(), dump_contents(), and get_sarray().
1.4.7