Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00008
00009
00010 #include "EventFilter/ShmBuffer/interface/FUShmRawCell.h"
00011
00012 #include <iostream>
00013 #include <iomanip>
00014 #include <cstring>
00015
00016 #define NSUPERFRAG_MAX 80
00017 #define NFED_MAX 1024
00018
00019
00020 using namespace std;
00021 using namespace evf;
00022
00023
00025
00027
00028
00029 FUShmRawCell::FUShmRawCell(unsigned int payloadSize)
00030 : payloadSize_(payloadSize)
00031 , nFed_(NFED_MAX)
00032 , nSuperFrag_(NSUPERFRAG_MAX)
00033 , lumiSection_(0)
00034 , eventType_(evt::NOP)
00035 {
00036 fedSizeOffset_=sizeof(FUShmRawCell);
00037 unsigned int* fedSizeAddr;
00038 fedSizeAddr=(unsigned int*)((unsigned long)this+fedSizeOffset_);
00039 new(fedSizeAddr) unsigned int[nFed_];
00040
00041 fedOffset_=fedSizeOffset_+sizeof(unsigned int)*nFed_;
00042 unsigned int* fedAddr;
00043 fedAddr=(unsigned int*)((unsigned long)this+fedOffset_);
00044 new(fedAddr) unsigned int[nFed_];
00045
00046 superFragSizeOffset_=fedOffset_+sizeof(unsigned int)*nFed_;
00047 unsigned int* superFragSizeAddr;
00048 superFragSizeAddr=(unsigned int*)((unsigned long)this+superFragSizeOffset_);
00049 new(superFragSizeAddr) unsigned int[nSuperFrag_];
00050
00051 superFragOffset_=superFragSizeOffset_+sizeof(unsigned int)*nSuperFrag_;
00052 unsigned char* superFragAddr;
00053 superFragAddr=(unsigned char*)((unsigned long)this+superFragOffset_);
00054 new(superFragAddr) unsigned char[nSuperFrag_];
00055
00056 payloadOffset_=superFragOffset_+sizeof(unsigned int)*nSuperFrag_;
00057 unsigned char* payloadAddr;
00058 payloadAddr=(unsigned char*)((unsigned long)this+payloadOffset_);
00059 new(payloadAddr) unsigned char[payloadSize_];
00060 }
00061
00062
00063
00064 FUShmRawCell::~FUShmRawCell()
00065 {
00066
00067 }
00068
00069
00071
00073
00074
00075 void FUShmRawCell::initialize(unsigned int index)
00076 {
00077 index_=index;
00078 lumiSection_=0;
00079 eventType_=evt::NOP;
00080 }
00081
00082
00083
00084 unsigned int FUShmRawCell::fedSize(unsigned int i) const
00085 {
00086 if (i>=nFed()) {cout<<"invalid fed index '"<<i<<"'."<<endl; return 0; }
00087 unsigned int* fedSizeAddr;
00088 fedSizeAddr=(unsigned int*)((unsigned long)this+fedSizeOffset_);
00089 fedSizeAddr+=i;
00090 unsigned int result=*fedSizeAddr;
00091 return result;
00092 }
00093
00094
00095
00096 unsigned char* FUShmRawCell::fedAddr(unsigned int i) const
00097 {
00098 if (i>=nFed()) {cout<<"invalid fed index '"<<i<<"'."<<endl; return 0; }
00099 unsigned int* fedOffsetAddr;
00100 fedOffsetAddr=(unsigned int*)((unsigned long)this+fedOffset_);
00101 fedOffsetAddr+=i;
00102 unsigned int fedOffset=*fedOffsetAddr;
00103 unsigned char* result=(unsigned char*)((unsigned long)payloadAddr()+fedOffset);
00104 return result;
00105 }
00106
00107
00108
00109 unsigned int FUShmRawCell::superFragSize(unsigned int i) const
00110 {
00111 if (i>=nSuperFrag()) {cout<<"invalid sf index '"<<i<<"'."<<endl; return 0; }
00112 unsigned int* superFragSizeAddr;
00113 superFragSizeAddr=(unsigned int*)((unsigned long)this+superFragSizeOffset_);
00114 superFragSizeAddr+=i;
00115 unsigned int result=*superFragSizeAddr;
00116 return result;
00117 }
00118
00119
00120
00121 unsigned char* FUShmRawCell::superFragAddr(unsigned int i) const
00122 {
00123 if (i>=nSuperFrag()) {cout<<"invalid fed index '"<<i<<"'."<<endl; return 0; }
00124 unsigned int* superFragOffsetAddr;
00125 superFragOffsetAddr=(unsigned int*)((unsigned long)this+superFragOffset_);
00126 superFragOffsetAddr+=i;
00127 unsigned int superFragOffset=*superFragOffsetAddr;
00128 unsigned char* result=(unsigned char*)((unsigned long)payloadAddr()+superFragOffset);
00129 return result;
00130 }
00131
00132
00133
00134 unsigned char* FUShmRawCell::payloadAddr() const
00135 {
00136 unsigned char* result=(unsigned char*)((unsigned long)this+payloadOffset_);
00137 return result;
00138 }
00139
00140
00141
00142 unsigned int FUShmRawCell::eventSize() const
00143 {
00144 return payloadPosition_;
00145 }
00146
00147
00148
00149 void FUShmRawCell::clear()
00150 {
00151 fuResourceId_=0xffffffff;
00152 buResourceId_=0xffffffff;
00153 lumiSection_ =0;
00154 eventType_ =evt::NOP;
00155 unsigned int* fedSizeAddr;
00156 fedSizeAddr=(unsigned int*)((unsigned long)this+fedSizeOffset_);
00157 for (unsigned int i=0;i<nFed();i++) *fedSizeAddr++=0;
00158
00159 unsigned int* superFragSizeAddr;
00160 superFragSizeAddr=(unsigned int*)((unsigned long)this+superFragSizeOffset_);
00161 for (unsigned int i=0;i<nSuperFrag();i++) *superFragSizeAddr++=0;
00162
00163 payloadPosition_=0;
00164 }
00165
00166
00167
00168 void FUShmRawCell::dump() const
00169 {
00170 for (unsigned int i=0;i<nFed();i++) {
00171 cout<<"fed "<<i<<": "<<flush;
00172 unsigned char* addr=fedAddr(i);
00173 unsigned int size=fedSize(i);
00174 cout.fill(0);
00175 cout<<setiosflags(ios::right);
00176 for (unsigned int j=0;j<size;j++)
00177 cout<<setw(2)<<hex<<(int)addr[j]<<dec<<" "<<flush;
00178 cout<<endl;
00179 }
00180 }
00181
00182
00183
00184 unsigned int FUShmRawCell::readFed(unsigned int i,
00185 unsigned char* buffer) const
00186 {
00187 unsigned int size=fedSize(i);
00188 unsigned char* addr=fedAddr(i);
00189 memcpy(buffer,addr,size);
00190 return size;
00191 }
00192
00193
00194
00195 unsigned char* FUShmRawCell::writeData(unsigned char* data,
00196 unsigned int dataSize)
00197 {
00198 if (payloadPosition_+dataSize>payloadSize_) {
00199 cout<<"FUShmRawCell::writeData: data to be written does not fit!"<<endl;
00200 return 0;
00201 }
00202
00203
00204 unsigned char* result=
00205 (unsigned char*)((unsigned long)this+payloadOffset_+payloadPosition_);
00206 memcpy(result,data,dataSize);
00207 payloadPosition_+=dataSize;
00208 return result;
00209 }
00210
00211
00212 void FUShmRawCell::setLumiSection(unsigned int ls)
00213 {
00214 lumiSection_=ls;
00215 }
00216
00217 bool FUShmRawCell::markFed(unsigned int i,
00218 unsigned int size,
00219 unsigned char* addr)
00220 {
00221 if (i>=nFed())
00222 {cout<<"invalid fed index '"<<i<<"'."<<endl; return false; }
00223 if (addr<payloadAddr())
00224 { cout<<"invalid fed addr '0x"<<hex<<(unsigned long)addr<<dec<<"'."<<endl; return false; }
00225
00226 unsigned long offset=(unsigned long)addr-(unsigned long)payloadAddr();
00227
00228 if (offset>=payloadSize())
00229 { cout<<"invalid fed addr '0x"<<hex<<(unsigned long)addr<<dec<<"'."<<endl; return false; }
00230
00231 unsigned int* fedSizeAddr;
00232 fedSizeAddr=(unsigned int*)((unsigned long)this+fedSizeOffset_);
00233 fedSizeAddr+=i;
00234 *fedSizeAddr=size;
00235
00236 unsigned int* fedAddr;
00237 fedAddr=(unsigned int*)((unsigned long)this+fedOffset_);
00238 fedAddr+=i;
00239 *fedAddr=offset;
00240
00241 return true;
00242 }
00243
00244
00245
00246 bool FUShmRawCell::markSuperFrag(unsigned int i,
00247 unsigned int size,
00248 unsigned char* addr)
00249 {
00250 if (i>=nSuperFrag())
00251 {cout<<"invalid sf index '"<<i<<"'."<<endl; return false; }
00252 if (addr<payloadAddr())
00253 {cout<<"invalid sf addr '0x"<<hex<<(unsigned long)addr<<dec<<"'."<<endl;return false;}
00254
00255 unsigned int offset=(unsigned long)addr-(unsigned long)payloadAddr();
00256
00257 if (offset>=payloadSize())
00258 {cout<<"invalid sf addr '0x"<<hex<<(unsigned long)addr<<dec<<"'."<<endl;return false;}
00259
00260 unsigned int* superFragSizeAddr;
00261 superFragSizeAddr=(unsigned int*)((unsigned long)this+superFragSizeOffset_);
00262 superFragSizeAddr+=i;
00263 *superFragSizeAddr=size;
00264
00265 unsigned int* superFragAddr;
00266 superFragAddr=(unsigned int*)((unsigned long)this+superFragOffset_);
00267 superFragAddr+=i;
00268 *superFragAddr=offset;
00269
00270 return true;
00271 }
00272
00273
00274
00275 unsigned int FUShmRawCell::size(unsigned int payloadSize)
00276 {
00277 return
00278 sizeof(FUShmRawCell)+
00279 sizeof(unsigned int)*2*(NFED_MAX+NSUPERFRAG_MAX)+
00280 sizeof(unsigned char)*payloadSize;
00281 }