/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/eformat/eformat-00-00-04/bench/validate.cxx

Go to the documentation of this file.
00001 //Dear emacs, this is -*- c++ -*-
00002 
00013 #include "eformat/eformat.h"
00014 #include "clocks/Clock.h"
00015 #include "clocks/Time.h"
00016 #include <iostream>
00017 #include <fstream>
00018 
00022 const size_t PAGE_SIZE = 8192; //8 kilobytes pages
00023 const size_t BUFFER_SIZE = 4194304; //4 Megabytes
00024 
00028 template <class TPointer>
00029 uint32_t components (const eformat::FullEventFragment<TPointer>& f)
00030 {
00031   using namespace eformat;
00032   uint32_t retval = 0;
00033 
00034   //max SD's is well bellow 64
00035   TPointer sdp[64];
00036   uint32_t nsd = f.children(sdp, 64);
00037   retval += nsd;
00038   for (size_t i=0; i<nsd; ++i) {
00039     SubDetectorFragment<TPointer> sd(sdp[i]);
00040     //max ROS's in system is well bellow 256
00041     TPointer rosp[256];
00042     uint32_t nros = sd.children(rosp, 256);
00043     retval += nros;
00044     for (size_t j=0; j<nros; ++j) {
00045       ROSFragment<TPointer> ros(rosp[j]);
00046       retval += ros.nchildren();
00047     }
00048   }
00049 
00050   return retval;
00051 }
00052 
00056 int main (int argc, char** argv)
00057 {
00058   using namespace eformat;
00059 
00060   if ( argc != 2 ) {
00061     std::cerr << "usage: " << argv[0] << " <test-file>"
00062               << std::endl;
00063     std::exit(1);
00064   }
00065 
00066   //time accounting
00067   double cpu_time_used = 0;
00068   uint32_t events_read = 0;
00069   uint32_t components_instantiated = 0;
00070   RealTimeClock my_clock;
00071   uint32_t event_size = 0;
00072 
00073   //open normally a file
00074   std::fstream in(argv[1], std::ios::in|std::ios::binary);
00075   if (!in) {
00076     std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl;
00077     std::exit(1);
00078   }
00079   size_t offset = 0;
00080 
00081 #ifdef PAGED_MEMORY
00082     std::cout << "Working with paged storage with page size = " 
00083               << PAGE_SIZE << " bytes." << std::endl;
00084 #else
00085     std::cout << "Working with contiguous storage." << std::endl;
00086 #endif
00087 
00088   while (in && in.good() && ! in.eof()) {
00089     //soft check, so we don't mistake too often
00090     uint32_t data[2];
00091     in.read((char*)data, 8);
00092     if (!in.good() || in.eof()) break; // end-of-file 
00093     if (data[0] != eformat::FULL_EVENT) {
00094       //stop!
00095       std::cout << "Word at offset " << HEX(offset) << " is not "
00096                 << HEX(eformat::FULL_EVENT) << std::endl;
00097       std::exit(1);
00098     }
00099 
00100 #ifdef PAGED_MEMORY
00101     //data[1] is the fragment size, in words. Take it and read the fragment
00102     in.seekg(offset);
00103     //read the event into my pages
00104     size_t to_read = data[1]<<2;
00105     size_t page_counter = 0;
00106     //std::cout << "Loading page";
00107     uint32_t paged_event[BUFFER_SIZE/PAGE_SIZE][PAGE_SIZE/sizeof(uint32_t)];
00108     while (to_read > 0) {
00109       size_t readnow = (PAGE_SIZE>to_read)?to_read:PAGE_SIZE;
00110       in.read((char*)paged_event[page_counter], readnow);
00111       to_read -= readnow;
00112       ++page_counter;
00113       //std::cout << " " << page_counter;
00114     }
00115     //std::cout << ": ";
00116     struct iovec myvec[BUFFER_SIZE/PAGE_SIZE];
00117     for (size_t i=0; i<page_counter; ++i) {
00118       myvec[i].iov_base = paged_event[i];
00119       myvec[i].iov_len = PAGE_SIZE;
00120     }
00121     //correct last page
00122     myvec[page_counter-1].iov_len = data[1]<<2 - (page_counter-1)*PAGE_SIZE;
00123     eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE> mem(myvec, page_counter);
00124 #else
00125     in.seekg(offset);
00126     uint32_t event[BUFFER_SIZE/4];
00127     in.read((char*)event, data[1]<<2);
00128 #endif
00129 
00130     offset += data[1]<<2;
00131 
00132     try {
00133 #ifdef PAGED_MEMORY
00134       FullEventFragment<eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE>::
00135         const_iterator> fe(mem.begin());
00136 #else
00137       FullEventFragment<const uint32_t*> fe(event);
00138 #endif
00139 
00140       event_size += 4*fe.fragment_size_word();
00141 
00142       Time start = my_clock.time();
00143       fe.check_tree();
00144       Time end = my_clock.time();
00145       Time diff = end - start;
00146 
00147       //calculate the number of event components:
00148       uint32_t comps = components(fe);
00149       components_instantiated += comps;
00150       
00151       //std::cout << " > Timing          : " << diff.as_milliseconds()
00152         //      << " ms" << std::endl;
00153       //std::cout << " > Timing/component: " << diff.as_milliseconds()*1e3/comps
00154         //      << " us" << std::endl;
00155       cpu_time_used += diff.as_milliseconds();
00156       ++events_read;
00157 
00158       //if check is ok, print the lvl1 identifier
00159       //std::cout << fe.lvl1_id() << "..";
00160     }
00161 
00162     catch (eformat::Issue& ex) {
00163       std::cerr << std::endl
00164                 << "Uncaught eformat exception: " << ex.what() << std::endl;
00165     }
00166 
00167     catch (ers::Issue& ex) {
00168       std::cerr << std::endl
00169                 << "Uncaught ERS exception: " << ex.what() << std::endl;
00170     }
00171 
00172     catch (std::exception& ex) {
00173       std::cerr << std::endl
00174                 << "Uncaught std exception: " << ex.what() << std::endl;
00175     }
00176 
00177     catch (...) {
00178       std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
00179     }
00180 
00181   }
00182 
00183   std::cout << std::endl;
00184   std::cout << " Statistics for Event Validation:" << std::endl;
00185   std::cout << " --------------------------------" << std::endl;
00186   std::cout << "  - Total reading time: " << cpu_time_used << " millisecs"
00187             << std::endl;
00188   std::cout << "  - Validation time per event ("
00189             << events_read << "): " << cpu_time_used/events_read
00190             << " millisecs" << std::endl;
00191   std::cout << "  - Average event size: "
00192             << event_size/(1024.0*1024*events_read) << " megabytes" << std::endl;
00193   std::cout << "  - Validation time per component ("
00194             << components_instantiated << "): " 
00195             << 1e3*cpu_time_used/components_instantiated
00196             << " microsecs" << std::endl;
00197   std::exit(0);
00198 }
00199 
00200 

Generated on Tue Nov 29 22:58:24 2016 for BOSS_7.0.2 by  doxygen 1.4.7