CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/ShmBuffer/src/FUShmRecoCell.cc

Go to the documentation of this file.
00001 
00002 //
00003 // FUShmRecoCell
00004 // -------------
00005 //
00006 //            17/03/2007 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
00008 
00009 
00010 #include "EventFilter/ShmBuffer/interface/FUShmRecoCell.h"
00011 
00012 #include <iostream>
00013 #include <iomanip>
00014 #include <cstring>
00015 
00016 using namespace std;
00017 using namespace evf;
00018 
00019 
00021 // construction/destruction
00023 
00024 //______________________________________________________________________________
00025 FUShmRecoCell::FUShmRecoCell(unsigned int payloadSize)
00026   : payloadSize_(payloadSize)
00027 {
00028   payloadOffset_=sizeof(FUShmRecoCell);
00029   void* payloadAddr=(void*)((unsigned long)this+payloadOffset_);
00030   new (payloadAddr) unsigned char[payloadSize_];
00031 }
00032 
00033 
00034 //______________________________________________________________________________
00035 FUShmRecoCell::~FUShmRecoCell()
00036 {
00037 
00038 }
00039 
00040 
00042 // implementation of member functions
00044 
00045 //______________________________________________________________________________
00046 void FUShmRecoCell::initialize(unsigned int index)
00047 {
00048   index_=index;
00049   clear();
00050 }
00051 
00052 
00053 //______________________________________________________________________________
00054 unsigned char* FUShmRecoCell::payloadAddr() const
00055 {
00056   unsigned char* result=(unsigned char*)((unsigned long)this+payloadOffset_);
00057   return result;
00058 }
00059 
00060 
00061 //______________________________________________________________________________
00062 void FUShmRecoCell::clear()
00063 {
00064   eventSize_=0;
00065   rawCellIndex_=0xffffffff;
00066 }
00067 
00068 
00069 //______________________________________________________________________________
00070 void FUShmRecoCell::writeInitMsg(unsigned int   outModId,
00071                                  unsigned int   fuProcessId,
00072                                  unsigned int   fuGuid,
00073                                  unsigned char *data,
00074                                  unsigned int   dataSize,
00075                                  unsigned int   nExpectedEPs)
00076 {
00077   if (eventSize_!=0)
00078     cout<<"FUShmRecoCell::writeInitMsg() WARNING: overwriting data!"<<endl;
00079   
00080   if (dataSize>payloadSize_) {
00081     cout<<"FUShmRecoCell::writeInitMsg() ERROR: data does not fit!"<<endl;
00082     return;
00083   }
00084   
00085   rawCellIndex_=0xffffffff;
00086   runNumber_   =0xffffffff;
00087   evtNumber_   =0xffffffff;
00088   outModId_    =outModId;
00089   fuProcessId_ =fuProcessId;
00090   fuGuid_      =fuGuid;
00091   type_        =0;
00092   unsigned char* targetAddr=payloadAddr();
00093   memcpy(targetAddr,data,dataSize);
00094   eventSize_=dataSize;
00095   nExpectedEPs_=nExpectedEPs;
00096 }
00097                                   
00098 
00099 //______________________________________________________________________________
00100 void FUShmRecoCell::writeEventData(unsigned int   rawCellIndex,
00101                                    unsigned int   runNumber,
00102                                    unsigned int   evtNumber,
00103                                    unsigned int   outModId,
00104                                    unsigned int   fuProcessId,
00105                                    unsigned int   fuGuid,
00106                                    unsigned char *data,
00107                                    unsigned int   dataSize)
00108 {
00109   if (eventSize_!=0)
00110     cout<<"FUShmRecoCell::writeEventData() WARNING: overwriting data!"<<endl;
00111   
00112   if (dataSize>payloadSize_) {
00113     cout<<"FUShmRecoCell::writeEventData() ERROR: data does not fit!"<<endl;
00114     return;
00115   }
00116   
00117   rawCellIndex_=rawCellIndex;
00118   runNumber_   =runNumber;
00119   evtNumber_   =evtNumber;
00120   outModId_    =outModId;
00121   fuProcessId_ =fuProcessId;
00122   fuGuid_      =fuGuid;
00123   type_        =1;
00124   unsigned char* targetAddr=payloadAddr();
00125   memcpy(targetAddr,data,dataSize);
00126   eventSize_=dataSize;
00127   nExpectedEPs_=0xffffffff;
00128 }
00129                                   
00130 
00131 //______________________________________________________________________________
00132 void FUShmRecoCell::writeErrorEvent(unsigned int   rawCellIndex,
00133                                     unsigned int   runNumber,
00134                                     unsigned int   evtNumber,
00135                                     unsigned int   fuProcessId,
00136                                     unsigned char *data,
00137                                     unsigned int   dataSize)
00138 {
00139   if (eventSize_!=0)
00140     cout<<"FUShmRecoCell::writeEventData() WARNING: overwriting data!"<<endl;
00141   
00142   if (dataSize>payloadSize_) {
00143     cout<<"FUShmRecoCell::writeEventData() ERROR: data does not fit!"<<endl;
00144     return;
00145   }
00146   
00147   rawCellIndex_=rawCellIndex;
00148   runNumber_   =runNumber;
00149   evtNumber_   =evtNumber;
00150   outModId_    =0xffffffff;
00151   fuProcessId_ =fuProcessId;
00152   fuGuid_      =0;
00153   type_        =2;
00154   unsigned char* targetAddr=payloadAddr();
00155   memcpy(targetAddr,data,dataSize);
00156   eventSize_=dataSize;
00157   nExpectedEPs_=0xffffffff;
00158 }
00159                                   
00160 
00161 //______________________________________________________________________________
00162 unsigned int FUShmRecoCell::size(unsigned int payloadSize)
00163 {
00164   return sizeof(FUShmRecoCell)+sizeof(unsigned char)*payloadSize;
00165 }