71 const Int_t kMAXFILEBUFFER = 262144;
74 #if !defined(_MSC_VER) || (_MSC_VER>1300)
77 const ULong64_t kPidOffsetMask = 0xffffffffffffUL;
106 Build(motherDir,
"", 0);
138 UInt_t bufferDecOffset = 0;
139 UInt_t bufferIncOffset = 0;
143 fNbytes -= bufferDecOffset;
144 }
else if (fKeylen > orig.
fKeylen) {
145 bufferIncOffset = fKeylen - orig.
fKeylen;
146 alloc += bufferIncOffset;
147 fNbytes += bufferIncOffset;
161 Error(
"ReadFile",
"Failed to read data.");
165 std::cout <<
"TKey Reading "<<nsize<<
" bytes at address "<<fSeekKey<<std::endl;
182 Build(motherDir,
"", pointer);
229 :
TNamed(name, obj->GetTitle())
233 if (!obj->IsA()->HasDefaultConstructor()) {
234 Warning(
"TKey",
"since %s has no public constructor\n"
235 "\twhich can be called without argument, objects of this class\n"
236 "\tcan not be read with the current library. You will need to\n"
237 "\tadd a default constructor before attempting to read it.",
243 Int_t lbuf, nout, noutot, bufmax, nzip;
257 if (cxlevel > 0 && fObjlen > 256) {
258 Int_t nbuffers = 1 + (fObjlen - 1)/kMAXZIPBUF;
265 for (
Int_t i = 0; i < nbuffers; ++i) {
266 if (i == nbuffers - 1) bufmax = fObjlen - nzip;
267 else bufmax = kMAXZIPBUF;
268 R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm);
269 if (nout == 0 || nout >= fObjlen) {
278 objbuf += kMAXZIPBUF;
302 :
TNamed(name,
"object title")
307 Warning(
"TKey",
"since %s has no public constructor\n"
308 "\twhich can be called without argument, objects of this class\n"
309 "\tcan not be read with the current library. You will need to\n"
310 "\tadd a default constructor before attempting to read it.",
315 const void* actualStart;
317 const char *temp = (
const char*) obj;
326 clActual =
const_cast<TClass*
>(cl);
333 fBufferRef->SetParent(
GetFile());
336 Streamer(*fBufferRef);
337 fKeylen = fBufferRef->Length();
339 Int_t lbuf, nout, noutot, bufmax, nzip;
341 fBufferRef->MapObject(actualStart,clActual);
342 clActual->
Streamer((
void*)actualStart, *fBufferRef);
343 lbuf = fBufferRef->Length();
348 if (cxlevel > 0 && fObjlen > 256) {
349 Int_t nbuffers = 1 + (fObjlen - 1)/kMAXZIPBUF;
352 char *objbuf = fBufferRef->Buffer() +
fKeylen;
356 for (
Int_t i = 0; i < nbuffers; ++i) {
357 if (i == nbuffers - 1) bufmax = fObjlen - nzip;
358 else bufmax = kMAXZIPBUF;
359 R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm);
360 if (nout == 0 || nout >= fObjlen) {
361 fBuffer = fBufferRef->Buffer();
363 fBufferRef->SetBufferOffset(0);
364 Streamer(*fBufferRef);
369 objbuf += kMAXZIPBUF;
373 fBufferRef->SetBufferOffset(0);
374 Streamer(*fBufferRef);
378 fBuffer = fBufferRef->Buffer();
380 fBufferRef->SetBufferOffset(0);
381 Streamer(*fBufferRef);
465 Error(
"Create",
"Cannot create key without file");
476 Error(
"Create",
"Cannot allocate %d bytes for ID = %s Title = %s",
483 if (fSeekKey >= f->
GetEND()) {
484 f->
SetEND(fSeekKey+nsize);
507 tobuf(buffer, nbytesleft);
533 if (option && option[0] ==
'v')
printf(
"Deleting key: %s at address %lld, nbytes = %d\n",
GetName(),fSeekKey,fNbytes);
535 Long64_t last = fSeekKey + fNbytes -1;
563 return ((fCycle >0) ? fCycle : -fCycle);
579 return ((fCycle >0) ? 0 : 1);
587 tobuf(buffer, fNbytes);
589 tobuf(buffer, version);
591 tobuf(buffer, fObjlen);
593 tobuf(buffer, fKeylen);
594 tobuf(buffer, fCycle);
596 tobuf(buffer, fSeekKey);
676 if (fCycle >0) fCycle = -
fCycle;
741 Error(
"ReadObj",
"Cannot allocate buffer: fObjlen = %d", fObjlen);
748 if (fObjlen > fNbytes-fKeylen) {
777 char *pobj = (
char*)cl->
New();
783 if (baseOffset==-1) {
787 Fatal(
"ReadObj",
"Incorrect detection of the inheritance from TObject for class %s.\n",
790 tobj = (
TObject*)(pobj+baseOffset);
794 if (fObjlen > fNbytes-fKeylen) {
797 Int_t nin, nout = 0, nbuf;
802 R__unzip(&nin, bufcur, &nbuf, (
unsigned char*) objbuf, &nout);
805 if (noutot >= fObjlen)
break;
884 Error(
"ReadObjWithBuffer",
"Cannot allocate buffer: fObjlen = %d", fObjlen);
891 if (fObjlen > fNbytes-fKeylen) {
907 char *pobj = (
char*)cl->
New();
913 if (baseOffset==-1) {
917 Fatal(
"ReadObjWithBuffer",
"Incorrect detection of the inheritance from TObject for class %s.\n",
920 tobj = (
TObject*)(pobj+baseOffset);
925 if (fObjlen > fNbytes-fKeylen) {
928 Int_t nin, nout = 0, nbuf;
933 R__unzip(&nin, bufcur, &nbuf, (
unsigned char*) objbuf, &nout);
936 if (noutot >= fObjlen)
break;
1009 Error(
"ReadObj",
"Cannot allocate buffer: fObjlen = %d", fObjlen);
1016 if (fObjlen > fNbytes-fKeylen) {
1036 Int_t baseOffset = 0;
1037 if (expectedClass) {
1040 if (baseOffset == -1) {
1051 cl =
const_cast<TClass*
>(expectedClass);
1052 Info(
"ReadObjectAny",
"Using Converter StreamerInfo from %s to %s",clOnfile->GetName(),expectedClass->
GetName());
1057 "Trying to read an emulated class (%s) to store in a compiled pointer (%s)",
1063 void *pobj = cl->
New();
1072 if (fObjlen > fNbytes-fKeylen) {
1075 Int_t nin, nout = 0, nbuf;
1080 R__unzip(&nin, bufcur, &nbuf, (
unsigned char*) objbuf, &nout);
1083 if (noutot >= fObjlen)
break;
1102 if (baseOffset==-1) {
1103 Fatal(
"ReadObj",
"Incorrect detection of the inheritance from TObject for class %s.\n",
1133 return ( ((
char*)pobj) + baseOffset );
1145 if (!obj || (
GetFile()==0))
return 0;
1154 if (fObjlen > fNbytes-fKeylen) {
1163 if (fObjlen > fNbytes-fKeylen) {
1166 Int_t nin, nout = 0, nbuf;
1171 R__unzip(&nin, bufcur, &nbuf, (
unsigned char*) objbuf, &nout);
1174 if (noutot >= fObjlen)
break;
1240 Int_t seekkey,seekdir;
1266 for (
Int_t i = 0; i < nsize; i += kMAXFILEBUFFER) {
1267 int nb = kMAXFILEBUFFER;
1268 if (i+nb > nsize) nb = nsize - i;
1274 Error(
"ReadFile",
"Failed to read data.");
1279 std::cout <<
"TKey Reading "<<nsize<<
" bytes at address "<<fSeekKey<<std::endl;
1346 void TKey::Streamer(
TBuffer &b)
1371 Int_t seekkey, seekdir;
1372 b >> seekkey; fSeekKey = (
Long64_t)seekkey;
1384 Error(
"Streamer",
"The value of fKeylen is incorrect (%d) ; trying to recover by setting it to zero",fKeylen);
1389 Error(
"Streamer",
"The value of fObjlen is incorrect (%d) ; trying to recover by setting it to zero",fObjlen);
1394 Error(
"Streamer",
"The value of fNbytes is incorrect (%d) ; trying to recover by setting it to zero",fNbytes);
1421 b << (
Int_t)fSeekKey;
1456 for (
Int_t i=0;i<nsize;i+=kMAXFILEBUFFER) {
1457 Int_t nb = kMAXFILEBUFFER;
1458 if (i+nb > nsize) nb = nsize - i;
1468 std::cout <<
" TKey Writing "<<nsize<<
" bytes at address "<<fSeekKey
1473 return result==
kTRUE ? -1 : nsize;
1492 for (
Int_t i=0;i<nsize;i+=kMAXFILEBUFFER) {
1493 Int_t nb = kMAXFILEBUFFER;
1494 if (i+nb > nsize) nb = nsize - i;
1504 std::cout <<
" TKey Writing "<<nsize<<
" bytes at address "<<fSeekKey
1508 return result==
kTRUE ? -1 : nsize;
1528 ret =
fTitle(start, stop - start);
Int_t fVersion
Key version identifier.
void SetBufferOffset(Int_t offset=0)
Int_t fLeft
Number of bytes left in current segment.
void frombuf(char *&buf, Bool_t *x)
Bool_t HasDefaultConstructor() const
Return true if we have access to a default constructor.
virtual void FillBuffer(char *&buffer) const
Copy string into I/O buffer.
Bool_t IsFolder() const
Check if object referenced by the key is a folder.
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket...
void Set()
Set Date/Time to current time as reported by the system.
virtual void ls(Option_t *option="") const
List Key contents.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual TList * GetListOfKeys() const
Int_t GetCompressionAlgorithm() const
virtual ULong_t Hash() const
Return hash value for this object.
const UChar_t kPidOffsetShift
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...
UInt_t Get() const
Return raw date/time as encoded by TDatime.
virtual void SetEND(Long64_t last)
virtual void Print(Option_t *option="") const
Print key contents.
TList * GetListOfFree() const
virtual TList * GetList() const
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Seek to a specific position in the file. Pos it either kBeg, kCur or kEnd.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read a buffer from the file.
virtual void * ReadObjectAny(const TClass *expectedClass)
To read an object (non deriving from TObject) from the file.
Short_t GetCycle() const
Return cycle number associated to this key.
Buffer base class used for serializing objects.
virtual void Browse(TBrowser *b)
Read object from disk and call its Browse() method.
void Build(TDirectory *motherDir, const char *classname, Long64_t filepos)
Method used in all TKey constructor to initialize basic data fields.
virtual const char * GetIconName() const
Title can keep 32x32 xpm thumbnail/icon of the parent object.
TFile * GetFile() const
Returns file to which key belong.
virtual const char * GetClassName() const
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects)...
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
void SetParent(TObject *parent)
Set parent owning this buffer.
virtual Long64_t GetEND() const
virtual void UseCurrentStyle()
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyl...
char * fBuffer
Object buffer.
void ReadBuffer(char *&buffer)
Decode Date/Time from output buffer, used by I/O system.
virtual void FillBuffer(char *&buffer)
Encode key header into output buffer.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TDirectory * fMotherDir
!pointer to mother directory
const ULong64_t kPidOffsetMask
void(* DirAutoAdd_t)(void *, TDirectory *)
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
const char * Data() const
Int_t GetBaseClassOffset(const TClass *toBase, void *address=0, bool isDerivedObject=true)
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Long64_t fSeekPdir
Location of parent directory on file.
Int_t GetCompressionLevel() const
virtual void ReadBuffer(char *&buffer)
Read string from I/O buffer.
The TNamed class is the base class for all named ROOT classes.
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
TClass * GetActualClass(const void *object) const
Return a pointer the the real class of the object.
void FillBuffer(char *&buffer)
Encode Date/Time into buffer, used by I/O system.
virtual Long64_t GetSeekDir() const
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=0)
Write the encoded object supported by this key.
int R__unzip_header(Int_t *nin, UChar_t *bufin, Int_t *lout)
Short_t fKeylen
Number of bytes for the key itself.
TString fClassName
Object Class name.
virtual ~TKey()
TKey default destructor.
virtual void SetPidOffset(UShort_t offset)=0
virtual Int_t Sizeof() const
Return the size in bytes of the key header structure.
void tobuf(char *&buf, Bool_t x)
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Delete(Option_t *option="")
Delete an object from the file.
TDatime fDatime
Date/Time of insertion in file.
virtual const char * GetTitle() const
Returns title (title can contain 32x32 xpm thumbnail/icon).
virtual Int_t WriteFileKeepBuffer(TFile *f=0)
Write the encoded object supported by this key.
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
virtual TFile * GetFile() const
virtual Long64_t GetSeekDir() const
virtual void Delete(Option_t *option="")
Delete this object.
Using a TBrowser one can browse all ROOT objects.
Bool_t HasRuleWithSourceClass(const TString &source) const
Return True if we have any rule whose source class is 'source'.
virtual void IncrementPidOffset(UShort_t offset)
Increment fPidOffset by 'offset'.
ClassImp(TKey) TKey
TKey default constructor.
virtual void Keep()
Set the "KEEP" status.
virtual void ReadBuffer(char *&buffer)
Decode input buffer.
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
A ROOT file is structured in Directories (like a file system).
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
virtual Bool_t WriteBuffer(const char *buf, Int_t len)
Write a buffer to the file.
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
void SetRefreshFlag(Bool_t flag)
Bool_t TestBit(UInt_t f) const
virtual Bool_t ReadFile()
Read the key structure from the file.
virtual void MakeFree(Long64_t first, Long64_t last)
Mark unused bytes on the file.
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
virtual void Browse(TBrowser *b)
This method is called by a browser to get the class information.
virtual const char * GetName() const
Returns name of object.
The ROOT global object gROOT contains a list of all defined classes.
virtual void Reset()
Reset the key as it had not been 'filled' yet.
virtual TObject * ReadObjWithBuffer(char *bufferRead)
To read a TObject* from bufferRead.
TBuffer * fBufferRef
Pointer to the TBuffer object.
virtual void SetParent(const TObject *parent)
Set parent in key buffer.
Long64_t fSeekKey
Location of object on file.
virtual Int_t AppendKey(TKey *)
void SetFirst(Long64_t first)
void ReadKeyBuffer(char *&buffer)
Decode input buffer.
virtual void MapObject(const TObject *obj, UInt_t offset=1)=0
virtual void SetName(const char *newname)
Set the name for directory If the directory name is changed after the directory was written once...
Short_t fCycle
Cycle number.
Long64_t GetFirst() const
Describe directory structure in memory.
unsigned long long ULong64_t
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
std::atomic< UInt_t > keyAbsNumber
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.
ROOT::DirAutoAdd_t GetDirectoryAutoAdd() const
Return the wrapper around the directory auto add function.
void R__unzip(Int_t *nin, UChar_t *bufin, Int_t *lout, char *bufout, Int_t *nout)
TString & gTDirectoryString()
Int_t fObjlen
Length of uncompressed object in bytes.
Mother of all ROOT objects.
virtual void Create(Int_t nbytes, TFile *f=0)
Create a TKey object of specified size.
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
TFree * GetBestFree(TList *lfree, Int_t nbytes)
Return the best free segment where to store nbytes.
virtual TObject * ReadObj()
To read a TObject* from the file.
virtual void DeleteBuffer()
Delete key buffer(s).
Short_t Max(Short_t a, Short_t b)
const ROOT::Detail::TSchemaRuleSet * GetSchemaRules() const
Return the set of the schema rules if any.
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Int_t fNbytes
Number of bytes for the object on file.
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
void Streamer(void *obj, TBuffer &b, const TClass *onfile_class=0) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual ULong_t Hash() const
This Hash function should redefine the default from TNamed.
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
virtual void SetMother(TObject *mother)
Short_t GetKeep() const
Returns the "KEEP" status.
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.