73#if !defined(_MSC_VER) || (_MSC_VER>1300)
84bool CheckKeyObjLenOverflow(
const char *methodName,
Int_t keyLen,
Int_t objLen)
86 constexpr auto maxInt_t = std::numeric_limits<Int_t>::max();
87 if (keyLen > (maxInt_t - objLen)) {
88 Error(methodName,
"fObjlen (%d) + fKeylen (%d) > max int (%d): cannot continue to read the key buffer.", objLen,
113 Build(motherDir,
"", 0);
145 UInt_t bufferDecOffset = 0;
146 UInt_t bufferIncOffset = 0;
153 alloc += bufferIncOffset;
166 if(
f->ReadBuffer(
fBuffer+bufferIncOffset,nsize) )
168 Error(
"ReadFile",
"Failed to read data.");
172 std::cout <<
"TKey Reading "<<nsize<<
" bytes at address "<<
fSeekKey<<std::endl;
189 Build(motherDir,
"", pointer);
241 Warning(
"TKey",
"since %s has no public constructor\n"
242 "\twhich can be called without argument, objects of this class\n"
243 "\tcan not be read with the current library. You will need to\n"
244 "\tadd a default constructor before attempting to read it.",
250 Int_t lbuf, nout, noutot, bufmax, nzip;
264 if (cxlevel > 0 &&
fObjlen > 256) {
265 const auto blocks = ROOT::Internal::GetZipBlocks(
fObjlen);
266 const Int_t nbuffers = blocks.fNBlocks;
267 const Int_t blockSize = blocks.fBlockSize;
274 for (
Int_t i = 0; i < nbuffers; ++i) {
275 if (i == nbuffers - 1)
279 R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm);
280 if (nout == 0 || nout >=
fObjlen) {
319 Warning(
"TKey",
"since %s has no public constructor\n"
320 "\twhich can be called without argument, objects of this class\n"
321 "\tcan not be read with the current library. You will need to\n"
322 "\tadd a default constructor before attempting to read it.",
327 const void* actualStart;
329 const char *temp = (
const char*) obj;
338 clActual =
const_cast<TClass*
>(cl);
350 Int_t lbuf, nout, noutot, bufmax, nzip;
363 if (cxlevel > 0 &&
fObjlen > 256) {
364 const auto blocks = ROOT::Internal::GetZipBlocks(
fObjlen);
365 const Int_t nbuffers = blocks.fNBlocks;
366 const Int_t blockSize = blocks.fBlockSize;
373 for (
Int_t i = 0; i < nbuffers; ++i) {
374 if (i == nbuffers - 1)
378 R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm);
379 if (nout == 0 || nout >=
fObjlen) {
413 auto objbuf =
reinterpret_cast<unsigned char *
>(targetBuffer) +
fKeylen;
414 auto bufcur =
reinterpret_cast<const unsigned char *
>(&compressedBuffer[
fKeylen]);
415 Int_t nin, nout = 0, nbuf;
419 while (nbytesRemain >= ROOT::Internal::kZipHeaderSize) {
420 Int_t hc = R__unzip_header(&nin, bufcur, &nbuf);
421 if ((hc != 0) || (nin > nbytesRemain) || (nbuf > objlenRemain))
423 R__unzip(&nin, bufcur, &nbuf, objbuf, &nout);
432 objlenRemain -= nout;
520 Error(
"Create",
"Cannot create key without file");
525 TList *lfree =
f->GetListOfFree();
529 TFree *bestfree =
f1->GetBestFree(lfree,nsize);
531 Error(
"Create",
"Cannot allocate %d bytes for ID = %s Title = %s",
545 if (
f->GetEND() > bestfree->
GetLast()) {
569 tobuf(buffer, nbytesleft);
599 printf(
"Rejected attempt to delete TDirectoryFile key: %s at address %lld, nbytes = %d\n",
649 return ((
fCycle >0) ? 0 : 1);
659 tobuf(buffer, version);
752 std::cout << (current ?
" [current cycle]" :
" [backup cycle]");
753 std::cout <<std::endl;
825 if (!bufferRef.
Buffer()) {
826 Error(
"ReadObj",
"Cannot allocate buffer: fObjlen = %d",
fObjlen);
833 std::unique_ptr<char []> compressedBuffer;
836 compressedBuffer.reset(
new char[
fNbytes]);
837 fBuffer = compressedBuffer.get();
862 char *pobj = (
char*)cl->
New();
868 if (baseOffset==-1) {
872 Fatal(
"ReadObj",
"Incorrect detection of the inheritance from TObject for class %s.\n",
875 tobj = (
TObject*)(pobj+baseOffset);
881 compressedBuffer.reset(
nullptr);
947 if (!bufferRef.
Buffer()) {
948 Error(
"ReadObjWithBuffer",
"Cannot allocate buffer: fObjlen = %d",
fObjlen);
973 char *pobj = (
char*)cl->
New();
979 if (baseOffset==-1) {
983 Fatal(
"ReadObjWithBuffer",
"Incorrect detection of the inheritance from TObject for class %s.\n",
986 tobj = (
TObject*)(pobj+baseOffset);
1054 if (!bufferRef.
Buffer()) {
1055 Error(
"ReadObj",
"Cannot allocate buffer: fObjlen = %d",
fObjlen);
1062 std::unique_ptr<char []> compressedBuffer;
1065 compressedBuffer.reset(
new char[
fNbytes]);
1066 fBuffer = compressedBuffer.get();
1086 Int_t baseOffset = 0;
1087 if (expectedClass) {
1090 if (baseOffset == -1) {
1101 cl =
const_cast<TClass*
>(expectedClass);
1103 Info(
"ReadObjectAny",
"Using Converter StreamerInfo from %s to %s", clOnfile->
GetName(),
1109 "Trying to read an emulated class (%s) to store in a compiled pointer (%s)",
1115 void *pobj = cl->
New();
1127 cl->
Streamer((
void*)pobj, bufferRef, clOnfile);
1133 cl->
Streamer((
void*)pobj, bufferRef, clOnfile);
1138 if (tobjBaseOffset == -1) {
1139 Fatal(
"ReadObj",
"Incorrect detection of the inheritance from TObject for class %s.\n",
1164 return ( ((
char*)pobj) + baseOffset );
1176 if (!obj || (
GetFile()==0))
return 0;
1185 std::unique_ptr<char []> compressedBuffer;
1188 compressedBuffer.reset(
new char[
fNbytes]);
1189 fBuffer = compressedBuffer.get();
1239 Error(
"ReadKeyBuffer",
"The value of fNbytes is negative (%d): cannot continue to read the key buffer.",
fNbytes);
1249 Error(
"ReadKeyBuffer",
"The value of fObjlen is negative (%d): cannot continue to read the key buffer.",
fObjlen);
1257 Error(
"ReadKeyBuffer",
"The value of fKeylen is negative (%d): cannot continue to read the key buffer.",
fKeylen);
1264 Error(
"ReadKeyBuffer",
"fNbytes (%d) < fKeylen (%d): cannot continue to read the key buffer.",
fNbytes,
fKeylen);
1316 std::size_t fRemainingBufSize;
1317 [[nodiscard]]
bool operator()(std::size_t additionalBytesNeeded) {
1318 if (
R__unlikely(additionalBytesNeeded > fRemainingBufSize)) {
1319 fOuter->
Error(
"ReadKeyBuffer",
"The given buffer is too small to fit this TKey.");
1323 fRemainingBufSize -= additionalBytesNeeded;
1326 } ConsumeBufCapacity{
this, bufsize};
1329 constexpr std::size_t kMinBufSize =
1331 if (!ConsumeBufCapacity(kMinBufSize))
1336 Error(
"ReadKeyBuffer",
"The value of fNbytes is negative (%d): cannot continue to read the key buffer.",
fNbytes);
1346 Error(
"ReadKeyBuffer",
"The value of fObjlen is negative (%d): cannot continue to read the key buffer.",
fObjlen);
1354 Error(
"ReadKeyBuffer",
"The value of fKeylen is negative (%d): cannot continue to read the key buffer.",
fKeylen);
1361 Error(
"ReadKeyBuffer",
"fNbytes (%d) < fKeylen (%d): cannot continue to read the key buffer.",
fNbytes,
fKeylen);
1366 constexpr auto maxInt_t = std::numeric_limits<Int_t>::max();
1368 Error(
"ReadKeyBuffer",
"fObjlen (%d) + fKeylen (%d) > max int (%d): cannot continue to read the key buffer.",
fObjlen,
fKeylen, maxInt_t);
1395 if (!ConsumeBufCapacity(2 *
sizeof(
UInt_t)))
1410 ConsumeBufCapacity.fRemainingBufSize -= nRead;
1418 nRead =
fName.
ReadBuffer(buffer, ConsumeBufCapacity.fRemainingBufSize);
1423 ConsumeBufCapacity.fRemainingBufSize -= nRead;
1445 Error(
"ReadFile",
"Failed to read data.");
1449 std::cout <<
"TKey Reading "<<nsize<<
" bytes at address "<<
fSeekKey<<std::endl;
1524 if (
b.IsReading()) {
1559 Error(
"Streamer",
"The value of fKeylen is incorrect (%d) ; trying to recover by setting it to zero",
fKeylen);
1564 Error(
"Streamer",
"The value of fObjlen is incorrect (%d) ; trying to recover by setting it to zero",
fObjlen);
1569 Error(
"Streamer",
"The value of fNbytes is incorrect (%d) ; trying to recover by setting it to zero",
fNbytes);
1641 std::cout <<
" TKey Writing "<<nsize<<
" bytes at address "<<
fSeekKey
1668 std::cout <<
" TKey Writing "<<nsize<<
" bytes at address "<<
fSeekKey
1692 ret =
fTitle(start, stop - start);
void frombuf(char *&buf, Bool_t *x)
void tobuf(char *&buf, Bool_t x)
#define R__unlikely(expr)
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short)
int Int_t
Signed integer 4 bytes (int)
short Version_t
Class version identifier (short)
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
short Short_t
Signed Short integer 2 bytes (short)
long long Long64_t
Portable signed long integer 8 bytes.
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
const char Option_t
Option string (const char)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
const ULong64_t kPidOffsetMask
static const TString gTDirectoryString("TDirectory")
std::atomic< UInt_t > keyAbsNumber
const UChar_t kPidOffsetShift
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Bool_t HasRuleWithSourceClass(const TString &source) const
Return True if we have any rule whose source class is 'source'.
Using a TBrowser one can browse all ROOT objects.
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr) override
Read class version from I/O buffer.
void MapObject(const TObject *obj, UInt_t offset=1) override
Add object to the fMap container.
void SetPidOffset(UShort_t offset) override
This offset is used when a key (or basket) is transferred from one file to the other.
Buffer base class used for serializing objects.
void SetParent(TObject *parent)
Set parent owning this buffer.
void SetBufferOffset(Int_t offset=0)
virtual void MapObject(const TObject *obj, UInt_t offset=1)=0
TClass instances represent classes, structs and namespaces in the ROOT type system.
void Streamer(void *obj, TBuffer &b, const TClass *onfile_class=nullptr) const
void Browse(TBrowser *b) override
This method is called by a browser to get the class information.
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
void * DynamicCast(const TClass *base, void *obj, Bool_t up=kTRUE)
Cast obj of this class type up to baseclass cl if up is true.
ROOT::DirAutoAdd_t GetDirectoryAutoAdd() const
Return the wrapper around the directory auto add function.
const ROOT::Detail::TSchemaRuleSet * GetSchemaRules() const
Return the set of the schema rules if any.
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Int_t GetBaseClassOffset(const TClass *toBase, void *address=nullptr, bool isDerivedObject=true)
Bool_t HasDefaultConstructor(Bool_t testio=kFALSE) const
Return true if we have access to a constructor usable for I/O.
TClass * GetActualClass(const void *object) const
Return a pointer to the real class of the object.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
UInt_t Get() const
Return raw date/time as encoded by TDatime.
void FillBuffer(char *&buffer)
Encode Date/Time into buffer, used by I/O system.
virtual void Streamer(TBuffer &)
Stream a object of type TDatime.
void Set()
Set Date/Time to current time as reported by the system.
void ReadBuffer(char *&buffer)
Decode Date/Time from output buffer, used by I/O system.
A ROOT file is structured in Directories (like a file system).
Long64_t GetSeekDir() const override
Describe directory structure in memory.
virtual Long64_t GetSeekDir() const
virtual TList * GetList() const
virtual Int_t AppendKey(TKey *)
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
virtual TFile * GetFile() const
void SetName(const char *newname) override
Set the name for directory If the directory name is changed after the directory was written once,...
virtual void SetMother(TObject *mother)
virtual TList * GetListOfKeys() const
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Int_t GetCompressionLevel() const
virtual Long64_t GetEND() const
virtual void MakeFree(Long64_t first, Long64_t last)
Mark unused bytes on the file.
Int_t GetCompressionAlgorithm() const
void SetFirst(Long64_t first)
void SetLast(Long64_t last)
Long64_t GetFirst() const
Book space in a file, create I/O buffers, to fill them, (un)compress them.
const char * GetTitle() const override
Returns title (title can contain 32x32 xpm thumbnail/icon).
static constexpr Version_t Class_Version()
void Delete(Option_t *option="") override
Delete an object from the file.
Int_t Sizeof() const override
Return the size in bytes of the key header structure.
TKey()
TKey default constructor.
~TKey() override
TKey default destructor.
TFile * GetFile() const
Returns file to which key belong.
virtual void Keep()
Set the "KEEP" status.
const char * GetIconName() const override
Title can keep 32x32 xpm thumbnail/icon of the parent object.
Int_t Read(const char *name) override
Read contents of object with specified name from the current directory.
Int_t UnzipBuffer(char *targetBuffer, const char *compressedBuffer) const
Core of uncompressing the key payload.
TDatime fDatime
Date/Time of insertion in file.
TBuffer * fBufferRef
Pointer to the TBuffer object.
UShort_t fPidOffset
!Offset to be added to the pid index in this key/buffer. This is actually saved in the high bits of f...
virtual void IncrementPidOffset(UShort_t offset)
Increment fPidOffset by 'offset'.
Short_t GetKeep() const
Returns the "KEEP" status.
Int_t fVersion
Key version identifier.
Bool_t IsFolder() const override
Check if object referenced by the key is a folder.
Int_t fLeft
Number of bytes left in current segment.
virtual const char * GetClassName() const
Short_t fKeylen
Number of bytes for the key itself.
virtual Bool_t ReadFile()
Read the key structure from the file.
void Browse(TBrowser *b) override
Read object from disk and call its Browse() method.
virtual Int_t WriteFileKeepBuffer(TFile *f=nullptr)
Write the encoded object supported by this key.
Long64_t fSeekKey
Location of object on file.
void Build(TDirectory *motherDir, const char *classname, Long64_t filepos)
Method used in all TKey constructor to initialize basic data fields.
char * fBuffer
Object buffer.
Long64_t fSeekPdir
Location of parent directory on file.
virtual void SetParent(const TObject *parent)
Set parent in key buffer.
virtual void * ReadObjectAny(const TClass *expectedClass)
To read an object (non deriving from TObject) from the file.
void ReadKeyBuffer(char *&buffer)
Decode input buffer.
Int_t fNbytes
Number of bytes for the whole key on file (key header and data)
Int_t fObjlen
Length of uncompressed object in bytes.
void Reset()
Reset the key as it had not been 'filled' yet.
Short_t fCycle
Cycle number.
virtual TObject * ReadObjWithBuffer(char *bufferRead)
To read a TObject* from bufferRead.
virtual void ls(Bool_t current) const
List Key contents.
Short_t GetCycle() const
Return cycle number associated to this key.
virtual TObject * ReadObj()
To read a TObject* from the file.
virtual void Create(Int_t nbytes, TFile *f=nullptr)
Create a TKey object of specified size.
virtual void DeleteBuffer()
Delete key buffer(s).
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=nullptr)
Write the encoded object supported by this key.
virtual void ReadBuffer(char *&buffer)
Decode input buffer.
TDirectory * fMotherDir
!pointer to mother directory
TString fClassName
Object Class name.
void Print(Option_t *option="") const override
Print key contents.
void FillBuffer(char *&buffer) override
Encode key header into output buffer.
void Streamer(TBuffer &) override
Stream a class object.
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
TObject * Remove(TObject *obj) override
Remove object from the list.
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
The TNamed class is the base class for all named ROOT classes.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
Mother of all ROOT objects.
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void UseCurrentStyle()
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyl...
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Delete(Option_t *option="")
Delete this object.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
virtual TClass * IsA() const
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
const char * Data() const
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
virtual void FillBuffer(char *&buffer) const
Copy string into I/O buffer.
virtual void Streamer(TBuffer &)
Stream a string object.
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
virtual void ReadBuffer(char *&buffer)
Read string from I/O buffer.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
void(* DirAutoAdd_t)(void *, TDirectory *)
EValues
Note: this is only temporarily a struct and will become a enum class hence the name convention used.