00001 00002 // 00003 // FUShmClient 00004 // ----------- 00005 // 00006 // 17/11/2006 Philipp Schieferdecker <philipp.schieferdecker@cern.ch> 00008 00009 00010 #include "EventFilter/ShmBuffer/bin/FUShmClient.h" 00011 00012 00013 #include <iostream> 00014 #include <cstdlib> // rand() 00015 #include <unistd.h> // sleep 00016 00017 00018 using namespace std; 00019 using namespace evf; 00020 00021 00022 double get_rnd(); 00023 00024 00026 // construction/destruction 00028 00029 //______________________________________________________________________________ 00030 FUShmClient::FUShmClient(FUShmBuffer* buffer) 00031 : buffer_(buffer) 00032 , crashPrb_(0.01) 00033 , sleep_(0) 00034 { 00035 00036 } 00037 00038 00039 //______________________________________________________________________________ 00040 FUShmClient::~FUShmClient() 00041 { 00042 00043 } 00044 00045 00047 // implementation of member functions 00049 00050 //______________________________________________________________________________ 00051 unsigned int FUShmClient::readNext(vector<vector<unsigned char> >& feds) 00052 { 00053 FUShmRawCell* cell=buffer_->rawCellToRead(); 00054 00055 // read data 00056 unsigned int iCell=cell->index(); 00057 unsigned int nFed =cell->nFed(); 00058 feds.resize(nFed); 00059 for (unsigned int i=0;i<nFed;i++) { 00060 unsigned int fedSize =cell->fedSize(i); 00061 feds[i].resize(fedSize); 00062 unsigned char *destAddr=(unsigned char*)&(feds[i][0]); 00063 cell->readFed(i,destAddr); 00064 } 00065 buffer_->finishReadingRawCell(cell); 00066 00067 // sleep 00068 if (sleep_>0.0) { 00069 cout<<"PROCESSING cell "<<cell->index()<<" ... "<<flush; 00070 sleep(sleep_); 00071 cout<<"DONE"<<endl; 00072 } 00073 00074 //crash 00075 if (get_rnd()<crashPrb()) { 00076 cout<<"FUShmClient::readNext(): CRASH! cell->index()="<<cell->index()<<endl; 00077 exit(1); 00078 } 00079 00080 buffer_->scheduleRawCellForDiscard(iCell); 00081 cell=buffer_->rawCellToDiscard(); 00082 buffer_->discardRawCell(cell); 00083 00084 return iCell; 00085 } 00086 00087 00088 //______________________________________________________________________________ 00089 double get_rnd() 00090 { 00091 double result=rand()/(double)RAND_MAX; 00092 return result; 00093 }