cdi_test2.cxx

00001 
00009 
00010 #include <iostream>
00011 #include <vector>
00012 #include <string>
00013 #include <fstream>
00014 
00015 // Other standard C includes
00016 extern "C" {
00017 #include <unistd.h>
00018 #include <sys/wait.h>
00019 #include <sys/types.h>
00020 #include <signal.h>
00021 #include <sys/time.h>
00022 };
00023 
00024 // some cclasses needed to store data
00025 #include "ipc/core.h"
00026 #include <ipc/partition.h>
00027 #include "cdi/cdiHandle.h"
00028 
00029 // The objects to be stored
00030 //#include "rc/Conditions.h"
00031 //#include "rc/RunParams.h"
00032 
00033 #include "AuxObjs.h"
00034 
00035 
00036 
00037 // the number of data updates that must be made
00038 #define MAX_UPD 1000
00039 #define log std::cout << OWLTime()
00040 
00041 
00042 
00043 
00044 
00045 int main(int argc, char**argv){
00046   
00047   IPCCore::init(argc, argv);
00048   
00049   setenv("TEST_NAME", __FILE__ ,1);  
00050   if (argc != 2 ){
00051     log << "::cdi_test -> Time interval not defined" << std::endl;
00052     return 1;
00053   }
00054   
00055   timeval t_start, t_end;
00056   
00057   std::ofstream fout("logs/cdi_test2.log");
00058   double interval;
00059   unsigned int tIntv = atoi(argv[1]);
00060   log << "::cdi_test2 -> Storing data with interval of " << tIntv << " microseconds" << std::endl;
00061   
00062   std::cout << OWLTime() << " :: cdi_test2 -> Initializing partition [be_test]!" << std::endl;
00063   
00064   fout << "------------------ Test1 START------------------------------" << std::endl;
00065   fout << "Initialize Online Environment : [" ;
00066   
00067   gettimeofday(&t_start,NULL);
00068   
00069 //IPCPartition      p("part_localhost");
00070 IPCPartition      p("be_test");
00071   
00072   if (p.isValid()) {
00073     std::cout << OWLTime() << " :: partition is valid!" << std::endl;
00074   }
00075   else
00076     std::cout << OWLTime() << " :: partition is NOT valid!" << std::endl;
00077   
00078   
00079   
00080   std::cout << OWLTime() << " :: cdi_test2 -> Initializing the dictionary!" << std::endl;
00081   
00082   ISInfoDictionary dict(p); 
00083   
00084   std::cout << OWLTime() << " :: cdi_test2 -> Initializing Conditions object!" << std::endl;
00085   //  Conditions c;
00086  
00087 
00088   gettimeofday(&t_end,NULL);
00089   interval = (double)(((double)t_end.tv_sec*1000+(double)t_end.tv_usec/1000)-((double)t_start.tv_sec*1000+(double)t_start.tv_usec/1000));
00090   fout << interval << "]" << std::endl;
00091   
00092 
00093 
00094   /* NEW PART GOES HERE
00095    */
00096      TestInfo1 obj1;
00097      TestInfo2 obj2;
00098      TestInfo3 obj3;
00099      TestInfo4 obj4;
00100      TestInfo5 obj5;
00101      TestInfo6 obj6;
00102      TestInfo7 obj7;
00103      TestInfo8 obj8;
00104      TestInfo9 obj9;
00105      TestInfo10 obj10;
00106      TestInfo11 obj11;
00107      TestInfo12 obj12;
00108 
00109 
00110 
00111 //  TestInfo tmp1;
00112 
00113   obj1.c = 'a';
00114   obj1.uc = 'b';    
00115   obj1.i = 1;
00116   obj1.ui = 2;
00117   obj1.s = 3;
00118   obj1.us = 4;
00119   obj1.l = 5;   
00120   obj1.ul = 6;
00121   obj1.f = 7.7;
00122   obj1.d = 8.8;
00123 
00124   /*  
00125   strcpy(obj1.str, "RunParams");
00126   strcpy(obj1.cstr, "This is a constant string");   
00127   strcpy((char *)obj1.ustr, "This is a dinamic unsigned string");
00128   strcpy((char *)obj1.custr, "This is a constant unsigned string");
00129   */
00130 
00131 // object 2
00132   obj2.c = 'a';
00133   obj2.uc = 'b';    
00134   obj2.i = 1;
00135   obj2.ui = 2;
00136   obj2.s = 3;
00137   obj2.us = 4;
00138   obj2.l = 5;   
00139   obj2.ul = 6;
00140   obj2.f = 7.7;
00141   obj2.d = 8.8;
00142   /*  strcpy(obj2.str, "RunParams");
00143   strcpy(obj2.cstr, "This is a constant string");   
00144   strcpy((char *)obj2.ustr, "This is a dinamic unsigned string");
00145   strcpy((char *)obj2.custr, "This is a constant unsigned string");
00146   */
00147 // object 3
00148   obj3.c = 'a';
00149   obj3.uc = 'b';    
00150   obj3.i = 1;
00151   obj3.ui = 3;
00152   obj3.s = 3;
00153   obj3.us = 4;
00154   obj3.l = 5;   
00155   obj3.ul = 6;
00156   obj3.f = 7.7;
00157   obj3.d = 8.8;
00158 
00159   /*
00160   strcpy(obj3.str, "RunParams");
00161   strcpy(obj3.cstr, "This is a constant string");   
00162   strcpy((char *)obj3.ustr, "This is a dinamic unsigned string");
00163   strcpy((char *)obj3.custr, "This is a constant unsigned string");
00164   */
00165 // object 4
00166   obj4.c = 'a';
00167   obj4.uc = 'b';    
00168   obj4.i = 1;
00169   obj4.ui = 4;
00170   obj4.s = 3;
00171   obj4.us = 4;
00172   obj4.l = 5;   
00173   obj4.ul = 6;
00174   obj4.f = 7.7;
00175   obj4.d = 8.8;
00176   /* strcpy(obj4.str, "RunParams");
00177   strcpy(obj4.cstr, "This is a constant string");   
00178   strcpy((char *)obj4.ustr, "This is a dinamic unsigned string");
00179   strcpy((char *)obj4.custr, "This is a constant unsigned string");
00180   */
00181 // object 5
00182   obj5.c = 'a';
00183   obj5.uc = 'b';    
00184   obj5.i = 1;
00185   obj5.ui = 5;
00186   obj5.s = 3;
00187   obj5.us = 4;
00188   obj5.l = 5;   
00189   obj5.ul = 6;
00190   obj5.f = 7.7;
00191   obj5.d = 8.8;
00192   /*
00193  strcpy(obj5.str, "RunParams");
00194   strcpy(obj5.cstr, "This is a constant string");   
00195   strcpy((char *)obj5.ustr, "This is a dinamic unsigned string");
00196   strcpy((char *)obj5.custr, "This is a constant unsigned string");
00197   */
00198 // object 6
00199   obj6.c = 'a';
00200   obj6.uc = 'b';    
00201   obj6.i = 1;
00202   obj6.ui = 6;
00203   obj6.s = 3;
00204   obj6.us = 4;
00205   obj6.l = 5;   
00206   obj6.ul = 6;
00207   obj6.f = 7.7;
00208   obj6.d = 8.8;
00209   /* strcpy(obj6.str, "RunParams");
00210   strcpy(obj6.cstr, "This is a constant string");   
00211   strcpy((char *)obj6.ustr, "This is a dinamic unsigned string");
00212   strcpy((char *)obj6.custr, "This is a constant unsigned string");
00213   */
00214 // object 7
00215   obj7.c = 'a';
00216   obj7.uc = 'b';    
00217   obj7.i = 1;
00218   obj7.ui = 7;
00219   obj7.s = 3;
00220   obj7.us = 4;
00221   obj7.l = 5;   
00222   obj7.ul = 6;
00223   obj7.f = 7.7;
00224   obj7.d = 8.8;
00225   /* strcpy(obj7.str, "RunParams");
00226   strcpy(obj7.cstr, "This is a constant string");   
00227   strcpy((char *)obj7.ustr, "This is a dinamic unsigned string");
00228   strcpy((char *)obj7.custr, "This is a constant unsigned string");
00229   */
00230 // object 8
00231   obj8.c = 'a';
00232   obj8.uc = 'b';    
00233   obj8.i = 1;
00234   obj8.ui = 8;
00235   obj8.s = 3;
00236   obj8.us = 4;
00237   obj8.l = 5;   
00238   obj8.ul = 6;
00239   obj8.f = 7.7;
00240   obj8.d = 8.8;
00241   /*  strcpy(obj8.str, "RunParams");
00242   strcpy(obj8.cstr, "This is a constant string");   
00243   strcpy((char *)obj8.ustr, "This is a dinamic unsigned string");
00244   strcpy((char *)obj8.custr, "This is a constant unsigned string");
00245   */
00246 // object 9
00247   obj9.c = 'a';
00248   obj9.uc = 'b';    
00249   obj9.i = 1;
00250   obj9.ui = 9;
00251   obj9.s = 3;
00252   obj9.us = 4;
00253   obj9.l = 5;   
00254   obj9.ul = 6;
00255   obj9.f = 7.7;
00256   obj9.d = 8.8;
00257 
00258   /*
00259   strcpy(obj9.str, "RunParams");
00260   strcpy(obj9.cstr, "This is a constant string");   
00261   strcpy((char *)obj9.ustr, "This is a dinamic unsigned string");
00262   strcpy((char *)obj9.custr, "This is a constant unsigned string");
00263 */
00264 
00265 // object 10
00266   obj10.c = 'a';
00267   obj10.uc = 'b';   
00268   obj10.i = 1;
00269   obj10.ui = 10;
00270   obj10.s = 3;
00271   obj10.us = 4;
00272   obj10.l = 5;  
00273   obj10.ul = 6;
00274   obj10.f = 7.7;
00275   obj10.d = 8.8;
00276   /* 
00277  strcpy(obj10.str, "RunParams");
00278   strcpy(obj10.cstr, "This is a constant string");  
00279   strcpy((char *)obj10.ustr, "This is a dinamic unsigned string");
00280   strcpy((char *)obj10.custr, "This is a constant unsigned string");
00281   */
00282 // object 11
00283   obj11.c = 'a';
00284   obj11.uc = 'b';   
00285   obj11.i = 1;
00286   obj11.ui = 11;
00287   obj11.s = 3;
00288   obj11.us = 4;
00289   obj11.l = 5;  
00290   obj11.ul = 6;
00291   obj11.f = 7.7;
00292   obj11.d = 8.8;
00293   /* 
00294  strcpy(obj11.str, "RunParams");
00295   strcpy(obj11.cstr, "This is a constant string");  
00296   strcpy((char *)obj11.ustr, "This is a dinamic unsigned string");
00297   strcpy((char *)obj11.custr, "This is a constant unsigned string");
00298   */
00299 // object 12
00300   obj12.c = 'a';
00301   obj12.uc = 'b';   
00302   obj12.i = 1;
00303   obj12.ui = 2;
00304   obj12.s = 3;
00305   obj12.us = 4;
00306   obj12.l = 5;  
00307   obj12.ul = 6;
00308   obj12.f = 7.7;
00309   obj12.d = 8.8;
00310   /* 
00311  strcpy(obj12.str, "RunParams");
00312   strcpy(obj12.cstr, "This is a constant string");  
00313   //strcpy((char *)obj12.ustr, "This is a dinamic unsigned string");
00314   //strcpy((char *)obj12.custr, "This is a constant unsigned string");
00315   obj12.ustr = "This is a dinamic unsigned string";
00316   obj12.cstr = "This is a constant unsigned string";
00317   */
00318                             
00319 
00320   std::vector<std::string> names;
00321   std::vector<ISInfo*> objs;
00322   objs.push_back(&obj1);
00323   objs.push_back(&obj2);
00324   objs.push_back(&obj3);
00325   objs.push_back(&obj4);
00326   objs.push_back(&obj5);
00327   objs.push_back(&obj6);
00328   objs.push_back(&obj7);
00329   objs.push_back(&obj8);
00330   objs.push_back(&obj9);
00331   objs.push_back(&obj10);
00332   objs.push_back(&obj11);
00333   objs.push_back(&obj12);
00334 
00335   for (unsigned int i=1; i<= 12; i++){
00336   std::ostringstream n;
00337   n << "RunParams.obj" << i;
00338   names.push_back(n.str().c_str());
00339   }
00340   
00341   std::cout << OWLTime() << " :: cdi_test2 -> Adding Information objects to the list!" << std::endl;
00342   fout << "Subscribing the object :["; 
00343   gettimeofday(&t_start,NULL);
00344   for (unsigned int i=1; i<=12; i++){
00345   dict.insert(names[i].c_str(),*(objs[i]));
00346   }
00347   gettimeofday(&t_end,NULL);
00348   interval = (double)(((double)t_end.tv_sec*1000+(double)t_end.tv_usec/1000)-((double)t_start.tv_sec*1000+(double)t_start.tv_usec/1000));
00349   fout << interval << "]" << std::endl;  
00350   sleep(30);
00351   /*
00352   */
00353 
00354    std::cout << OWLTime() << " ::cdi_test2 -> Starting to update the objects" << std::endl;
00355   //after having a nice beauty sleep we need to get to work again
00356   // let's start to update data
00357   
00358 
00359   timeval tt_s, tt_e;
00360   gettimeofday(&t_start,NULL);
00361 
00362   for (unsigned int i = 1; i <= MAX_UPD; i++) {
00363     for (unsigned int j = 1; j <=12; j++){
00364       (dynamic_cast<TestInfo1*>(objs[0]))->i += i;
00365       dynamic_cast<TestInfo2*>(objs[1])->i += i;
00366       dynamic_cast<TestInfo3*>(objs[2])->i += i;
00367       dynamic_cast<TestInfo4*>(objs[3])->i += i;
00368       dynamic_cast<TestInfo5*>(objs[4])->i += i;
00369       dynamic_cast<TestInfo6*>(objs[5])->i += i;
00370       dynamic_cast<TestInfo7*>(objs[6])->i += i;
00371       dynamic_cast<TestInfo8*>(objs[7])->i += i;
00372       dynamic_cast<TestInfo9*>(objs[8])->i += i;
00373       dynamic_cast<TestInfo10*>(objs[9])->i += i;
00374       fout << "Updating object [" << i << "| 0 ] : -> [";
00375       gettimeofday(&tt_s,NULL);
00376       dict.update(names[j].c_str(),*(objs[j]));
00377       gettimeofday(&tt_e,NULL);
00378       interval = (double)(((double)tt_e.tv_sec*1000+(double)tt_e.tv_usec/1000)-((double)tt_s.tv_sec*1000+(double)tt_s.tv_usec/1000));
00379       fout << interval << "]" << std::endl;
00380       // number of microseconds to sleep
00381       usleep(tIntv);
00382     }
00383   }
00384   gettimeofday(&t_end,NULL);
00385   interval = (double)(((double)t_end.tv_sec*1000+(double)t_end.tv_usec/1000)-((double)t_start.tv_sec*1000+(double)t_start.tv_usec/1000));
00386   fout << "Total update time: [" << interval << "]" << std::endl;
00387   fout << "-------------------------------------END OF TEST ----------------------------------";
00388 
00389   fout.close();
00390   log << "::cdi_test2 -> Test finished....exiting" << std::endl;
00391   return 0;
00392 }

Generated on Mon Feb 6 14:01:17 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6