00001 #ifndef USER_INFO_CC
00002 #define USER_INFO_CC
00003
00004 #include "user_info.hh"
00005
00006 namespace larlight {
00007
00008
00009 user_info::user_info(DATA::DATA_TYPE type) : data_base(type)
00010
00011 {
00012 if(_type!=DATA::UserInfo) {
00013
00014 Message::send(MSG::ERROR,__FUNCTION__,
00015 Form("Provided data type (%s) not supported! Reset to default.",DATA::DATA_TREE_NAME[_type].c_str()));
00016
00017 _type=DATA::UserInfo;
00018
00019 }
00020
00021 clear_data();
00022 }
00023
00024
00025 user_info::user_info(const user_info &original) :
00026 data_base(original),
00027 _d_map(original._d_map),
00028 _i_map(original._i_map),
00029 _s_map(original._s_map),
00030 _b_map(original._b_map),
00031 _darray_map(original._darray_map),
00032 _iarray_map(original._iarray_map),
00033 _sarray_map(original._sarray_map),
00034 _barray_map(original._barray_map)
00035
00036 {};
00037
00038
00039 void user_info::clear_data()
00040
00041 {
00042 _d_map.clear();
00043 _i_map.clear();
00044 _s_map.clear();
00045 _b_map.clear();
00046 _darray_map.clear();
00047 _iarray_map.clear();
00048 _sarray_map.clear();
00049 _barray_map.clear();
00050 }
00051
00052
00053 void user_info::dump_contents()
00054
00055 {
00056
00057 Message::get()->send(MSG::NORMAL,__FUNCTION__," Start contents dump...");
00058 std::string msg("");
00059
00060 if(_d_map.size()){
00061 msg ="Contents of double variables shown below.\n";
00062 msg+=Form(" %-20s ... Value\n","Key");
00063 for(std::map<std::string,double>::const_iterator iter(_d_map.begin());
00064 iter!=_d_map.end();
00065 ++iter)
00066 msg+=Form(" %-20s ... %g\n",(*iter).first.c_str(), (*iter).second);
00067 Message::get()->send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00068 }
00069
00070 if(_i_map.size()){
00071 msg ="Contents of int variables shown below.\n";
00072 msg+=Form(" %-20s ... Value\n","Key");
00073 for(std::map<std::string,int>::const_iterator iter(_i_map.begin());
00074 iter!=_i_map.end();
00075 ++iter)
00076 msg+=Form(" %-20s ... %d\n",(*iter).first.c_str(), (*iter).second);
00077 Message::get()->send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00078 }
00079
00080 if(_s_map.size()){
00081 msg ="Contents of std::string variables shown below.\n";
00082 msg+=Form(" %-20s ... Value\n","Key");
00083 for(std::map<std::string,std::string>::const_iterator iter(_s_map.begin());
00084 iter!=_s_map.end();
00085 ++iter)
00086 msg+=Form(" %-20s ... %s\n",(*iter).first.c_str(), (*iter).second.c_str());
00087 Message::get()->send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00088 }
00089
00090 if(_b_map.size()){
00091 msg ="Contents of bool variables shown below.\n";
00092 msg+=Form(" %-20s ... Value\n","Key");
00093 for(std::map<std::string,bool>::const_iterator iter(_b_map.begin());
00094 iter!=_b_map.end();
00095 ++iter)
00096 msg+=Form(" %-20s ... %d\n",(*iter).first.c_str(), (int)((*iter).second));
00097 Message::get()->send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00098 }
00099
00100 if(_darray_map.size()){
00101 msg ="Contents of double array shown below.\n";
00102 for(std::map<std::string,std::vector<double> >::const_iterator iter(_darray_map.begin());
00103 iter!=_darray_map.end();
00104 ++iter){
00105 msg+=Form(" Key=%-20s\n ",(*iter).first.c_str());
00106 int ctr=1;
00107 for(std::vector<double>::const_iterator cont_iter((*iter).second.begin());
00108 cont_iter!=(*iter).second.end();
00109 ++cont_iter){
00110 msg+=Form("%g ",(*cont_iter));
00111 ctr++;
00112 if(ctr%8==0)
00113 msg+="\n ";
00114 }
00115 }
00116 Message::get()->send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00117 }
00118
00119 if(_iarray_map.size()){
00120 msg ="Contents of int array shown below.\n";
00121 for(std::map<std::string,std::vector<int> >::const_iterator iter(_iarray_map.begin());
00122 iter!=_iarray_map.end();
00123 ++iter){
00124 msg+=Form(" Key=%-20s\n ",(*iter).first.c_str());
00125 int ctr=1;
00126 for(std::vector<int>::const_iterator cont_iter((*iter).second.begin());
00127 cont_iter!=(*iter).second.end();
00128 ++cont_iter){
00129 msg+=Form("%d ",(*cont_iter));
00130 ctr++;
00131 if(ctr%8==0)
00132 msg+="\n ";
00133 }
00134 }
00135 Message::get()->send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00136 }
00137
00138 if(_sarray_map.size()){
00139 msg ="Contents of std::string array shown below.\n";
00140 for(std::map<std::string,std::vector<std::string> >::const_iterator iter(_sarray_map.begin());
00141 iter!=_sarray_map.end();
00142 ++iter){
00143 msg+=Form(" Key=%-20s\n ",(*iter).first.c_str());
00144 int ctr=1;
00145 for(std::vector<std::string>::const_iterator cont_iter((*iter).second.begin());
00146 cont_iter!=(*iter).second.end();
00147 ++cont_iter){
00148 msg+=Form("%s ",(*cont_iter).c_str());
00149 ctr++;
00150 if(ctr%8==0)
00151 msg+="\n ";
00152 }
00153 }
00154 Message::get()->send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00155 }
00156
00157 if(_barray_map.size()){
00158 msg ="Contents of bool array shown below.\n";
00159 for(std::map<std::string,std::vector<bool> >::const_iterator iter(_barray_map.begin());
00160 iter!=_barray_map.end();
00161 ++iter){
00162 msg+=Form(" Key=%-20s\n ",(*iter).first.c_str());
00163 int ctr=1;
00164 for(std::vector<bool>::const_iterator cont_iter((*iter).second.begin());
00165 cont_iter!=(*iter).second.end();
00166 ++cont_iter){
00167 msg+=Form("%d ",(int)(*cont_iter));
00168 ctr++;
00169 if(ctr%8==0)
00170 msg+="\n ";
00171 }
00172 }
00173 Message::get()->send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00174 }
00175 Message::get()->send(MSG::NORMAL,__FUNCTION__," End of dump...");
00176 }
00177
00178
00179 void user_info::append(std::string key, double value)
00180
00181 {
00182 if(_darray_map.find(key)==_darray_map.end())
00183 _darray_map[key]=std::vector<double>();
00184 _darray_map[key].push_back(value);
00185 }
00186
00187
00188 void user_info::append(std::string key, int value)
00189
00190 {
00191 if(_iarray_map.find(key)==_iarray_map.end())
00192 _iarray_map[key]=std::vector<int>();
00193 _iarray_map[key].push_back(value);
00194 }
00195
00196
00197 void user_info::append(std::string key, std::string value)
00198
00199 {
00200 if(_sarray_map.find(key)==_sarray_map.end())
00201 _sarray_map[key]=std::vector<std::string>();
00202 _sarray_map[key].push_back(value);
00203 }
00204
00205
00206 void user_info::append(std::string key, bool value)
00207
00208 {
00209 if(_barray_map.find(key)==_barray_map.end())
00210 _barray_map[key]=std::vector<bool>();
00211 _barray_map[key].push_back(value);
00212 }
00213
00214
00215 double user_info::get_double(std::string key) const
00216
00217 {
00218 std::map<std::string,double>::const_iterator item(_d_map.find(key));
00219 if(item==_d_map.end()){
00220 Message::get()->send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00221 return 0;
00222 }
00223 return (*item).second;
00224 }
00225
00226
00227 int user_info::get_int(std::string key) const
00228
00229 {
00230 std::map<std::string,int>::const_iterator item(_i_map.find(key));
00231 if(item==_i_map.end()){
00232 Message::get()->send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00233 return 0;
00234 }
00235 return (*item).second;
00236 }
00237
00238
00239 std::string user_info::get_string(std::string key) const
00240
00241 {
00242 std::map<std::string,std::string>::const_iterator item(_s_map.find(key));
00243 if(item==_s_map.end()){
00244 Message::get()->send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00245 return 0;
00246 }
00247 return (*item).second;
00248 }
00249
00250
00251 bool user_info::get_bool(std::string key) const
00252
00253 {
00254 std::map<std::string,bool>::const_iterator item(_b_map.find(key));
00255 if(item==_b_map.end()){
00256 Message::get()->send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00257 return 0;
00258 }
00259 return (*item).second;
00260 }
00261
00262
00263 std::vector<double>* user_info::get_darray(std::string key)
00264
00265 {
00266 std::map<std::string,std::vector<double> >::iterator item(_darray_map.find(key));
00267 if(item==_darray_map.end()){
00268 Message::get()->send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00269 return 0;
00270 }
00271 return &((*item).second);
00272 }
00273
00274
00275 std::vector<int>* user_info::get_iarray(std::string key)
00276
00277 {
00278 std::map<std::string,std::vector<int> >::iterator item(_iarray_map.find(key));
00279 if(item==_iarray_map.end()){
00280 Message::get()->send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00281 return 0;
00282 }
00283 return &((*item).second);
00284 }
00285
00286
00287 std::vector<std::string>* user_info::get_sarray(std::string key)
00288
00289 {
00290 std::map<std::string,std::vector<std::string> >::iterator item(_sarray_map.find(key));
00291 if(item==_sarray_map.end()){
00292 Message::get()->send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00293 return 0;
00294 }
00295 return &((*item).second);
00296 }
00297
00298
00299 std::vector<bool>* user_info::get_barray(std::string key)
00300
00301 {
00302 std::map<std::string,std::vector<bool> >::iterator item(_barray_map.find(key));
00303 if(item==_barray_map.end()){
00304 Message::get()->send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00305 return 0;
00306 }
00307 return &((*item).second);
00308 }
00309
00310
00311 event_user::event_user(DATA::DATA_TYPE type) : std::vector<larlight::user_info>(),
00312 event_base(type)
00313
00314 {
00315 if(_type!=DATA::UserInfo) {
00316
00317 Message::send(MSG::ERROR,__FUNCTION__,
00318 Form("Provided data type (%s) not supported! Reset to default.",DATA::DATA_TREE_NAME[_type].c_str()));
00319
00320 _type=DATA::UserInfo;
00321 }
00322
00323 clear_data();
00324 }
00325 }
00326
00327 #endif