cdi_test1.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 
00034 
00035 
00036 // the number of data updates that must be made
00037 #define MAX_UPD 1000
00038 #define log std::cout << OWLTime()
00039 
00040 
00041 
00042 
00043 
00044 int main(int argc, char**argv){
00045   IPCCore::init(argc, argv);
00046 
00047   setenv("TEST_NAME", __FILE__ ,1);  
00048   if (argc != 2 ){
00049     log << "::cdi_test -> Time interval not defined" << std::endl;
00050     return 1;
00051   }
00052 
00053   timeval t_start, t_end;
00054 
00055   std::ofstream fout("logs/cdi_test1.log");
00056   double interval;
00057   unsigned int tIntv = atoi(argv[1]);
00058   log << "::cdi_test -> Storing data with interval of " << tIntv << " microseconds" << std::endl;
00059 
00060   std::cout << OWLTime() << " :: cdi_test -> Initializing partition [be_test]!" << std::endl;
00061   
00062   fout << "------------------ Test1 START------------------------------" << std::endl;
00063   fout << "Initialize Online Environment : [" ;
00064   
00065   gettimeofday(&t_start,NULL);
00066   
00067 //IPCPartition      p("part_localhost");
00068 IPCPartition      p("be_test");
00069   
00070   if (p.isValid()) {
00071     std::cout << OWLTime() << " :: partition is valid!" << std::endl;
00072   }
00073   else
00074     std::cout << OWLTime() << " :: partition is NOT valid!" << std::endl;
00075   
00076   
00077   
00078   std::cout << OWLTime() << " :: cdi_test -> Initializing the dictionary!" << std::endl;
00079   
00080   ISInfoDictionary dict(p); 
00081   
00082   std::cout << OWLTime() << " :: cdi_test -> Initializing Conditions object!" << std::endl;
00083   //  Conditions c;
00084  
00085 
00086   gettimeofday(&t_end,NULL);
00087   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));
00088   fout << interval << "]" << std::endl;
00089   
00090   
00091   RunParams rp;
00092   
00093   std::vector<std::string> a;
00094   
00095   std::cout << OWLTime() << " :: cdi_test -> Adding Information objects to the list!" << std::endl;
00096   // a.push_back("RunCtrl.Application_dsa_supervisor");
00097   //  a.push_back("RunEvents.*");
00098   a.push_back("RunParams.RunParams");
00099   //  a.push_back("RunParams.Conditions");
00100   
00101   rp.run_number = 0;
00102   rp.max_events = 1000;
00103   rp.rec_enable = 1;
00104   rp.trigger_type = 1;
00105   rp.detector_mask = 1;
00106   rp.beam_type = 1;
00107   rp.beam_energy = 1000;
00108   rp.filename_tag = "Test string";
00109   rp.timeSOR = OWLTime();
00110   rp.timeEOR = OWLTime();
00111   rp.totalTime = 12312;
00112   
00113                 //  c.ISServers_size = 3;
00114   // c.isservers = a;
00115   
00116   
00117   //  std::cout << OWLTime() << " :: cdi_test -> Publishing the servers to the dictionary!" << std::endl;
00118   //  dict.insert("RunParams.Conditions", c);
00119   std::cout << OWLTime() << " :: cdi_test -> Insert RunParams to the dictionary!" << std::endl;
00120 
00121   fout << "Subscribing the object :["; 
00122   gettimeofday(&t_start,NULL);
00123   dict.insert("RunParams.RunParams",rp);
00124   gettimeofday(&t_end,NULL);
00125   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));
00126   fout << interval << "]" << std::endl;  
00127   sleep(30);
00128 
00129   //c.ISServers = new std::string("RunCtr.RunCtrl");
00130   
00138   std::cout << OWLTime() << " ::cdi_test (parent) -> Starting to update the objects" << std::endl;
00139   //after having a nice beauty sleep we need to get to work again
00140   // let's start to update data
00141   
00142   int status;
00143   timeval tt_s, tt_e;
00144   gettimeofday(&t_start,NULL);
00145 
00146   for (unsigned int i = 1; i <= MAX_UPD; i++) {
00147     std::ostringstream t;
00148     rp.run_number += 1;
00149     rp.max_events += 10;
00150     rp.rec_enable = ((rp.rec_enable) % i);
00151     rp.trigger_type = 1;
00152     rp.detector_mask = 1;
00153     rp.beam_type = 1;
00154     rp.beam_energy += 11;
00155     t << "_" << i;
00156     rp.filename_tag = std::string("Teste_str" + t.str());
00157     /*
00158       rp.timeSOR = OWLTime();
00159       rp.timeEOR = OWLTime();
00160       rp.totalTime = 12312;
00161     */
00162     fout << "Updating object [" << i << ": -> [";
00163     gettimeofday(&tt_s,NULL);
00164     dict.update("RunParams.RunParams",rp);
00165     gettimeofday(&tt_e,NULL);
00166     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));
00167     fout << interval << "]" << std::endl;
00168     // number of microseconds to sleep
00169     status = usleep(tIntv);
00170     if (status != 0) {
00171     fout << "========> FAILED TO SLEEP!!"<< std::endl;
00172     fout.close();
00173     exit (1);
00174     }
00175     
00176   }
00177   gettimeofday(&t_end,NULL);
00178   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));
00179   fout << "Total update time: [" << interval << "]" << std::endl;
00180   fout << "-------------------------------------END OF TEST ----------------------------------";
00181 
00182   fout.close();
00183   log << "::cdi_test -> Test finished....exiting" << std::endl;
00184   return 0;
00185 }

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