CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FUShmClient.cc
Go to the documentation of this file.
1 //
3 // FUShmClient
4 // -----------
5 //
6 // 17/11/2006 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
8 
9 
11 
12 
13 #include <iostream>
14 #include <cstdlib> // rand()
15 #include <unistd.h> // sleep
16 
17 
18 using namespace std;
19 using namespace evf;
20 
21 
22 double get_rnd();
23 
24 
26 // construction/destruction
28 
29 //______________________________________________________________________________
30 FUShmClient::FUShmClient(FUShmBuffer* buffer)
31  : buffer_(buffer)
32  , crashPrb_(0.01)
33  , sleep_(0)
34 {
35 
36 }
37 
38 
39 //______________________________________________________________________________
41 {
42 
43 }
44 
45 
47 // implementation of member functions
49 
50 //______________________________________________________________________________
51 unsigned int FUShmClient::readNext(vector<vector<unsigned char> >& feds)
52 {
54 
55  // read data
56  unsigned int iCell=cell->index();
57  unsigned int nFed =cell->nFed();
58  feds.resize(nFed);
59  for (unsigned int i=0;i<nFed;i++) {
60  unsigned int fedSize =cell->fedSize(i);
61  feds[i].resize(fedSize);
62  unsigned char *destAddr=(unsigned char*)&(feds[i][0]);
63  cell->readFed(i,destAddr);
64  }
66 
67  // sleep
68  if (sleep_>0.0) {
69  cout<<"PROCESSING cell "<<cell->index()<<" ... "<<flush;
70  sleep(sleep_);
71  cout<<"DONE"<<endl;
72  }
73 
74  //crash
75  if (get_rnd()<crashPrb()) {
76  cout<<"FUShmClient::readNext(): CRASH! cell->index()="<<cell->index()<<endl;
77  exit(1);
78  }
79 
81  cell=buffer_->rawCellToDiscard();
82  buffer_->discardRawCell(cell);
83 
84  return iCell;
85 }
86 
87 
88 //______________________________________________________________________________
89 double get_rnd()
90 {
91  double result=rand()/(double)RAND_MAX;
92  return result;
93 }
FUShmRawCell * rawCellToRead()
Definition: FUShmBuffer.cc:317
FUShmRawCell * rawCellToDiscard()
Definition: FUShmBuffer.cc:373
int i
Definition: DBlmapReader.cc:9
unsigned int readNext(std::vector< std::vector< unsigned char > > &feds)
Definition: FUShmClient.cc:51
double crashPrb() const
Definition: FUShmClient.h:28
void sleep(Duration_t)
Definition: Utils.h:163
void discardRawCell(FUShmRawCell *cell)
Definition: FUShmBuffer.cc:495
tuple result
Definition: query.py:137
unsigned int readFed(unsigned int i, unsigned char *buffer) const
double get_rnd()
Definition: FUShmClient.cc:89
unsigned int index() const
Definition: FUShmRawCell.h:25
unsigned int nFed() const
Definition: FUShmRawCell.h:33
Signal rand(Signal arg)
Definition: vlib.cc:442
tuple cout
Definition: gather_cfg.py:121
unsigned int fedSize(unsigned int i) const
Definition: FUShmRawCell.cc:82
void finishReadingRawCell(FUShmRawCell *cell)
Definition: FUShmBuffer.cc:410
FUShmBuffer * buffer_
Definition: FUShmClient.h:36
void scheduleRawCellForDiscard(unsigned int iCell)
Definition: FUShmBuffer.cc:454