CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FUShmRawCell.cc
Go to the documentation of this file.
1 //
3 // FUShmRawCell
4 // ------------
5 //
6 // 09/11/2006 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
8 
9 
11 
12 #include <iostream>
13 #include <iomanip>
14 #include <cstring>
15 
16 #define NSUPERFRAG_MAX 80
17 #define NFED_MAX 1024
18 
19 
20 using namespace std;
21 using namespace evf;
22 
23 
25 // construction/destruction
27 
28 //______________________________________________________________________________
29 FUShmRawCell::FUShmRawCell(unsigned int payloadSize)
30  : payloadSize_(payloadSize)
31  , nFed_(NFED_MAX)
32  , nSuperFrag_(NSUPERFRAG_MAX)
33  , lumiSection_(0)
34  , eventType_(evt::NOP)
35 {
37  unsigned int* fedSizeAddr;
38  fedSizeAddr=(unsigned int*)((unsigned long)this+fedSizeOffset_);
39  new(fedSizeAddr) unsigned int[nFed_];
40 
41  fedOffset_=fedSizeOffset_+sizeof(unsigned int)*nFed_;
42  unsigned int* fedAddr;
43  fedAddr=(unsigned int*)((unsigned long)this+fedOffset_);
44  new(fedAddr) unsigned int[nFed_];
45 
46  superFragSizeOffset_=fedOffset_+sizeof(unsigned int)*nFed_;
47  unsigned int* superFragSizeAddr;
48  superFragSizeAddr=(unsigned int*)((unsigned long)this+superFragSizeOffset_);
49  new(superFragSizeAddr) unsigned int[nSuperFrag_];
50 
52  unsigned char* superFragAddr;
53  superFragAddr=(unsigned char*)((unsigned long)this+superFragOffset_);
54  new(superFragAddr) unsigned char[nSuperFrag_];
55 
56  payloadOffset_=superFragOffset_+sizeof(unsigned int)*nSuperFrag_;
57  unsigned char* payloadAddr;
58  payloadAddr=(unsigned char*)((unsigned long)this+payloadOffset_);
59  new(payloadAddr) unsigned char[payloadSize_];
60 }
61 
62 
63 //______________________________________________________________________________
65 {
66 
67 }
68 
69 
71 // implementation of member functions
73 
74 //______________________________________________________________________________
75 void FUShmRawCell::initialize(unsigned int index)
76 {
77  index_=index;
78  lumiSection_=0;
80 }
81 
82 
83 //______________________________________________________________________________
84 unsigned int FUShmRawCell::fedSize(unsigned int i) const
85 {
86  if (i>=nFed()) {cout<<"invalid fed index '"<<i<<"'."<<endl; return 0; }
87  unsigned int* fedSizeAddr;
88  fedSizeAddr=(unsigned int*)((unsigned long)this+fedSizeOffset_);
89  fedSizeAddr+=i;
90  unsigned int result=*fedSizeAddr;
91  return result;
92 }
93 
94 
95 //______________________________________________________________________________
96 unsigned char* FUShmRawCell::fedAddr(unsigned int i) const
97 {
98  if (i>=nFed()) {cout<<"invalid fed index '"<<i<<"'."<<endl; return 0; }
99  unsigned int* fedOffsetAddr;
100  fedOffsetAddr=(unsigned int*)((unsigned long)this+fedOffset_);
101  fedOffsetAddr+=i;
102  unsigned int fedOffset=*fedOffsetAddr;
103  unsigned char* result=(unsigned char*)((unsigned long)payloadAddr()+fedOffset);
104  return result;
105 }
106 
107 
108 //______________________________________________________________________________
109 unsigned int FUShmRawCell::superFragSize(unsigned int i) const
110 {
111  if (i>=nSuperFrag()) {cout<<"invalid sf index '"<<i<<"'."<<endl; return 0; }
112  unsigned int* superFragSizeAddr;
113  superFragSizeAddr=(unsigned int*)((unsigned long)this+superFragSizeOffset_);
114  superFragSizeAddr+=i;
115  unsigned int result=*superFragSizeAddr;
116  return result;
117 }
118 
119 
120 //______________________________________________________________________________
121 unsigned char* FUShmRawCell::superFragAddr(unsigned int i) const
122 {
123  if (i>=nSuperFrag()) {cout<<"invalid fed index '"<<i<<"'."<<endl; return 0; }
124  unsigned int* superFragOffsetAddr;
125  superFragOffsetAddr=(unsigned int*)((unsigned long)this+superFragOffset_);
126  superFragOffsetAddr+=i;
127  unsigned int superFragOffset=*superFragOffsetAddr;
128  unsigned char* result=(unsigned char*)((unsigned long)payloadAddr()+superFragOffset);
129  return result;
130 }
131 
132 
133 //______________________________________________________________________________
134 unsigned char* FUShmRawCell::payloadAddr() const
135 {
136  unsigned char* result=(unsigned char*)((unsigned long)this+payloadOffset_);
137  return result;
138 }
139 
140 
141 //______________________________________________________________________________
142 unsigned int FUShmRawCell::eventSize() const
143 {
144  return payloadPosition_;
145 }
146 
147 
148 //______________________________________________________________________________
150 {
151  fuResourceId_=0xffffffff;
152  buResourceId_=0xffffffff;
153  lumiSection_ =0;
155  unsigned int* fedSizeAddr;
156  fedSizeAddr=(unsigned int*)((unsigned long)this+fedSizeOffset_);
157  for (unsigned int i=0;i<nFed();i++) *fedSizeAddr++=0;
158 
159  unsigned int* superFragSizeAddr;
160  superFragSizeAddr=(unsigned int*)((unsigned long)this+superFragSizeOffset_);
161  for (unsigned int i=0;i<nSuperFrag();i++) *superFragSizeAddr++=0;
162 
164 }
165 
166 
167 //______________________________________________________________________________
168 void FUShmRawCell::dump() const
169 {
170  for (unsigned int i=0;i<nFed();i++) {
171  cout<<"fed "<<i<<": "<<flush;
172  unsigned char* addr=fedAddr(i);
173  unsigned int size=fedSize(i);
174  cout.fill(0);
175  cout<<setiosflags(ios::right);
176  for (unsigned int j=0;j<size;j++)
177  cout<<setw(2)<<hex<<(int)addr[j]<<dec<<" "<<flush;
178  cout<<endl;
179  }
180 }
181 
182 
183 //______________________________________________________________________________
184 unsigned int FUShmRawCell::readFed(unsigned int i,
185  unsigned char* buffer) const
186 {
187  unsigned int size=fedSize(i);
188  unsigned char* addr=fedAddr(i);
189  memcpy(buffer,addr,size);
190  return size;
191 }
192 
193 
194 //______________________________________________________________________________
195 unsigned char* FUShmRawCell::writeData(unsigned char* data,
196  unsigned int dataSize)
197 {
198  if (payloadPosition_+dataSize>payloadSize_) {
199  cout<<"FUShmRawCell::writeData: data to be written does not fit!"<<endl;
200  return 0;
201  }
202 
203  // result = addr of data to be written *in* the cell
204  unsigned char* result=
205  (unsigned char*)((unsigned long)this+payloadOffset_+payloadPosition_);
206  memcpy(result,data,dataSize);
207  payloadPosition_+=dataSize;
208  return result;
209 }
210 
211 //______________________________________________________________________________
213 {
215 }
216 //______________________________________________________________________________
217 bool FUShmRawCell::markFed(unsigned int i,
218  unsigned int size,
219  unsigned char* addr)
220 {
221  if (i>=nFed())
222  {cout<<"invalid fed index '"<<i<<"'."<<endl; return false; }
223  if (addr<payloadAddr())
224  { cout<<"invalid fed addr '0x"<<hex<<(unsigned long)addr<<dec<<"'."<<endl; return false; }
225 
226  unsigned long offset=(unsigned long)addr-(unsigned long)payloadAddr();
227 
228  if (offset>=payloadSize())
229  { cout<<"invalid fed addr '0x"<<hex<<(unsigned long)addr<<dec<<"'."<<endl; return false; }
230 
231  unsigned int* fedSizeAddr;
232  fedSizeAddr=(unsigned int*)((unsigned long)this+fedSizeOffset_);
233  fedSizeAddr+=i;
234  *fedSizeAddr=size;
235 
236  unsigned int* fedAddr;
237  fedAddr=(unsigned int*)((unsigned long)this+fedOffset_);
238  fedAddr+=i;
239  *fedAddr=offset;
240 
241  return true;
242 }
243 
244 
245 //______________________________________________________________________________
246 bool FUShmRawCell::markSuperFrag(unsigned int i,
247  unsigned int size,
248  unsigned char* addr)
249 {
250  if (i>=nSuperFrag())
251  {cout<<"invalid sf index '"<<i<<"'."<<endl; return false; }
252  if (addr<payloadAddr())
253  {cout<<"invalid sf addr '0x"<<hex<<(unsigned long)addr<<dec<<"'."<<endl;return false;}
254 
255  unsigned int offset=(unsigned long)addr-(unsigned long)payloadAddr();
256 
257  if (offset>=payloadSize())
258  {cout<<"invalid sf addr '0x"<<hex<<(unsigned long)addr<<dec<<"'."<<endl;return false;}
259 
260  unsigned int* superFragSizeAddr;
261  superFragSizeAddr=(unsigned int*)((unsigned long)this+superFragSizeOffset_);
262  superFragSizeAddr+=i;
263  *superFragSizeAddr=size;
264 
265  unsigned int* superFragAddr;
266  superFragAddr=(unsigned int*)((unsigned long)this+superFragOffset_);
267  superFragAddr+=i;
268  *superFragAddr=offset;
269 
270  return true;
271 }
272 
273 
274 //______________________________________________________________________________
275 unsigned int FUShmRawCell::size(unsigned int payloadSize)
276 {
277  return
278  sizeof(FUShmRawCell)+
279  sizeof(unsigned int)*2*(NFED_MAX+NSUPERFRAG_MAX)+
280  sizeof(unsigned char)*payloadSize;
281 }
#define NFED_MAX
Definition: FUShmRawCell.cc:17
int i
Definition: DBlmapReader.cc:9
unsigned int payloadPosition_
Definition: FUShmRawCell.h:95
unsigned int superFragOffset_
Definition: FUShmRawCell.h:93
unsigned char * writeData(unsigned char *data, unsigned int dataSize)
bool markFed(unsigned int i, unsigned int size, unsigned char *addr)
unsigned int eventType_
Definition: FUShmRawCell.h:89
unsigned int nSuperFrag_
Definition: FUShmRawCell.h:87
void dump() const
static unsigned int size(unsigned int payloadSize)
void initialize(unsigned int index)
Definition: FUShmRawCell.cc:75
unsigned char * payloadAddr() const
tuple result
Definition: query.py:137
unsigned char * superFragAddr(unsigned int i) const
int j
Definition: DBlmapReader.cc:9
unsigned int payloadOffset_
Definition: FUShmRawCell.h:94
bool markSuperFrag(unsigned int i, unsigned int size, unsigned char *addr)
unsigned int offset(bool)
unsigned char * fedAddr(unsigned int i) const
Definition: FUShmRawCell.cc:96
unsigned int fedOffset_
Definition: FUShmRawCell.h:91
unsigned int payloadSize() const
Definition: FUShmRawCell.h:30
unsigned int readFed(unsigned int i, unsigned char *buffer) const
unsigned int fuResourceId_
Definition: FUShmRawCell.h:82
unsigned int lumiSection_
Definition: FUShmRawCell.h:88
unsigned int index_
Definition: FUShmRawCell.h:81
unsigned int payloadSize_
Definition: FUShmRawCell.h:85
unsigned int eventSize() const
unsigned int superFragSize(unsigned int i) const
unsigned int superFragSizeOffset_
Definition: FUShmRawCell.h:92
unsigned int fedSizeOffset_
Definition: FUShmRawCell.h:90
unsigned int buResourceId_
Definition: FUShmRawCell.h:83
unsigned int index() const
Definition: FUShmRawCell.h:25
void setLumiSection(unsigned int)
unsigned int nFed() const
Definition: FUShmRawCell.h:33
unsigned int nSuperFrag() const
Definition: FUShmRawCell.h:37
tuple cout
Definition: gather_cfg.py:41
unsigned int fedSize(unsigned int i) const
Definition: FUShmRawCell.cc:84
FUShmRawCell(unsigned int payloadSize)
Definition: FUShmRawCell.cc:29
tuple size
Write out results.
#define NSUPERFRAG_MAX
Definition: FUShmRawCell.cc:16
unsigned int nFed_
Definition: FUShmRawCell.h:86