72const Int_t kMAXFILEBUFFER = 262144;
75#if !defined(_MSC_VER) || (_MSC_VER>1300)
104 Build(motherDir,
"", 0);
136 UInt_t bufferDecOffset = 0;
137 UInt_t bufferIncOffset = 0;
144 alloc += bufferIncOffset;
157 if(
f->ReadBuffer(
fBuffer+bufferIncOffset,nsize) )
159 Error(
"ReadFile",
"Failed to read data.");
163 std::cout <<
"TKey Reading "<<nsize<<
" bytes at address "<<
fSeekKey<<std::endl;
180 Build(motherDir,
"", pointer);
231 if (!obj->IsA()->HasDefaultConstructor()) {
232 Warning(
"TKey",
"since %s has no public constructor\n"
233 "\twhich can be called without argument, objects of this class\n"
234 "\tcan not be read with the current library. You will need to\n"
235 "\tadd a default constructor before attempting to read it.",
241 Int_t lbuf, nout, noutot, bufmax, nzip;
255 if (cxlevel > 0 &&
fObjlen > 256) {
263 for (
Int_t i = 0; i < nbuffers; ++i) {
264 if (i == nbuffers - 1) bufmax =
fObjlen - nzip;
265 else bufmax = kMAXZIPBUF;
266 R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm);
267 if (nout == 0 || nout >=
fObjlen) {
276 objbuf += kMAXZIPBUF;
305 Warning(
"TKey",
"since %s has no public constructor\n"
306 "\twhich can be called without argument, objects of this class\n"
307 "\tcan not be read with the current library. You will need to\n"
308 "\tadd a default constructor before attempting to read it.",
313 const void* actualStart;
315 const char *temp = (
const char*) obj;
317 Int_t offset = (cl != clActual) ?
324 clActual =
const_cast<TClass*
>(cl);
337 Int_t lbuf, nout, noutot, bufmax, nzip;
346 if (cxlevel > 0 &&
fObjlen > 256) {
354 for (
Int_t i = 0; i < nbuffers; ++i) {
355 if (i == nbuffers - 1) bufmax =
fObjlen - nzip;
356 else bufmax = kMAXZIPBUF;
357 R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm);
358 if (nout == 0 || nout >=
fObjlen) {
367 objbuf += kMAXZIPBUF;
466 Error(
"Create",
"Cannot create key without file");
471 TList *lfree =
f->GetListOfFree();
475 TFree *bestfree =
f1->GetBestFree(lfree,nsize);
477 Error(
"Create",
"Cannot allocate %d bytes for ID = %s Title = %s",
491 if (
f->GetEND() > bestfree->
GetLast()) {
515 tobuf(buffer, nbytesleft);
544 if (option && option[0] ==
'v')
545 printf(
"Rejected attempt to delete TDirectoryFile key: %s at address %lld, nbytes = %d\n",
549 if (option && option[0] ==
'v') printf(
"Deleting key: %s at address %lld, nbytes = %d\n",
GetName(),
fSeekKey,
fNbytes);
595 return ((
fCycle >0) ? 0 : 1);
605 tobuf(buffer, version);
751 if (!bufferRef.
Buffer()) {
752 Error(
"ReadObj",
"Cannot allocate buffer: fObjlen = %d",
fObjlen);
759 std::unique_ptr<char []> compressedBuffer;
762 compressedBuffer.reset(
new char[
fNbytes]);
763 fBuffer = compressedBuffer.get();
788 char *pobj = (
char*)cl->
New();
794 if (baseOffset==-1) {
798 Fatal(
"ReadObj",
"Incorrect detection of the inheritance from TObject for class %s.\n",
801 tobj = (
TObject*)(pobj+baseOffset);
808 Int_t nin, nout = 0, nbuf;
813 R__unzip(&nin, bufcur, &nbuf, (
unsigned char*) objbuf, &nout);
820 compressedBuffer.reset(
nullptr);
822 tobj->Streamer(bufferRef);
830 tobj->Streamer(bufferRef);
886 if (!bufferRef.
Buffer()) {
887 Error(
"ReadObjWithBuffer",
"Cannot allocate buffer: fObjlen = %d",
fObjlen);
912 char *pobj = (
char*)cl->
New();
918 if (baseOffset==-1) {
922 Fatal(
"ReadObjWithBuffer",
"Incorrect detection of the inheritance from TObject for class %s.\n",
925 tobj = (
TObject*)(pobj+baseOffset);
933 Int_t nin, nout = 0, nbuf;
938 R__unzip(&nin, bufcur, &nbuf, (
unsigned char*) objbuf, &nout);
946 tobj->Streamer(bufferRef);
954 tobj->Streamer(bufferRef);
1006 if (!bufferRef.
Buffer()) {
1007 Error(
"ReadObj",
"Cannot allocate buffer: fObjlen = %d",
fObjlen);
1014 std::unique_ptr<char []> compressedBuffer;
1017 compressedBuffer.reset(
new char[
fNbytes]);
1018 fBuffer = compressedBuffer.get();
1038 Int_t baseOffset = 0;
1039 if (expectedClass) {
1042 if (baseOffset == -1) {
1053 cl =
const_cast<TClass*
>(expectedClass);
1054 Info(
"ReadObjectAny",
"Using Converter StreamerInfo from %s to %s",clOnfile->
GetName(),expectedClass->
GetName());
1059 "Trying to read an emulated class (%s) to store in a compiled pointer (%s)",
1065 void *pobj = cl->
New();
1077 Int_t nin, nout = 0, nbuf;
1082 R__unzip(&nin, bufcur, &nbuf, (
unsigned char*) objbuf, &nout);
1090 cl->
Streamer((
void*)pobj, bufferRef, clOnfile);
1096 cl->
Streamer((
void*)pobj, bufferRef, clOnfile);
1101 if (tobjBaseOffset == -1) {
1102 Fatal(
"ReadObj",
"Incorrect detection of the inheritance from TObject for class %s.\n",
1127 return ( ((
char*)pobj) + baseOffset );
1139 if (!obj || (
GetFile()==0))
return 0;
1148 std::unique_ptr<char []> compressedBuffer;
1151 compressedBuffer.reset(
new char[
fNbytes]);
1152 fBuffer = compressedBuffer.get();
1165 Int_t nin, nout = 0, nbuf;
1170 R__unzip(&nin, bufcur, &nbuf, (
unsigned char*) objbuf, &nout);
1177 if (nout) obj->Streamer(bufferRef);
1179 obj->Streamer(bufferRef);
1261 for (
Int_t i = 0; i < nsize; i += kMAXFILEBUFFER) {
1262 int nb = kMAXFILEBUFFER;
1263 if (i+nb > nsize) nb = nsize - i;
1269 Error(
"ReadFile",
"Failed to read data.");
1274 std::cout <<
"TKey Reading "<<nsize<<
" bytes at address "<<
fSeekKey<<std::endl;
1344 if (
b.IsReading()) {
1379 Error(
"Streamer",
"The value of fKeylen is incorrect (%d) ; trying to recover by setting it to zero",
fKeylen);
1384 Error(
"Streamer",
"The value of fObjlen is incorrect (%d) ; trying to recover by setting it to zero",
fObjlen);
1389 Error(
"Streamer",
"The value of fNbytes is incorrect (%d) ; trying to recover by setting it to zero",
fNbytes);
1454 for (
Int_t i=0;i<nsize;i+=kMAXFILEBUFFER) {
1455 Int_t nb = kMAXFILEBUFFER;
1456 if (i+nb > nsize) nb = nsize - i;
1457 f->WriteBuffer(buffer,nb);
1461 Bool_t result =
f->WriteBuffer(buffer,nsize);
1466 std::cout <<
" TKey Writing "<<nsize<<
" bytes at address "<<
fSeekKey
1471 return result==
kTRUE ? -1 : nsize;
1490 for (
Int_t i=0;i<nsize;i+=kMAXFILEBUFFER) {
1491 Int_t nb = kMAXFILEBUFFER;
1492 if (i+nb > nsize) nb = nsize - i;
1493 f->WriteBuffer(buffer,nb);
1497 Bool_t result =
f->WriteBuffer(buffer,nsize);
1502 std::cout <<
" TKey Writing "<<nsize<<
" bytes at address "<<
fSeekKey
1506 return result==
kTRUE ? -1 : nsize;
1526 ret =
fTitle(start, stop - start);
void frombuf(char *&buf, Bool_t *x)
void tobuf(char *&buf, Bool_t x)
unsigned long long ULong64_t
const ULong64_t kPidOffsetMask
static const TString gTDirectoryString("TDirectory")
std::atomic< UInt_t > keyAbsNumber
const UChar_t kPidOffsetShift
void R__unzip(Int_t *nin, UChar_t *bufin, Int_t *lout, char *bufout, Int_t *nout)
int R__unzip_header(Int_t *nin, UChar_t *bufin, Int_t *lout)
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 transfered 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 * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
virtual void Browse(TBrowser *b)
This method is called by a browser to get the class information.
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
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.
Int_t GetBaseClassOffset(const TClass *toBase, void *address=0, bool isDerivedObject=true)
Bool_t HasDefaultConstructor(Bool_t testio=kFALSE) const
void Streamer(void *obj, TBuffer &b, const TClass *onfile_class=0) const
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
TClass * GetActualClass(const void *object) const
Return a pointer the 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.
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 ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
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.
virtual void Print(Option_t *option="") const
Print key contents.
virtual void FillBuffer(char *&buffer)
Encode key header into output buffer.
TKey()
TKey default constructor.
virtual void Delete(Option_t *option="")
Delete an object from the file.
TFile * GetFile() const
Returns file to which key belong.
virtual void Keep()
Set the "KEEP" status.
virtual Int_t WriteFileKeepBuffer(TFile *f=0)
Write the encoded object supported by this key.
virtual const char * GetIconName() const
Title can keep 32x32 xpm thumbnail/icon of the parent object.
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
virtual void ls(Option_t *option="") const
List Key contents.
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.
virtual ~TKey()
TKey default destructor.
Int_t fLeft
Number of bytes left in current segment.
virtual const char * GetClassName() const
virtual void Create(Int_t nbytes, TFile *f=0)
Create a TKey object of specified size.
virtual const char * GetTitle() const
Returns title (title can contain 32x32 xpm thumbnail/icon).
Short_t fKeylen
Number of bytes for the key itself.
virtual Bool_t ReadFile()
Read the key structure from the file.
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=0)
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.
Bool_t IsFolder() const
Check if object referenced by the key is a folder.
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 object on file.
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.
Short_t GetCycle() const
Return cycle number associated to this key.
virtual TObject * ReadObj()
To read a TObject* from the file.
virtual void DeleteBuffer()
Delete key buffer(s).
virtual Int_t Sizeof() const
Return the size in bytes of the key header structure.
virtual void ReadBuffer(char *&buffer)
Decode input buffer.
TDirectory * fMotherDir
!pointer to mother directory
virtual void Browse(TBrowser *b)
Read object from disk and call its Browse() method.
TString fClassName
Object Class name.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
virtual TObject * First() const
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.
virtual const char * GetName() const
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 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 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 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 *)
Short_t Max(Short_t a, Short_t b)
EValues
Note: this is only temporarily a struct and will become a enum class hence the name.