CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/EventFilter/ShmBuffer/bin/FUShmServer_t.cc

Go to the documentation of this file.
00001 
00002 //
00003 // FUShmServer_t
00004 // -------------
00005 //
00006 //            17/11/2006 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
00008 
00009 
00010 #include "EventFilter/ShmBuffer/interface/FUShmBuffer.h"
00011 #include "EventFilter/ShmBuffer/bin/FUShmServer.h"
00012 
00013 #include <iostream>
00014 #include <cstdlib>   // rand()
00015 #include <sstream>
00016 
00017 
00018 using namespace std;
00019 using namespace evf;
00020 
00021 
00022 //______________________________________________________________________________
00023 int main(int argc,char**argv)
00024 {
00025   bool         segmentationMode=false;
00026   unsigned int nCells          =32;
00027   unsigned int nFed            = 4;
00028   unsigned int bytesPerFed     =10;
00029   unsigned int cellBufferSize  =nFed*bytesPerFed;
00030   
00031   if (argc>1) { stringstream ss; ss<<argv[1]; ss>>segmentationMode; }
00032   
00033   cout<<" FUShmServer_t:"
00034       <<" segmentationMode="<<segmentationMode
00035       <<" nCells="<<nCells
00036       <<" nFed="<<nFed
00037       <<" bytesPerFed="<<bytesPerFed
00038       <<" cellBufferSize="<<cellBufferSize<<endl<<endl;
00039   
00040   FUShmBuffer* buffer=FUShmBuffer::createShmBuffer(segmentationMode,
00041                                                    nCells,0,0,
00042                                                    cellBufferSize,0,0);
00043   if (0==buffer) return 1;
00044   FUShmServer* server=new FUShmServer(buffer);
00045   
00046   
00047   // the fake data written to shared memory
00048   unsigned char* data         =new unsigned char[cellBufferSize];
00049   unsigned int*  fedSize      =new unsigned int[nFed];
00050   for (unsigned int i=0;i<nFed;i++) fedSize[i]=bytesPerFed;
00051   
00052   
00053   // server loop
00054   while(1) {
00055     
00056     // generate data
00057     for (unsigned int i=0;i<cellBufferSize;i++) {
00058       unsigned int rnd=rand();
00059       double tmp=rnd/(double)RAND_MAX*255;
00060       rnd=(unsigned int)tmp;
00061       data[i]=(unsigned char)rnd;
00062     }
00063     
00064     unsigned int iCell=server->writeNext(data,nFed,fedSize);
00065     cout<<"WROTE at index "<<iCell<<endl;
00066   }
00067   
00068   return 0;
00069 }