00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00020 #include "RawData/RawDataBlock.h"
00021
00022 #include <cassert>
00023 #include <string.h>
00024
00025 #include "MessageService/MsgService.h"
00026 #include "MessageService/MsgFormat.h"
00027
00028
00029 #include "RawData/RawBlockRegistry.h"
00030 REGISTERRAWBLOCK(RawDataBlock,0,0);
00031
00032 ClassImp(RawDataBlock)
00033
00034
00035
00036 Bool_t RawDataBlock::fgForceHexDump = false;
00037
00038
00039
00040 std::ostream& operator<<(std::ostream& os, const RawDataBlock& r)
00041 { return r.FormatToOStream(os); }
00042
00043
00044 RawDataBlock::RawDataBlock()
00045 : fSize(0), fRawBlock(0)
00046 {
00047
00048 }
00049
00050
00051 RawDataBlock::RawDataBlock(const Int_t *block)
00052 : fSize(0), fRawBlock(0)
00053 {
00054
00055
00056
00057
00058 if ( ! block ) return;
00059
00060 fSize = (*block);
00061
00062 if (fSize > 0) {
00063 fRawBlock = new Int_t [fSize];
00064 memcpy(fRawBlock,block,sizeof(Int_t)*fSize);
00065 } else {
00066 fSize = 0;
00067 }
00068 }
00069
00070
00071 RawDataBlock::RawDataBlock(const RawDataBlock &rhs)
00072 : TObject(rhs), fSize(0), fRawBlock(0)
00073 {
00074
00075
00076
00077
00078 fSize = rhs.GetSize();
00079
00080 if (fSize > 0) {
00081 const Int_t* block = rhs.GetData();
00082 fRawBlock = new Int_t [fSize];
00083 memcpy(fRawBlock,block,sizeof(Int_t)*fSize);
00084 } else {
00085 fSize = 0;
00086 }
00087 }
00088
00089
00090 RawDataBlock::~RawDataBlock()
00091 {
00092 if (fSize > 0) delete [] fRawBlock;
00093 }
00094
00095
00096 RawDataBlock& RawDataBlock::operator=(const RawDataBlock& rhs)
00097 {
00098
00099
00100
00101
00102
00103
00104 if (this == &rhs) return *this;
00105
00106
00107 if (fSize > 0) { delete [] fRawBlock; fRawBlock = 0; }
00108
00109 fSize = rhs.GetSize();
00110
00111 if (fSize > 0) {
00112 const Int_t* block = rhs.GetData();
00113 fRawBlock = new Int_t [fSize];
00114 memcpy(fRawBlock,block,sizeof(Int_t)*fSize);
00115 } else {
00116 fSize = 0;
00117 }
00118
00119 return *this;
00120 }
00121
00122 Int_t* RawDataBlock::AppendToBuffer(Int_t *bstart) const
00123 {
00124
00125 memcpy(bstart,fRawBlock,sizeof(Int_t)*fSize);
00126 Int_t *buff_end = bstart + fSize;
00127 return buff_end;
00128 }
00129
00130
00131 void RawDataBlock::Print(Option_t *option) const
00132 {
00133 FormatToOStream(cout,option);
00134 }
00135
00136
00137 std::ostream& RawDataBlock::FormatToOStream(std::ostream& os,
00138 Option_t *option) const
00139 {
00140
00141
00142
00143 RawBlockId rbid = GetBlockId();
00144
00145 os << GetName()
00146 << " size=" << fSize
00147 << endl
00148 << " checksum=0x"
00149 << hex << setw(8) << setfill('0')
00150 << GetChecksum() << setfill(' ') << dec
00151 << ((TestChecksum()) ? " (error)" : " (okay)")
00152 << endl
00153 << " " << rbid.AsString()
00154 << " 0x" << hex << setw(8) << setfill('0')
00155 << rbid.GetEncoded() << setfill(' ') << dec
00156 << endl;
00157
00158 Bool_t inhex = (strchr(option,'x')!=0 || strchr(option,'X')!=0);
00159
00160 if ( fSize>0 && ( inhex || fgForceHexDump ) ) {
00161
00162 os << hex << setfill('0');
00163
00164
00165
00166
00167 Int_t ncol = 4;
00168 Int_t ncol_last = (fSize+ncol-1)%ncol + 1;
00169 Bool_t lastmatch = false;
00170 Bool_t lastline = false;
00171 Int_t *next_word = fRawBlock;
00172 Int_t nfull_lines = fSize/ncol;
00173 if (ncol_last == ncol) nfull_lines--;
00174 Int_t *start_last = fRawBlock + ncol*nfull_lines;
00175 Int_t nbytes = 0;
00176
00177 while (next_word < fRawBlock+fSize) {
00178
00179 if (next_word == start_last) {
00180 lastline = true;
00181 ncol = ncol_last;
00182 }
00183
00184 Int_t *prev = next_word - ncol;
00185 if (prev >= fRawBlock && !lastline ) {
00186
00187 Bool_t linematch = true;
00188 Int_t *chek = next_word;
00189 for (int i=0; i<ncol; i++)
00190 linematch = ( *prev++ == *chek++ ) ? linematch : false;
00191 if (linematch) {
00192 next_word += ncol;
00193 nbytes += sizeof(Int_t)*ncol;
00194 if (!lastmatch) {
00195
00196
00197 os << " *\n";
00198 }
00199 lastmatch = true;
00200 continue;
00201 }
00202 else lastmatch = false;
00203
00204 }
00205
00206 os << "0x" << setw(6) << nbytes << ":";
00207
00208 for (int i=0; i<ncol; i++) {
00209 os << " " << setw(8) << *next_word;
00210 next_word++;
00211 nbytes += sizeof(Int_t);
00212 }
00213
00214 os << "\n";
00215 }
00216
00217 }
00218
00219
00220 os << setfill(' ') << dec;
00221 return os;
00222 }
00223
00224