30 Bool_t TMessage::fgEvolution = kFALSE;
46 TMessage::TMessage(UInt_t what, Int_t bufsiz) :
47 TBufferFile(TBuffer::kWrite, bufsiz + 2*sizeof(UInt_t)),
48 fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
59 fBufCompCur =
nullptr;
64 SetBit(kCannotHandleMemberWiseStreaming);
71 TMessage::TMessage(
void *buf, Int_t bufsize) : TBufferFile(TBuffer::kRead, bufsize, buf),
72 fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
75 fBufCur +=
sizeof(UInt_t);
80 fBufCompCur =
nullptr;
85 if (fWhat & kMESS_ZIP) {
88 fBufCompCur = fBuffer + bufsize;
93 if (fWhat == kMESS_OBJECT) {
96 SetBufferOffset(
sizeof(UInt_t) +
sizeof(fWhat));
106 TMessage::~TMessage()
116 void TMessage::EnableSchemaEvolutionForAll(Bool_t enable)
118 fgEvolution = enable;
124 Bool_t TMessage::UsesSchemaEvolutionForAll()
132 void TMessage::ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t )
134 if (fgEvolution || fEvolution) {
135 if (!fInfos) fInfos =
new TList();
144 void TMessage::Forward()
148 SetBufferOffset(fBufSize);
149 SetBit(kCannotHandleMemberWiseStreaming);
168 void TMessage::TagStreamerInfo(TVirtualStreamerInfo *info)
170 if (fgEvolution || fEvolution) {
171 if (!fInfos) fInfos =
new TList();
179 void TMessage::Reset()
181 SetBufferOffset(
sizeof(UInt_t) +
sizeof(fWhat));
187 fBufCompCur =
nullptr;
191 if (fgEvolution || fEvolution) {
195 fBitsPIDs.ResetAllBits();
202 void TMessage::SetLength()
const
205 char *buf = Buffer();
207 tobuf(buf, (UInt_t)(Length() -
sizeof(UInt_t)));
211 tobuf(buf, (UInt_t)(CompLength() -
sizeof(UInt_t)));
222 void TMessage::SetWhat(UInt_t what)
226 char *buf = Buffer();
228 buf +=
sizeof(UInt_t);
234 buf +=
sizeof(UInt_t);
235 tobuf(buf, what | kMESS_ZIP);
242 void TMessage::SetCompressionAlgorithm(Int_t algorithm)
244 if (algorithm < 0 || algorithm >= ROOT::RCompressionSetting::EAlgorithm::kUndefined) algorithm = 0;
247 newCompress = 100 * algorithm + ROOT::RCompressionSetting::ELevel::kUseMin;
249 int level = fCompress % 100;
250 newCompress = 100 * algorithm + level;
252 if (newCompress != fCompress && fBufComp) {
255 fBufCompCur =
nullptr;
258 fCompress = newCompress;
264 void TMessage::SetCompressionLevel(Int_t level)
266 if (level < 0) level = 0;
267 if (level > 99) level = 99;
272 int algorithm = fCompress / 100;
273 if (algorithm >= ROOT::RCompressionSetting::EAlgorithm::kUndefined) algorithm = 0;
274 newCompress = 100 * algorithm + level;
276 if (newCompress != fCompress && fBufComp) {
279 fBufCompCur =
nullptr;
282 fCompress = newCompress;
288 void TMessage::SetCompressionSettings(Int_t settings)
290 if (settings != fCompress && fBufComp) {
293 fBufCompCur =
nullptr;
296 fCompress = settings;
306 Int_t TMessage::Compress()
308 Int_t compressionLevel = GetCompressionLevel();
309 Int_t compressionAlgorithm = GetCompressionAlgorithm();
310 if (compressionLevel <= 0) {
315 fBufCompCur =
nullptr;
321 if (fBufComp && fCompPos == fBufCur) {
330 fBufCompCur =
nullptr;
334 if (Length() <= (Int_t)(256 + 2*
sizeof(UInt_t))) {
344 Int_t hdrlen = 2*
sizeof(UInt_t);
345 Int_t messlen = Length() - hdrlen;
346 Int_t nbuffers = 1 + (messlen - 1) / kMAXZIPBUF;
347 Int_t chdrlen = 3*
sizeof(UInt_t);
348 Int_t buflen = std::max(512, chdrlen + messlen + 9*nbuffers);
349 fBufComp =
new char[buflen];
350 char *messbuf = Buffer() + hdrlen;
351 char *bufcur = fBufComp + chdrlen;
355 for (Int_t i = 0; i < nbuffers; ++i) {
356 if (i == nbuffers - 1)
357 bufmax = messlen - nzip;
360 R__zipMultipleAlgorithm(compressionLevel, &bufmax, messbuf, &bufmax, bufcur, &nout,
361 static_cast<ROOT::RCompressionSetting::EAlgorithm::EValues>(compressionAlgorithm));
362 if (nout == 0 || nout >= messlen) {
366 fBufCompCur =
nullptr;
372 messbuf += kMAXZIPBUF;
375 fBufCompCur = bufcur;
379 tobuf(bufcur, (UInt_t)(CompLength() -
sizeof(UInt_t)));
380 Int_t what = fWhat | kMESS_ZIP;
382 tobuf(bufcur, Length());
391 Int_t TMessage::Uncompress()
393 if (!fBufComp || !(fWhat & kMESS_ZIP))
397 Int_t hdrlen = 2*
sizeof(UInt_t);
398 char *bufcur1 = fBufComp + hdrlen;
399 frombuf(bufcur1, &buflen);
400 UChar_t *bufcur = (UChar_t*)bufcur1;
404 if(R__unzip_header(&nin, bufcur, &nbuf)!=0) {
405 Error(
"Uncompress",
"Inconsistency found in header (nin=%d, nbuf=%d)", nin, nbuf);
409 fBuffer =
new char[buflen];
411 fBufCur = fBuffer +
sizeof(UInt_t) +
sizeof(fWhat);
412 fBufMax = fBuffer + fBufSize;
413 char *messbuf = fBuffer + hdrlen;
418 Int_t hc = R__unzip_header(&nin, bufcur, &nbuf);
420 R__unzip(&nin, bufcur, &nbuf, (
unsigned char*) messbuf, &nout);
423 if (noutot >= buflen - hdrlen)
break;
440 UShort_t TMessage::WriteProcessID(TProcessID *pid)
442 if (fBitsPIDs.TestBitNumber(0))
return 0;
444 pid = TProcessID::GetPID();
446 fBitsPIDs.SetBitNumber(0);
447 UInt_t uid = pid->GetUniqueID();
448 fBitsPIDs.SetBitNumber(uid+1);