Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TDirectoryFile.cxx
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Rene Brun 22/01/2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/**
13 \class TDirectoryFile
14 \ingroup io_files
15
16 A ROOT file is structured in Directories (like a file system).
17 Each Directory has a list of Keys (see TKeys) and a list of objects
18 in memory. A Key is a small object that describes the type and location
19 of a persistent object in a file. The persistent object may be a directory.
20Begin_Macro
21../../../tutorials/io/fildir.C
22End_Macro
23 The structure of a file is shown in TFile::TFile
24*/
25
26#include "strlcpy.h"
27#include "TDirectoryFile.h"
28#include "TFile.h"
29#include "TBufferFile.h"
30#include "TBufferJSON.h"
31#include "TMapFile.h"
32#include "TClassTable.h"
33#include "TInterpreter.h"
34#include "THashList.h"
35#include "TBrowser.h"
36#include "TFree.h"
37#include "TKey.h"
38#include "TStreamerInfo.h"
39#include "TROOT.h"
40#include "TError.h"
41#include "Bytes.h"
42#include "TClass.h"
43#include "TRegexp.h"
44#include "TSystem.h"
45#include "TStreamerElement.h"
46#include "TProcessUUID.h"
47#include "TVirtualMutex.h"
49
50#include <iostream>
51#include <cstring>
53const UInt_t kIsBigFile = BIT(16);
54const Int_t kMaxLen = 2048;
55
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Default TDirectoryFile constructor
62{
63 /// Intentionally placed here
64 /// when TDirectoryFile() = default; used, mac1014/cxx17 fails on some tests
65 /// Problem with TObject::IsOnHeap() failing
66}
67
68
69////////////////////////////////////////////////////////////////////////////////
70/// Create a new TDirectoryFile
71///
72/// A new directory with a name and a title is created in the current directory.
73/// The directory header information is immediately saved on the file
74/// A new key is added in the parent directory.
75/// When this constructor is called from a class directly derived
76/// from TDirectoryFile, the third argument, classname, MUST be specified.
77/// In this case, classname must be the name of the derived class.
78///
79/// Note that the directory name cannot contain slashes.
81TDirectoryFile::TDirectoryFile(const char *name, const char *title, Option_t *classname, TDirectory* initMotherDir)
82{
83 // We must not publish this objects to the list of RecursiveRemove (indirectly done
84 // by 'Appending' this object to it's mother) before the object is completely
85 // initialized.
86 // However a better option would be to delay the publishing until the very end,
87 // but it is currently done in the middle of the initialization (by Build which
88 // is a public interface) ....
90
91 fName = name;
92 fTitle = title;
93
94 if (!initMotherDir) initMotherDir = gDirectory;
95
96 if (strchr(name,'/')) {
97 ::Error("TDirectoryFile","directory name (%s) cannot contain a slash", name);
98 gDirectory = nullptr;
99 return;
100 }
101 if (strlen(GetName()) == 0) {
102 ::Error("TDirectoryFile","directory name cannot be \"\"");
103 gDirectory = nullptr;
104 return;
105 }
106
107 BuildDirectoryFile(initMotherDir ? initMotherDir->GetFile() : nullptr, initMotherDir);
108
109 TDirectory* motherdir = GetMotherDir();
111
112 if (!motherdir || !f) return;
113 if (!f->IsWritable()) return; //*-* in case of a directory in memory
114 if (motherdir->GetKey(name)) {
115 Error("TDirectoryFile","An object with name %s exists already", name);
116 return;
117 }
118 TClass *cl = nullptr;
119 if (classname[0]) {
120 cl = TClass::GetClass(classname);
121 if (!cl) {
122 Error("TDirectoryFile","Invalid class name: %s",classname);
123 return;
124 }
125 } else {
126 cl = TDirectoryFile::IsA();
127 }
128
129 fBufferSize = 0;
131
133
135
136 // Temporarily redundant, see comment on lock early in the function.
137 // R__LOCKGUARD(gROOTMutex);
138 gROOT->GetUUIDs()->AddUUID(fUUID,this);
139 // We should really be doing this now rather than in Build, see
140 // comment at the start of the function.
141 // if (initMotherDir && strlen(GetName()) != 0) initMotherDir->Append(this);
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Initialize the key associated with this directory (and the related
146/// data members.
149{
150 TFile* f = GetFile(); // NOLINT: silence clang-tidy warnings
151 if (f->IsBinary()) {
152 if (!cl) {
153 cl = IsA(); // NOLINT: silence clang-tidy warnings
154 }
155 TDirectory* motherdir = GetMotherDir();
156 fSeekParent = motherdir->GetSeekDir();
157 Int_t nbytes = TDirectoryFile::Sizeof();
158 TKey *key = new TKey(fName,fTitle,cl,nbytes,motherdir);
159 fNbytesName = key->GetKeylen();
160 fSeekDir = key->GetSeekKey();
161 if (fSeekDir == 0) return;
162 char *buffer = key->GetBuffer();
164 Int_t cycle = motherdir ? motherdir->AppendKey(key) : 0;
165 key->WriteFile(cycle);
166 } else {
167 fSeekParent = 0;
168 fNbytesName = 0;
169 fSeekDir = f->DirCreateEntry(this);
170 if (fSeekDir == 0) return;
171 }
172
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Destructor.
179{
180 if (fKeys) {
181 fKeys->Delete("slow");
183 }
184
186
187 // Delete our content before we become somewhat invalid
188 // since some those objects (TTree for example) needs information
189 // from this object. Note that on some platform after the end
190 // of the body (i.e. thus during ~TDirectory which is also
191 // contains this code) the execution of 'this->GetFile()' fails
192 // to return the 'proper' value (because it uses the wrong
193 // virtual function).
194 if (fList) {
195 fList->Delete("slow");
197 }
198
199 if (gDebug) {
200 Info("~TDirectoryFile", "dtor called for %s", GetName());
201 }
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Append object to this directory.
206///
207/// If replace is true:
208/// remove any existing objects with the same same (if the name is not ""
210void TDirectoryFile::Append(TObject *obj, Bool_t replace /* = kFALSE */)
211{
212 if (!obj || !fList) return;
213
214 TDirectory::Append(obj,replace);
215
216 if (!fMother) return;
217 if (fMother->IsA() == TMapFile::Class()) {
218 TMapFile *mfile = (TMapFile*)fMother;
219 mfile->Add(obj);
220 }
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Insert key in the linked list of keys of this directory.
227{
228 if (!fKeys) {
229 Error("AppendKey","TDirectoryFile not initialized yet.");
230 return 0;
231 }
232
234
235 key->SetMotherDir(this);
236
237 // This is a fast hash lookup in case the key does not already exist
238 TKey *oldkey = (TKey*)fKeys->FindObject(key->GetName());
239 if (!oldkey) {
240 fKeys->Add(key);
241 return 1;
242 }
243
244 // If the key name already exists we have to make a scan for it
245 // and insert the new key ahead of the current one
246 TObjLink *lnk = fKeys->FirstLink();
247 while (lnk) {
248 oldkey = (TKey*)lnk->GetObject();
249 if (!strcmp(oldkey->GetName(), key->GetName()))
250 break;
251 lnk = lnk->Next();
252 }
253
254 fKeys->AddBefore(lnk, key);
255 return oldkey->GetCycle() + 1;
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Browse the content of the directory.
262{
264
265 if (b) {
266 TObject *obj = nullptr;
267 TIter nextin(fList);
268 TKey *key = nullptr, *keyo = nullptr;
269 TIter next(fKeys);
270
271 cd();
272
273 //Add objects that are only in memory
274 while ((obj = nextin())) {
275 if (fKeys->FindObject(obj->GetName())) continue;
276 b->Add(obj, obj->GetName());
277 }
278
279 //Add keys
280 while ((key = (TKey *) next())) {
281 int skip = 0;
282 if (!keyo || (keyo && strcmp(keyo->GetName(), key->GetName()))) {
283 skip = 0;
284 obj = fList->FindObject(key->GetName());
285
286 if (obj) {
287 b->Add(obj, obj->GetName());
288 if (obj->IsFolder() && !obj->InheritsFrom("TTree"))
289 skip = 1;
290 }
291 }
292
293 if (!skip) {
294 name.Form("%s;%d", key->GetName(), key->GetCycle());
295 b->Add(key, name);
296 }
297
298 keyo = key;
299 }
300 }
301}
302
303////////////////////////////////////////////////////////////////////////////////
304/// Initialise directory to defaults.
306void TDirectoryFile::BuildDirectoryFile(TFile* motherFile, TDirectory* motherDir)
307{
308 // If directory is created via default ctor (when dir is read from file)
309 // don't add it here to the directory since its name is not yet known.
310 // It will be added to the directory in TKey::ReadObj().
311
312 if (motherDir && strlen(GetName()) != 0) motherDir->Append(this);
313
316 fDatimeC.Set();
317 fDatimeM.Set();
318 fNbytesKeys = 0;
319 fSeekDir = 0;
320 fSeekParent = 0;
321 fSeekKeys = 0;
322 fList = new THashList(100,50);
323 fKeys = new THashList(100,50);
324 fList->UseRWLock();
325 fMother = motherDir;
326 fFile = motherFile ? motherFile : TFile::CurrentFile();
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Change current directory to "this" directory.
332///
333/// Returns kTRUE in case of success.
336{
337 Bool_t ok = TDirectory::cd();
338 if (ok)
340 return ok;
341}
342
343////////////////////////////////////////////////////////////////////////////////
344/// Change current directory the directory described by the path if given one.
345/// change the current directory to "path". The absolute path syntax is:
346///
347/// file.root:/dir1/dir2
348///
349/// where file.root is the file and /dir1/dir2 the desired subdirectory
350/// in the file. Relative syntax is relative to "this" directory. E.g:
351/// ../aa. Returns kTRUE in case of success.
353Bool_t TDirectoryFile::cd(const char *path)
354{
355 Bool_t ok = TDirectory::cd(path);
356 if (ok)
358 return ok;
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Clean the pointers to this object (gDirectory, TContext, etc.)
365{
366 // After CleanTargets either gFile was changed appropriately
367 // by a cd() or needs to be set to zero.
368 if (gFile == this) {
369 gFile = nullptr;
370 }
371
373}
374
375////////////////////////////////////////////////////////////////////////////////
376/// Make a clone of an object using the Streamer facility.
377///
378/// If the object derives from TNamed, this function is called
379/// by TNamed::Clone. TNamed::Clone uses the optional argument newname to set
380/// a new name to the newly created object.
381///
382/// If autoadd is true and if the object class has a
383/// DirectoryAutoAdd function, it will be called at the end of the
384/// function with the parameter gDirectory. This usually means that
385/// the object will be appended to the current ROOT directory.
387TObject *TDirectoryFile::CloneObject(const TObject *obj, Bool_t autoadd /* = kTRUE */)
388{
389 // if no default ctor return immediately (error issued by New())
390 char *pobj = (char*)obj->IsA()->New();
391 if (!pobj) return nullptr;
392
393 Int_t baseOffset = obj->IsA()->GetBaseClassOffset(TObject::Class());
394 if (baseOffset==-1) {
395 // cl does not inherit from TObject.
396 // Since this is not supported in this function, the only reason we could reach this code
397 // is because something is screwed up in the ROOT code.
398 Fatal("CloneObject","Incorrect detection of the inheritance from TObject for class %s.\n",
399 obj->IsA()->GetName());
400 }
401 TObject *newobj = (TObject*)(pobj+baseOffset);
402
403 //create a buffer where the object will be streamed
404 {
405 // NOTE: do we still need to make this change to gFile?
406 // NOTE: This can not be 'gDirectory=0' as at least roofit expect gDirectory to not be null
407 // during the streaming ....
408 TFile *filsav = gFile;
409 gFile = nullptr;
410 const Int_t bufsize = 10000;
411 TBufferFile buffer(TBuffer::kWrite,bufsize);
412 buffer.MapObject(obj); //register obj in map to handle self reference
413 {
414 Bool_t isRef = obj->TestBit(kIsReferenced);
415 ((TObject*)obj)->ResetBit(kIsReferenced);
416
417 ((TObject*)obj)->Streamer(buffer);
418
419 if (isRef) ((TObject*)obj)->SetBit(kIsReferenced);
420 }
421
422 // read new object from buffer
423 buffer.SetReadMode();
424 buffer.ResetMap();
425 buffer.SetBufferOffset(0);
426 buffer.MapObject(newobj); //register obj in map to handle self reference
427 newobj->Streamer(buffer);
428 newobj->ResetBit(kIsReferenced);
429 newobj->ResetBit(kCanDelete);
430 gFile = filsav;
431 }
432
433 if (autoadd) {
435 if (func) {
436 func(newobj,this);
437 }
438 }
439 return newobj;
440}
441
442////////////////////////////////////////////////////////////////////////////////
443/// Scan the memory lists of all files for an object with name
446{
447 TFile *f;
449 TIter next(gROOT->GetListOfFiles());
450 while ((f = (TFile*)next())) {
451 TObject *obj = f->GetList()->FindObject(name);
452 if (obj) return obj;
453 }
454 return nullptr;
455}
456
457////////////////////////////////////////////////////////////////////////////////
458/// Find a directory named "apath".
459///
460/// It apath is null or empty, returns "this" directory.
461/// Otherwise use the name "apath" to find a directory.
462/// The absolute path syntax is:
463///
464/// file.root:/dir1/dir2
465///
466/// where file.root is the file and /dir1/dir2 the desired subdirectory
467/// in the file. Relative syntax is relative to "this" directory. E.g:
468/// ../aa.
469/// Returns 0 in case path does not exist.
470/// If printError is true, use Error with 'funcname' to issue an error message.
473 Bool_t printError, const char *funcname)
474{
475 Int_t nch = 0;
476 if (apath) nch = strlen(apath);
477 if (!nch) {
478 return this;
479 }
480
481 if (funcname==0 || strlen(funcname)==0) funcname = "GetDirectory";
482
483 TDirectory *result = this;
484
485 char *path = new char[nch+1]; path[0] = 0;
486 if (nch) strlcpy(path,apath,nch+1);
487 char *s = (char*)strchr(path, ':');
488 if (s) {
489 *s = '\0';
491 TDirectory *f = (TDirectory *)gROOT->GetListOfFiles()->FindObject(path);
492 // Check if this is a duplicate (2nd opening) on this file and prefer
493 // this file.
494 if (GetFile()) {
495 auto url = GetFile()->GetEndpointUrl();
496 if (f && 0 == url->Compare(f->GetFile()->GetEndpointUrl())) {
497 result = GetDirectory(s+1,printError,funcname);
498 delete [] path;
499 return result;
500 }
501 }
502 if (!f && !strcmp(gROOT->GetName(), path)) f = gROOT;
503 if (s) *s = ':';
504 if (f) {
505 result = f;
506 if (s && *(s+1)) result = f->GetDirectory(s+1,printError,funcname);
507 delete [] path; return result;
508 } else {
509 if (printError) Error(funcname, "No such file %s", path);
510 delete [] path; return nullptr;
511 }
512 }
513
514 // path starts with a slash (assumes current file)
515 if (path[0] == '/') {
516 TDirectory *td = fFile;
517 if (!fFile) td = gROOT;
518 result = td->GetDirectory(path+1,printError,funcname);
519 delete [] path; return result;
520 }
521
522 TDirectoryFile *obj;
523 char *slash = (char*)strchr(path,'/');
524 if (!slash) { // we are at the lowest level
525 if (!strcmp(path, "..")) {
527 delete [] path; return result;
528 }
529 GetObject(path,obj);
530 if (!obj) {
531 if (printError) Error(funcname,"Unknown directory %s", path);
532 delete [] path; return nullptr;
533 }
534
535 delete [] path; return obj;
536 }
537
538 TString subdir(path);
539 slash = (char*)strchr(subdir.Data(),'/');
540 *slash = 0;
541 //Get object with path from current directory/file
542 if (!strcmp(subdir, "..")) {
543 TDirectory* mom = GetMotherDir();
544 if (mom)
545 result = mom->GetDirectory(slash+1,printError,funcname);
546 delete [] path; return result;
547 }
548 GetObject(subdir,obj);
549 if (!obj) {
550 if (printError) Error(funcname,"Unknown directory %s", subdir.Data());
551 delete [] path; return nullptr;
552 }
553
554 result = ((TDirectory*)obj)->GetDirectory(slash+1,printError,funcname);
555 delete [] path; return result;
556}
557
558////////////////////////////////////////////////////////////////////////////////
559/// Delete all objects from memory and directory structure itself.
562{
563 if (!fList || !fSeekDir) {
564 return;
565 }
566
567 // Save the directory key list and header
568 Save();
569
570 Bool_t nodelete = option ? (!strcmp(option, "nodelete") ? kTRUE : kFALSE) : kFALSE;
571
572 if (!nodelete) {
573 Bool_t fast = kTRUE;
574 TObjLink *lnk = fList->FirstLink();
575 while (lnk) {
576 if (lnk->GetObject()->IsA() == TDirectoryFile::Class()) {fast = kFALSE;break;}
577 lnk = lnk->Next();
578 }
579 // Delete objects from directory list, this in turn, recursively closes all
580 // sub-directories (that were allocated on the heap)
581 // if this dir contains subdirs, we must use the slow option for Delete!
582 // we must avoid "slow" as much as possible, in particular Delete("slow")
583 // with a large number of objects (eg >10^5) would take for ever.
584 {
585 if (fast) fList->Delete();
586 else fList->Delete("slow");
587 }
588 }
589
590 // Delete keys from key list (but don't delete the list header)
591 if (fKeys) {
592 fKeys->Delete("slow");
593 }
594
596}
597
598////////////////////////////////////////////////////////////////////////////////
599/// Delete Objects or/and keys in the current directory.
600///
601/// \param[in] namecycle Encodes the name and cycle of the objects to delete in
602/// the current directory (e.g. the top directory of a TFile)
603/// - <em>namecycle</em> has the format <em>name;cycle</em>.
604/// - <em>namecycle</em>="" is same as <em>namecycle</em>="T*"
605/// - <em>name</em>="*" means all objects, use "T*" to also delete subdirectories
606/// - <em>cycle</em>="*" means all cycles (memory and keys)
607/// - <em>cycle</em>="" or <em>cycle</em>="9999" ==> apply to a memory object
608/// - When <em>name</em>="*"" use "T*" to delete subdirectories also
609///
610/// To delete one directory, you must specify the directory cycle,
611/// eg. file.Delete("dir1;1");
612///
613/// Examples:
614/// | Pattern | Description |
615/// |---------|-------------|
616/// | foo | delete object named foo in memory |
617/// | foo* | delete all objects with a name starting with foo |
618/// | foo;1 | delete cycle 1 of foo on file |
619/// | foo;* | delete all cycles of foo on file and also from memory |
620/// | *;2 | delete all objects on file having the cycle 2 |
621/// | *;* | delete all objects from memory and file |
622/// | T*;* | delete all objects from memory and file and all subdirectories |
623///
624/// \note For some objects, this method, which is used e.g. by rootrm,
625/// properly deletes the specified cycles of the object, but does not free any ‘dependent’
626/// data records (unless it is a TDirectoryFile). In other words, in these cases, Delete
627/// does not free all subdata records, but rather orphans them, ie. the file size is not
628/// reduced, and there is later no option to shrink it nor recover the disappeared ‘dependent’
629/// items. For example, deleting a TTree does not free up space from the directory since the
630/// underlying basket records are not recursively deleted. If this is wanted, one can call
631/// TTree::Delete("all") before calling TDirectoryFile::Delete(); file size won't
632/// shrink either, but more space will be left open for overwriting with other objects.
633/// See also Purge() documentation. A workaround to reduce filesize is to clone all
634/// objects (excluding those to be deleted) into a new TFile.
635///
636/// ## WARNING
637/// If the key to be deleted contains special characters ("+","^","?", etc)
638/// that have a special meaning for the regular expression parser (see TRegexp)
639/// then you must specify 2 backslash characters to escape the regular expression.
640/// For example, if the key to be deleted is namecycle = "C++", you must call
641///
642/// mydir.Delete("C\\+\\+"));
643///
645void TDirectoryFile::Delete(const char *namecycle)
646{
647 if (gDebug)
648 Info("Delete","Call for this = %s namecycle = %s",
649 GetName(), (namecycle ? namecycle : "null"));
650
651 TDirectory::TContext ctxt(this);
652 Short_t cycle;
653 char name[kMaxLen];
654 const char *nmcy = (namecycle) ? namecycle : "";
655 DecodeNameCycle(nmcy, name, cycle, kMaxLen);
656
657 Int_t deleteall = 0;
658 Int_t deletetree = 0;
659 if(strcmp(name,"*") == 0) deleteall = 1;
660 if(strcmp(name,"*T") == 0){ deleteall = 1; deletetree = 1;}
661 if(strcmp(name,"T*") == 0){ deleteall = 1; deletetree = 1;}
662 if(namecycle==0 || !namecycle[0]){ deleteall = 1; deletetree = 1;}
663 TRegexp re(name,kTRUE);
664 TString s;
665 Int_t deleteOK = 0;
666
667//*-*---------------------Case of Object in memory---------------------
668// ========================
669 if (cycle >= 9999 ) {
670 TNamed *idcur;
671 TIter next(fList);
672 while ((idcur = (TNamed *) next())) {
673 deleteOK = 0;
674 s = idcur->GetName();
675 if (deleteall || s.Index(re) != kNPOS) {
676 deleteOK = 1;
677 if (idcur->IsA() == TDirectoryFile::Class()) {
678 deleteOK = 2;
679 if (!deletetree && deleteall) deleteOK = 0;
680 }
681 }
682 if (deleteOK != 0) {
683 fList->Remove(idcur);
684 if (deleteOK==2) {
685 // read subdirectories to correctly delete them
686 if (deletetree)
687 ((TDirectory*) idcur)->ReadAll("dirs");
688 idcur->Delete(deletetree ? "T*;*" : "*");
689 delete idcur;
690 } else
691 idcur->Delete(name);
692 }
693 }
694// if (deleteOK == 2) {
695// Info("Delete","Dir:%lx %s", fList->FindObject(name), name);
696// delete fList->FindObject(name); //deleting a TDirectory
697// }
698 }
699//*-*---------------------Case of Key---------------------
700// ===========
701 if (cycle != 9999 ) {
702 if (IsWritable()) {
703 TKey *key;
704 TIter nextkey(GetListOfKeys());
705 while ((key = (TKey *) nextkey())) {
706 deleteOK = 0;
707 s = key->GetName();
708 if (deleteall || s.Index(re) != kNPOS) {
709 if (cycle == key->GetCycle()) deleteOK = 1;
710 if (cycle > 9999) deleteOK = 1;
711 //if (!strcmp(key->GetClassName(),"TDirectory")) {
712 if (strstr(key->GetClassName(),"TDirectory")) {
713 deleteOK = 2;
714 if (!deletetree && deleteall) deleteOK = 0;
715 if (cycle == key->GetCycle()) deleteOK = 2;
716 }
717 }
718 if (deleteOK) {
719 if (deleteOK==2) {
720 // read directory with subdirectories to correctly delete and free key structure
721 TDirectory* dir = GetDirectory(key->GetName(), kTRUE, "Delete");
722 if (dir!=0) {
723 dir->Delete("T*;*");
724 fList->Remove(dir);
725 delete dir;
726 }
727 }
728
729 key->Delete();
730 fKeys->Remove(key);
732 delete key;
733 }
734 }
735 TFile* f = GetFile();
736 if (fModified && (f!=0)) {
737 WriteKeys(); //*-* Write new keys structure
738 WriteDirHeader(); //*-* Write new directory header
739 f->WriteFree(); //*-* Write new free segments list
740 f->WriteHeader(); //*-* Write new file header
741 }
742 }
743 }
744}
745
746////////////////////////////////////////////////////////////////////////////////
747/// Encode directory header into output buffer
749void TDirectoryFile::FillBuffer(char *&buffer)
750{
755 {
756 // One of the address is larger than 2GB we need to use longer onfile
757 // integer, thus we increase the version number.
758 // Note that fSeekDir and fSeekKey are not necessarily correlated, if
759 // some object are 'removed' from the file and the holes are reused.
760 version += 1000;
761 }
762 tobuf(buffer, version);
763 const bool reproducible = TestBit(TFile::kReproducible) || (fFile && fFile->TestBit(TFile::kReproducible));
764 if (reproducible) {
765 TDatime((UInt_t) 1).FillBuffer(buffer);
766 TDatime((UInt_t) 1).FillBuffer(buffer);
767 } else {
768 fDatimeC.FillBuffer(buffer);
769 fDatimeM.FillBuffer(buffer);
770 }
771 tobuf(buffer, fNbytesKeys);
772 tobuf(buffer, fNbytesName);
773 if (version > 1000) {
774 tobuf(buffer, fSeekDir);
775 tobuf(buffer, fSeekParent);
776 tobuf(buffer, fSeekKeys);
777 } else {
778 tobuf(buffer, (Int_t)fSeekDir);
779 tobuf(buffer, (Int_t)fSeekParent);
780 tobuf(buffer, (Int_t)fSeekKeys);
781 }
782 if (reproducible)
783 TUUID("00000000-0000-0000-0000-000000000000").FillBuffer(buffer);
784 else
785 fUUID.FillBuffer(buffer);
786 if (fFile && fFile->GetVersion() < 40000) return;
787 if (version <=1000) for (Int_t i=0;i<3;i++) tobuf(buffer,Int_t(0));
788}
789
790////////////////////////////////////////////////////////////////////////////////
791/// Find key with name `keyname` in the current directory.
792/// `keyname` may be of the form name;cycle.
793/// See GetKey() for details on the semantics of this form.
795TKey *TDirectoryFile::FindKey(const char *keyname) const
796{
797 Short_t cycle;
798 char name[kMaxLen];
799
800 DecodeNameCycle(keyname, name, cycle, kMaxLen);
801 return GetKey(name,cycle);
802}
803
804////////////////////////////////////////////////////////////////////////////////
805/// Find key with name `keyname` in the current directory or
806/// its subdirectories.
807/// `keyname` may be of the form name;cycle.
808/// See GetKey() for details on the semantics of this form.
809///
810/// NOTE: that If a key is found, the directory containing the key becomes
811/// the current directory
813TKey *TDirectoryFile::FindKeyAny(const char *keyname) const
814{
815 TDirectory *dirsav = gDirectory;
816 Short_t cycle;
817 char name[kMaxLen];
818
819 DecodeNameCycle(keyname, name, cycle, kMaxLen);
820
821 auto listOfKeys = dynamic_cast<THashList *>(GetListOfKeys());
822 if (!listOfKeys) {
823 Error("FindKeyAny", "Unexpected type of TDirectoryFile::fKeys!");
824 return nullptr;
825 }
826
827 if (const TList *keyList = listOfKeys->GetListForObject(name)) {
828 for (auto key: TRangeDynCast<TKey>(*keyList)) {
829 if (key && !strcmp(key->GetName(), name)
830 && (cycle == 9999 || cycle >= key->GetCycle())) {
831 const_cast<TDirectoryFile*>(this)->cd(); // may be we should not make cd ???
832 return key;
833 }
834 }
835 }
836
837 //try with subdirectories
838 TIter next(GetListOfKeys());
839 TKey *key;
840 while ((key = (TKey *) next())) {
841 //if (!strcmp(key->GetClassName(),"TDirectory")) {
842 if (strstr(key->GetClassName(),"TDirectory")) {
843 TDirectory* subdir =
844 const_cast<TDirectoryFile*>(this)->GetDirectory(key->GetName(), kTRUE, "FindKeyAny");
845 TKey *k = subdir ? subdir->FindKeyAny(keyname) : nullptr;
846 if (k) return k;
847 }
848 }
849 if (dirsav) dirsav->cd();
850 return nullptr;
851}
852
853////////////////////////////////////////////////////////////////////////////////
854/// Find object by name in the list of memory objects of the current
855/// directory or its sub-directories.
856///
857/// After this call the current directory is not changed.
858/// To automatically set the current directory where the object is found,
859/// use FindKeyAny(aname)->ReadObj().
861TObject *TDirectoryFile::FindObjectAny(const char *aname) const
862{
863 //object may be already in the list of objects in memory
865 if (obj) return obj;
866
867 TDirectory *dirsav = gDirectory;
868 Short_t cycle;
869 char name[kMaxLen];
870
871 DecodeNameCycle(aname, name, cycle, kMaxLen);
872
873 auto listOfKeys = dynamic_cast<THashList *>(GetListOfKeys());
874 if (!listOfKeys) {
875 Error("FindObjectAny", "Unexpected type of TDirectoryFile::fKeys!");
876 return nullptr;
877 }
878
879 if (const TList *keyList = listOfKeys->GetListForObject(name)) {
880 for (auto key: TRangeDynCast<TKey>(*keyList)) {
881 if (key && !strcmp(key->GetName(), name)
882 && (cycle == 9999 || cycle >= key->GetCycle())) {
883 return key->ReadObj();
884 }
885 }
886 }
887
888 //try with subdirectories
889 TIter next(GetListOfKeys());
890 TKey *key;
891 while ((key = (TKey *) next())) {
892 //if (!strcmp(key->GetClassName(),"TDirectory")) {
893 if (strstr(key->GetClassName(),"TDirectory")) {
894 TDirectory* subdir =
895 ((TDirectory*)this)->GetDirectory(key->GetName(), kTRUE, "FindKeyAny");
896 TKey *k = subdir ? subdir->FindKeyAny(aname) : nullptr;
897 if (k) { if (dirsav) dirsav->cd(); return k->ReadObj();}
898 }
899 }
900 if (dirsav) dirsav->cd();
901 return nullptr;
902}
903
904////////////////////////////////////////////////////////////////////////////////
905/// Return pointer to object identified by namecycle.
906///
907/// Properties:
908/// - namecycle has the format name;cycle
909/// - name = * is illegal, cycle = * is illegal
910/// - cycle = "" or cycle = 9999 ==> apply to a memory object
911///
912/// Examples:
913/// | %Pattern | Explanation |
914/// |----------|-------------|
915/// | foo | get object named foo in memory if object is not in memory, try with highest cycle from file |
916/// | foo;1 | get cycle 1 of foo on file |
917///
918/// \note The requested object needs to derive from TObject. Otherwise, a warning will be issued as in
919/// this case the function returns the begin address of the object and if multiple inheritance is in use, the
920/// caller can only reinterpret_cast to the "left" base classes.
921/// In the future, the function will return a nullptr if the underlying type cannot be cast to TObject*.
922/// For these reasons, always prefer the type-safe variant TDirectory::Get<T>(), see next section.
923///
924/// ### The Get<T> Method
925/// The method Get<T> offers better protection and avoids the need for any
926/// cast:
927/// ~~~{.cpp}
928/// auto objPtr = directory->Get<MyClass>("some object");
929/// if (objPtr) { ... the object exists can be cast to MyClass ... }
930/// ~~~
931///
932/// ### Very important note about inheritance
933/// In case the class of this object derives from TObject but not
934/// as a first inheritance, one must use dynamic_cast<>().
935///
936/// #### Example 1 - Simple case:
937///
938/// class MyClass : public TObject, public AnotherClass
939///
940/// then on return, the object can be cast statically:
941///
942/// auto objPtr = static_cast<MyClass*>(directory->Get("some object of MyClass"));
943///
944/// #### Example 2 - Special case:
945///
946/// class MyClass : public AnotherClass, public TObject
947///
948/// then on return, one must do:
949///
950/// auto objPtr = dynamic_cast<MyClass*>(directory->Get("some object of MyClass"));
951///
952/// Of course, dynamic_cast<> can also be used in the example 1.
953///
955TObject *TDirectoryFile::Get(const char *namecycle)
956{
957 Short_t cycle;
958 char name[kMaxLen];
959
960 DecodeNameCycle(namecycle, name, cycle, kMaxLen);
961 Int_t nch = strlen(name);
962 for (Int_t i = nch-1; i > 0; i--) {
963 if (name[i] == '/') {
964 name[i] = 0;
965 TDirectory* dirToSearch=GetDirectory(name);
966 const char *subnamecycle = namecycle + i + 1;
967 name[i] = '/';
968 return dirToSearch?dirToSearch->Get(subnamecycle):0;
969 }
970 }
971 const char *namobj = name;
972
973//*-*---------------------Case of Object in memory---------------------
974// ========================
975 TObject *idcur = fList ? fList->FindObject(namobj) : nullptr;
976 if (idcur) {
977 if (idcur==this && strlen(namobj)!=0) {
978 // The object has the same name has the directory and
979 // that's what we picked-up! We just need to ignore
980 // it ...
981 idcur = nullptr;
982 } else if (cycle == 9999) {
983 return idcur;
984 } else {
985 if (idcur->InheritsFrom(TCollection::Class()))
986 idcur->Delete(); // delete also list elements
987 delete idcur;
988 idcur = nullptr;
989 }
990 }
991
992//*-*---------------------Case of Key---------------------
993// ===========
994 auto listOfKeys = dynamic_cast<THashList *>(GetListOfKeys());
995 if (!listOfKeys) {
996 Error("Get", "Unexpected type of TDirectoryFile::fKeys!");
997 return nullptr;
998 }
999
1000 if (const TList *keyList = listOfKeys->GetListForObject(namobj)) {
1001 for (auto key: TRangeDynCast<TKey>(*keyList)) {
1002 if (key && !strcmp(key->GetName(), namobj)
1003 && (cycle == 9999 || cycle == key->GetCycle())) {
1004 if (TClass *cl = TClass::GetClass(key->GetClassName()); cl && !cl->IsTObject()) {
1005 Warning("Get",
1006 "The object '%s' of type '%s' does not derive from TObject. Using Get() for such objects is "
1007 "deprecated, since the returned pointer is not a valid TObject*. Use Get<%s>(\"%s\").",
1008 namobj, key->GetClassName(), key->GetClassName(), namecycle);
1009 }
1010 TDirectory::TContext ctxt(this);
1011 return key->ReadObj();
1012 }
1013 }
1014 }
1015
1016 return nullptr;
1017}
1018
1019////////////////////////////////////////////////////////////////////////////////
1020/// Return pointer to object identified by namecycle.
1021///
1022/// The returned object may or may not derive from TObject.
1023///
1024/// - namecycle has the format name;cycle
1025/// - name = * is illegal, cycle = * is illegal
1026/// - cycle = "" or cycle = 9999 ==> apply to a memory object
1027///
1028/// ## Very important note
1029/// The calling application must cast the returned object to
1030/// the final type, e.g.
1031///
1032/// auto objPtr = reinterpret_cast<MyClass*>(directory->GetObject("some object of MyClass"));
1034void *TDirectoryFile::GetObjectUnchecked(const char *namecycle)
1035{
1036 return GetObjectChecked(namecycle,(TClass*)nullptr);
1037}
1038
1039////////////////////////////////////////////////////////////////////////////////
1040/// See documentation of TDirectoryFile::GetObjectChecked(const char*,const TClass*).
1042void *TDirectoryFile::GetObjectChecked(const char *namecycle, const char* classname)
1043{
1044 return GetObjectChecked(namecycle,TClass::GetClass(classname));
1045}
1046
1047////////////////////////////////////////////////////////////////////////////////
1048/// Return pointer to object identified by namecycle if and only if the actual
1049/// object is a type suitable to be stored as a pointer to a "expectedClass"
1050/// If expectedClass is null, no check is performed.
1051///
1052/// - namecycle has the format name;cycle
1053/// - name = * is illegal, cycle = * is illegal
1054/// - cycle = "" or cycle = 9999 ==> apply to a memory object
1055///
1056/// ### Very important note
1057/// The calling application must cast the returned pointer to
1058/// the type described by the 2 arguments (i.e. cl):
1059///
1060/// auto objPtr = reinterpret_cast<MyClass*>(directory->GetObjectChecked("some object of MyClass","MyClass"));
1061///
1062/// Note: We recommend using the method TDirectoryFile::Get<T>:
1063/// ~~~{.cpp}
1064/// auto objPtr = directory->Get<MyClass>("some object inheriting from MyClass");
1065/// if (objPtr) { ... we found what we are looking for ... }
1066/// ~~~
1068void *TDirectoryFile::GetObjectChecked(const char *namecycle, const TClass* expectedClass)
1069{
1070
1071 // If the name is invalid, issue an error message and return a nullptr
1072 if (!namecycle || '\0' == namecycle[0]) {
1073 Error("GetObjectChecked", "The provided key name is invalid.");
1074 return nullptr;
1075 }
1076
1077 Short_t cycle;
1078 char name[kMaxLen];
1079
1080 DecodeNameCycle(namecycle, name, cycle, kMaxLen);
1081 Int_t nch = strlen(name);
1082 for (Int_t i = nch-1; i > 0; i--) {
1083 if (name[i] == '/') {
1084 name[i] = 0;
1085 TDirectory* dirToSearch=GetDirectory(name);
1086 const char *subnamecycle = namecycle + i + 1;
1087 name[i] = '/';
1088 if (dirToSearch) {
1089 return dirToSearch->GetObjectChecked(subnamecycle, expectedClass);
1090 } else {
1091 return nullptr;
1092 }
1093 }
1094 }
1095 const char *namobj = name;
1096
1097//*-*---------------------Case of Object in memory---------------------
1098// ========================
1099 if (expectedClass==0 || expectedClass->IsTObject()) {
1100 TObject *objcur = fList ? fList->FindObject(namobj) : nullptr;
1101 if (objcur) {
1102 if (objcur==this && strlen(namobj)!=0) {
1103 // The object has the same name has the directory and
1104 // that's what we picked-up! We just need to ignore
1105 // it ...
1106 objcur = nullptr;
1107 } else if (cycle == 9999) {
1108 // Check type
1109 if (expectedClass && objcur->IsA()->GetBaseClassOffset(expectedClass) == -1) return nullptr;
1110 else return objcur;
1111 } else {
1112 if (objcur->InheritsFrom(TCollection::Class()))
1113 objcur->Delete(); // delete also list elements
1114 delete objcur;
1115 objcur = nullptr;
1116 }
1117 }
1118 }
1119
1120//*-*---------------------Case of Key---------------------
1121// ===========
1122 auto listOfKeys = dynamic_cast<THashList *>(GetListOfKeys());
1123 if (!listOfKeys) {
1124 Error("GetObjectChecked", "Unexpected type of TDirectoryFile::fKeys!");
1125 return nullptr;
1126 }
1127
1128 if (const TList *keyList = listOfKeys->GetListForObject(namobj)) {
1129 for (auto key: TRangeDynCast<TKey>(*keyList)) {
1130 if (key && !strcmp(key->GetName(), namobj)
1131 && (cycle == 9999 || cycle == key->GetCycle())) {
1132 TDirectory::TContext ctxt(this);
1133 return key->ReadObjectAny(expectedClass);
1134 }
1135 }
1136 }
1137
1138 return nullptr;
1139}
1140
1141////////////////////////////////////////////////////////////////////////////////
1142/// Return the buffer size to create new TKeys.
1143///
1144/// If the stored fBufferSize is null, the value returned is the average
1145/// buffer size of objects in the file so far.
1148{
1149 if (fBufferSize <= 0) return fFile->GetBestBuffer();
1150 else return fBufferSize;
1151}
1152
1153
1154////////////////////////////////////////////////////////////////////////////////
1155/// Return pointer to key with name,cycle. If no key exists with the specified
1156/// cycle, returns the key with the highest cycle that is lower than the requested cycle.
1157///
1158/// if cycle = 9999 returns highest cycle
1160TKey *TDirectoryFile::GetKey(const char *name, Short_t cycle) const
1161{
1162 if (!fKeys) return nullptr;
1163
1164 auto listOfKeys = dynamic_cast<THashList *>(GetListOfKeys());
1165 if (!listOfKeys) {
1166 Error("GetKey", "Unexpected type of TDirectoryFile::fKeys!");
1167 return nullptr;
1168 }
1169
1170 if (const TList *keyList = listOfKeys->GetListForObject(name)) {
1171 for (auto key: TRangeDynCast<TKey>(*keyList)) {
1172 if (key && !strcmp(key->GetName(), name)
1173 && (cycle == 9999 || cycle >= key->GetCycle())) {
1174 return key;
1175 }
1176 }
1177 }
1178
1179 return nullptr;
1180}
1181
1182////////////////////////////////////////////////////////////////////////////////
1183/// List Directory contents
1184///
1185/// Indentation is used to identify the directory tree
1186/// Subdirectories are listed first, then objects in memory, then objects on the file
1187///
1188/// The option can has the following format: <b>`[-d |-m][<regexp>]`</b>
1189/// Options:
1190/// - -d: only list objects in the file
1191/// - -m: only list objects in memory
1192/// The `<regexp>` will be used to match the name of the objects.
1193/// By default memory and disk objects are listed.
1196{
1198 std::cout <<ClassName()<<"*\t\t"<<GetName()<<"\t"<<GetTitle()<<std::endl;
1200
1201 TString opta = option;
1202 TString opt = opta.Strip(TString::kBoth);
1203 Bool_t memobj = kTRUE;
1204 Bool_t diskobj = kTRUE;
1205 TString reg;
1206 if (opt.BeginsWith("-m")) {
1207 diskobj = kFALSE;
1208 if (opt.Length() > 2) {
1209 reg = opt(2,opt.Length());
1210 }
1211 } else if (opt.BeginsWith("-d")) {
1212 memobj = kFALSE;
1213 if (opt.Length() > 2) {
1214 reg = opt(2,opt.Length());
1215 }
1216 } else if (!opt.IsNull()) {
1217 reg = opt;
1218 }
1219
1220 TRegexp re(reg, kTRUE);
1221
1222 if (memobj) {
1223 TObject *obj;
1224 TIter nextobj(fList);
1225 while ((obj = (TObject *) nextobj())) {
1226 TString s = obj->GetName();
1227 if (!reg.IsNull() && s.Index(re) == kNPOS)
1228 continue;
1229 obj->ls(option); //*-* Loop on all the objects in memory
1230 }
1231 }
1232
1233 if (diskobj && fKeys) {
1234 //*-* Loop on all the keys
1235 for (TObjLink *lnk = fKeys->FirstLink(); lnk != nullptr; lnk = lnk->Next()) {
1236 TKey *key = (TKey*)lnk->GetObject();
1237 TString s = key->GetName();
1238 if (!reg.IsNull() && s.Index(re) == kNPOS)
1239 continue;
1240 bool first = (lnk->Prev() == nullptr) || (s != lnk->Prev()->GetObject()->GetName());
1241 bool hasbackup = (lnk->Next() != nullptr) && (s == lnk->Next()->GetObject()->GetName());
1242 if (first)
1243 if (hasbackup)
1244 key->ls(true);
1245 else
1246 key->ls();
1247 else
1248 key->ls(false);
1249 }
1250 }
1252}
1253
1254////////////////////////////////////////////////////////////////////////////////
1255/// Interface to TFile::Open
1257TFile *TDirectoryFile::OpenFile(const char *name, Option_t *option,const char *ftitle, Int_t compress, Int_t netopt)
1258{
1259 return TFile::Open(name,option,ftitle,compress,netopt);
1260
1261}
1262
1263////////////////////////////////////////////////////////////////////////////////
1264/// Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
1265///
1266/// @param name the name or hierarchy of the subdirectory ("a" or "a/b/c")
1267/// @param title the title of the directory. For hierarchies, this is only applied
1268/// to the innermost directory (so if `name == "a/b/c"` and `title == "my dir"`,
1269/// only `c` will have the title `"my dir"`).
1270/// @param returnExistingDirectory if key-name is already existing, the returned
1271/// value points to preexisting sub-directory if true and to `nullptr` if false.
1272/// @return a pointer to the created sub-directory, not to the top sub-directory
1273/// of the hierarchy (in the above example, the returned TDirectory * points
1274/// to "c"). In case of an error, it returns `nullptr`. In case of a preexisting
1275/// sub-directory (hierarchy) with the requested name, the return value depends
1276/// on the parameter returnExistingDirectory.
1278TDirectory *TDirectoryFile::mkdir(const char *name, const char *title, Bool_t returnExistingDirectory)
1279{
1280 if (!name || !title || !name[0]) return nullptr;
1281 if (!title[0]) title = name;
1282 if (GetKey(name)) {
1283 if (returnExistingDirectory)
1284 return (TDirectoryFile*) GetDirectory(name);
1285 else {
1286 Error("mkdir","An object with name %s exists already",name);
1287 return nullptr;
1288 }
1289 }
1290 if (const char *slash = strchr(name,'/')) {
1291 TString workname(name, Long_t(slash-name));
1292 TDirectoryFile *tmpdir = nullptr;
1293 GetObject(workname.Data(), tmpdir);
1294 if (!tmpdir) {
1295 // We give all intermediate directories a default title, as `title` is only given to the innermost dir.
1296 tmpdir = (TDirectoryFile *)mkdir(workname.Data(), "");
1297 if (!tmpdir) return nullptr;
1298 }
1299 return tmpdir->mkdir(slash + 1, title, returnExistingDirectory);
1300 }
1301
1302 TDirectory::TContext ctxt(this);
1303
1304 return new TDirectoryFile(name, title, "", this);
1305}
1306
1307////////////////////////////////////////////////////////////////////////////////
1308/// Purge lowest key cycles in a directory.
1309///
1310/// By default, only the highest cycle of a key is kept. Keys for which
1311/// the "KEEP" flag has been set are not removed. See TKey::Keep().
1312/// NOTE: This does not reduce the size of a TFile--
1313/// the space is simply freed up to be overwritten.
1316{
1317 if (!IsWritable()) return;
1318
1319 TDirectory::TContext ctxt(this);
1320
1321 TKey *key;
1323
1324 while ((key = (TKey*)prev())) { // reverse loop on keys
1325 TKey *keyprev = (TKey*)GetListOfKeys()->Before(key);
1326 if (!keyprev) break;
1327 if (key->GetKeep() == 0) {
1328 if (strcmp(key->GetName(), keyprev->GetName()) == 0) {
1329 key->Delete(); // Remove from the file.
1330 delete key; // Remove from memory.
1331 }
1332 }
1333 }
1334 TFile *f = GetFile();
1335 if (fModified && f) {
1336 WriteKeys(); // Write new keys structure
1337 WriteDirHeader(); // Write new directory header
1338 f->WriteFree(); // Write new free segments list
1339 f->WriteHeader(); // Write new file header
1340 }
1341}
1342
1343////////////////////////////////////////////////////////////////////////////////
1344/// Read objects from a ROOT file directory into memory.
1345///
1346/// If an object is already in memory, the memory copy is deleted
1347/// and the object is again read from the file.
1348/// If opt=="dirs", only subdirectories will be read
1349/// If opt=="dirs*" complete directory tree will be read
1352{
1353 TDirectory::TContext ctxt(this);
1354
1355 TKey *key;
1356 TIter next(GetListOfKeys());
1357
1358 Bool_t readdirs = ((opt!=0) && ((strcmp(opt,"dirs")==0) || (strcmp(opt,"dirs*")==0)));
1359
1360 if (readdirs)
1361 while ((key = (TKey *) next())) {
1362
1363 //if (strcmp(key->GetClassName(),"TDirectory")!=0) continue;
1364 if (strstr(key->GetClassName(),"TDirectory")==0) continue;
1365
1366 TDirectory *dir = GetDirectory(key->GetName(), kTRUE, "ReadAll");
1367
1368 if ((dir!=0) && (strcmp(opt,"dirs*")==0)) dir->ReadAll("dirs*");
1369 }
1370 else
1371 while ((key = (TKey *) next())) {
1372 TObject *thing = GetList()->FindObject(key->GetName());
1373 if (thing) { delete thing; }
1374 key->ReadObj();
1375 }
1376}
1377
1378////////////////////////////////////////////////////////////////////////////////
1379/// Read the linked list of keys.
1380///
1381/// Every directory has a linked list (fKeys). This linked list has been
1382/// written on the file via WriteKeys as a single data record.
1383///
1384/// It is interesting to call this function in the following situation.
1385/// Assume another process1 is connecting this directory in Update mode
1386/// - Process1 is adding/updating objects in this directory
1387/// - You want to see the latest status from process1.
1388/// Example Process1:
1389/// ~~~{.cpp}
1390/// obj1.Write();
1391/// obj2.Write();
1392/// gDirectory->SaveSelf();
1393/// ~~~
1394///
1395/// Example Process2:
1396/// ~~~{.cpp}
1397/// gDirectory->ReadKeys();
1398/// obj1->Draw();
1399/// ~~~
1400/// This is an efficient way (without opening/closing files) to view
1401/// the latest updates of a file being modified by another process
1402/// as it is typically the case in a data acquisition system.
1405{
1406 if (!fFile || !fKeys) return 0;
1407
1408 if (!fFile->IsBinary())
1409 return fFile->DirReadKeys(this);
1410
1411 TDirectory::TContext ctxt(this);
1412
1413 char *buffer;
1414 if (forceRead) {
1415 fKeys->Delete();
1416 //In case directory was updated by another process, read new
1417 //position for the keys
1419 char *header = new char[nbytes];
1420 buffer = header;
1422 if ( fFile->ReadBuffer(buffer,nbytes) ) {
1423 // ReadBuffer return kTRUE in case of failure.
1424 delete [] header;
1425 return 0;
1426 }
1427 buffer += fNbytesName;
1428 Version_t versiondir;
1429 frombuf(buffer,&versiondir);
1430 fDatimeC.ReadBuffer(buffer);
1431 fDatimeM.ReadBuffer(buffer);
1432 frombuf(buffer, &fNbytesKeys);
1433 frombuf(buffer, &fNbytesName);
1434 if (versiondir > 1000) {
1435 frombuf(buffer, &fSeekDir);
1436 frombuf(buffer, &fSeekParent);
1437 frombuf(buffer, &fSeekKeys);
1438 } else {
1439 Int_t sdir,sparent,skeys;
1440 frombuf(buffer, &sdir); fSeekDir = (Long64_t)sdir;
1441 frombuf(buffer, &sparent); fSeekParent = (Long64_t)sparent;
1442 frombuf(buffer, &skeys); fSeekKeys = (Long64_t)skeys;
1443 }
1444 delete [] header;
1445 }
1446
1447 Int_t nkeys = 0;
1448 Long64_t fsize = fFile->GetSize();
1449 if ( fSeekKeys > 0) {
1450 TKey *headerkey = new TKey(fSeekKeys, fNbytesKeys, this);
1451 headerkey->ReadFile();
1452 buffer = headerkey->GetBuffer();
1453 headerkey->ReadKeyBuffer(buffer);
1454
1455 TKey *key;
1456 frombuf(buffer, &nkeys);
1457 for (Int_t i = 0; i < nkeys; i++) {
1458 key = new TKey(this);
1459 key->ReadKeyBuffer(buffer);
1460 if (key->GetSeekKey() < 64 || key->GetSeekKey() > fsize) {
1461 Error("ReadKeys","reading illegal key, exiting after %d keys",i);
1462 fKeys->Remove(key);
1463 nkeys = i;
1464 break;
1465 }
1466 if (key->GetSeekPdir() < 64 || key->GetSeekPdir() > fsize) {
1467 Error("ReadKeys","reading illegal key, exiting after %d keys",i);
1468 fKeys->Remove(key);
1469 nkeys = i;
1470 break;
1471 }
1472 fKeys->Add(key);
1473 }
1474 delete headerkey;
1475 }
1476
1477 return nkeys;
1478}
1479
1480
1481////////////////////////////////////////////////////////////////////////////////
1482/// Read object with keyname from the current directory
1483///
1484/// Read contents of object with specified name from the current directory.
1485/// First the key with keyname is searched in the current directory,
1486/// next the key buffer is deserialized into the object.
1487/// The object must have been created before via the default constructor.
1488/// See TObject::Write().
1490Int_t TDirectoryFile::ReadTObject(TObject *obj, const char *keyname)
1491{
1492 if (!fFile) { Error("ReadTObject","No file open"); return 0; }
1493 auto listOfKeys = dynamic_cast<THashList *>(GetListOfKeys());
1494 if (!listOfKeys) {
1495 Error("ReadTObject", "Unexpected type of TDirectoryFile::fKeys!");
1496 return 0;
1497 }
1498
1499 if (const TList *keyList = listOfKeys->GetListForObject(keyname)) {
1500 for (auto key: TRangeDynCast<TKey>(*keyList)) {
1501 if (key && !strcmp(key->GetName(), keyname) ) {
1502 return key->Read(obj);
1503 }
1504 }
1505 }
1506
1507 Error("ReadTObject","Key not found");
1508 return 0;
1509}
1510
1511////////////////////////////////////////////////////////////////////////////////
1512/// Reset the TDirectory after its content has been merged into another
1513/// Directory.
1514///
1515/// This returns the TDirectoryFile object back to its state
1516/// before any data has been written to the file.
1517/// The object in the in-memory list are assumed to also have been reset.
1520{
1521 // There is nothing to reset in the base class (TDirectory) since
1522 // we do want to key the list of in-memory object as is.
1523 fModified = kFALSE;
1524 // Does not change: fWritable
1525 fDatimeC.Set();
1526 fDatimeM.Set();
1527 fNbytesKeys = 0; // updated when the keys are written
1528 fNbytesName = 0; // updated by Init
1529 // Does not change (user customization): fBufferSize;
1530 fSeekDir = 0; // updated by Init
1531 fSeekParent = 0; // updated by Init
1532 fSeekKeys = 0; // updated by Init
1533 // Does not change: fFile
1534 TKey *key = fKeys ? (TKey*)fKeys->FindObject(fName) : nullptr;
1535 TClass *cl = IsA();
1536 if (key) {
1537 cl = TClass::GetClass(key->GetClassName());
1538 }
1539 // NOTE: We should check that the content is really mergeable and in
1540 // the in-mmeory list, before deleting the keys.
1541 if (fKeys) {
1542 fKeys->Delete("slow");
1543 }
1544
1546
1547 // Do the same with the sub-directories.
1548 TIter next(GetList());
1549 TObject *idcur;
1550 while ((idcur = next())) {
1551 if (idcur->IsA() == TDirectoryFile::Class()) {
1552 ((TDirectoryFile*)idcur)->ResetAfterMerge(info);
1553 }
1554 }
1555
1556}
1557
1558////////////////////////////////////////////////////////////////////////////////
1559/// Removes subdirectory from the directory
1560///
1561/// When directory is deleted, all keys in all subdirectories will be
1562/// read first and deleted from file (if exists)
1563/// Equivalent call is Delete("name;*");
1565void TDirectoryFile::rmdir(const char *name)
1566{
1567 if (!name || (*name==0)) return;
1568
1569 TString mask(name);
1570 mask += ";*";
1571 Delete(mask);
1572}
1573
1574////////////////////////////////////////////////////////////////////////////////
1575/// Save recursively all directory keys and headers
1578{
1579 TDirectory::TContext ctxt(this);
1580
1581 SaveSelf();
1582
1583 // recursively save all sub-directories
1584 if (fList && fList->FirstLink()) {
1585 auto lnk = fList->FirstLink()->shared_from_this();
1586 while (lnk) {
1587 TObject *idcur = lnk->GetObject();
1588 if (TDirectoryFile *dir = dynamic_cast<TDirectoryFile *>(idcur)) {
1589 dir->Save();
1590 }
1591 lnk = lnk->NextSP();
1592 }
1593 }
1594}
1595
1596////////////////////////////////////////////////////////////////////////////////
1597/// Save object in filename.
1598///
1599/// If filename is `nullptr` or "", a file with "<objectname>.root" is created.
1600/// The name of the key is the object name.
1601/// By default new file will be created. Using option "a", one can append object
1602/// to the existing ROOT file.
1603/// If the operation is successful, it returns the number of bytes written to the file
1604/// otherwise it returns 0.
1605/// By default a message is printed. Use option "q" to not print the message.
1606/// If filename contains ".json" extension, JSON representation of the object
1607/// will be created and saved in the text file. Such file can be used in
1608/// JavaScript ROOT (https://root.cern/js/) to display object in web browser
1609/// When creating JSON file, option string may contain compression level from 0 to 3 (default 0)
1611Int_t TDirectoryFile::SaveObjectAs(const TObject *obj, const char *filename, Option_t *option) const
1612{
1613 // option can contain single letter args: "a" for append, "q" for quiet in any combinations
1614
1615 if (!obj) return 0;
1616 TString fname, opt = option;
1617 if (filename && *filename)
1618 fname = filename;
1619 else
1620 fname.Form("%s.root", obj->GetName());
1621 opt.ToLower();
1622
1623 Int_t nbytes = 0;
1624 if (fname.Index(".json") > 0) {
1625 nbytes = TBufferJSON::ExportToFile(fname, obj, option);
1626 } else {
1627 TContext ctxt; // The TFile::Open will change the current directory.
1628 auto *local = TFile::Open(fname.Data(), opt.Contains("a") ? "update" : "recreate");
1629 if (!local) return 0;
1630 nbytes = obj->Write();
1631 delete local;
1632 }
1633 if (!opt.Contains("q") && !gSystem->AccessPathName(fname.Data()))
1634 obj->Info("SaveAs", "ROOT file %s has been created", fname.Data());
1635 return nbytes;
1636}
1637
1638////////////////////////////////////////////////////////////////////////////////
1639/// Save Directory keys and header
1640///
1641/// If the directory has been modified (fModified set), write the keys
1642/// and the directory header. This function assumes the cd is correctly set.
1643///
1644/// It is recommended to use this function in the following situation:
1645/// Assume a process1 using a directory in Update mode
1646/// - New objects or modified objects have been written to the directory.
1647/// - You do not want to close the file.
1648/// - You want your changes be visible from another process2 already connected
1649/// to this directory in read mode.
1650/// - Call this function.
1651/// - In process2, use TDirectoryFile::ReadKeys to refresh the directory.
1654{
1655 if (IsWritable() && (fModified || force) && fFile) {
1656 Bool_t dowrite = kTRUE;
1657 if (fFile->GetListOfFree())
1658 dowrite = fFile->GetListOfFree()->First() != nullptr;
1659 if (dowrite) {
1660 TDirectory *dirsav = gDirectory;
1661 if (dirsav != this) cd();
1662 WriteKeys(); //*-*- Write keys record
1663 WriteDirHeader(); //*-*- Update directory record
1664 if (dirsav && dirsav != this) dirsav->cd();
1665 }
1666 }
1667}
1668
1669////////////////////////////////////////////////////////////////////////////////
1670/// Set the default buffer size when creating new TKeys.
1671///
1672/// See also TDirectoryFile::GetBufferSize
1675{
1676 fBufferSize = bufsize;
1677}
1678
1679////////////////////////////////////////////////////////////////////////////////
1680/// Find the action to be executed in the dictionary of the parent class
1681/// and store the corresponding exec number into fBits.
1682///
1683/// This function searches a data member in the class of parent with an
1684/// offset corresponding to this.
1685/// If a comment "TEXEC:" is found in the comment field of the data member,
1686/// the function stores the exec identifier of the exec statement
1687/// following this keyword.
1690{
1691 Int_t offset = (char*)ref - (char*)parent;
1692 TClass *cl = parent->IsA();
1693 cl->BuildRealData(parent);
1695 TIter next(info->GetElements());
1696 TStreamerElement *element;
1697 while((element = (TStreamerElement*)next())) {
1698 if (element->GetOffset() != offset) continue;
1699 Int_t execid = element->GetExecID();
1700 if (execid > 0) ref->SetBit(execid << 8);
1701 return;
1702 }
1703}
1704
1705////////////////////////////////////////////////////////////////////////////////
1706/// Set the new value of fWritable recursively
1709{
1710 TDirectory::TContext ctxt(this);
1711
1712 fWritable = writable;
1713
1714 // recursively set all sub-directories
1715 if (fList) {
1716 TObject *idcur;
1717 TIter next(fList);
1718 while ((idcur = next())) {
1719 if (idcur->InheritsFrom(TDirectoryFile::Class())) {
1720 TDirectoryFile *dir = (TDirectoryFile*)idcur;
1721 dir->SetWritable(writable);
1722 }
1723 }
1724 }
1725}
1726
1727
1728////////////////////////////////////////////////////////////////////////////////
1729/// Return the size in bytes of the directory header
1732{
1733 Int_t nbytes = 22;
1734
1735 nbytes += fDatimeC.Sizeof();
1736 nbytes += fDatimeM.Sizeof();
1737 nbytes += fUUID.Sizeof();
1738 //assume that the file may be above 2 Gbytes if file version is > 4
1739 if (fFile && fFile->GetVersion() >= 40000) nbytes += 12;
1740 return nbytes;
1741}
1742
1743
1744////////////////////////////////////////////////////////////////////////////////
1745/// Stream a class object
1748{
1749 Version_t v,version;
1750 if (b.IsReading()) {
1751 BuildDirectoryFile((TFile*)b.GetParent(), nullptr);
1752 if (fFile && fFile->IsWritable()) fWritable = kTRUE;
1753
1754 if (fFile && !fFile->IsBinary()) {
1755 Version_t R__v = b.ReadVersion(0, 0);
1756
1757 TClass* dirclass = (R__v < 5) ? TDirectory::Class() : TDirectoryFile::Class();
1758
1759 b.ClassBegin(dirclass, R__v);
1760
1761 TString sbuf;
1762
1763 b.ClassMember("CreateTime","TString");
1764 sbuf.Streamer(b);
1765 TDatime timeC(sbuf.Data());
1766 fDatimeC = timeC;
1767
1768 b.ClassMember("ModifyTime","TString");
1769 sbuf.Streamer(b);
1770 TDatime timeM(sbuf.Data());
1771 fDatimeM = timeM;
1772
1773 b.ClassMember("UUID","TString");
1774 sbuf.Streamer(b);
1775 TUUID id(sbuf.Data());
1776 fUUID = id;
1777
1778 b.ClassEnd(dirclass);
1779
1780 fSeekKeys = 0; // read keys later in the TKeySQL class
1781 } else {
1782 b >> version;
1785 b >> fNbytesKeys;
1786 b >> fNbytesName;
1787 if (version > 1000) {
1789 b >> fSeekDir;
1790 b >> fSeekParent;
1791 b >> fSeekKeys;
1792 } else {
1793 Int_t sdir,sparent,skeys;
1794 b >> sdir; fSeekDir = (Long64_t)sdir;
1795 b >> sparent; fSeekParent = (Long64_t)sparent;
1796 b >> skeys; fSeekKeys = (Long64_t)skeys;
1797 }
1798 v = version%1000;
1799 if (v == 2) {
1801 } else if (v > 2) {
1802 fUUID.Streamer(b);
1803 }
1804 }
1805 fList->UseRWLock();
1807 gROOT->GetUUIDs()->AddUUID(fUUID,this);
1808 if (fSeekKeys) ReadKeys();
1809 } else {
1810 if (fFile && !fFile->IsBinary()) {
1811 b.WriteVersion(TDirectoryFile::Class());
1812
1813 TString sbuf;
1814
1815 b.ClassBegin(TDirectoryFile::Class());
1816
1817 b.ClassMember("CreateTime","TString");
1818 sbuf = fDatimeC.AsSQLString();
1819 sbuf.Streamer(b);
1820
1821 b.ClassMember("ModifyTime","TString");
1822 fDatimeM.Set();
1823 sbuf = fDatimeM.AsSQLString();
1824 sbuf.Streamer(b);
1825
1826 b.ClassMember("UUID","TString");
1827 sbuf = fUUID.AsString();
1828 sbuf.Streamer(b);
1829
1830 b.ClassEnd(TDirectoryFile::Class());
1831 } else {
1833 if (fFile && fFile->GetEND() > TFile::kStartBigFile) version += 1000;
1834 b << version;
1837 b << fNbytesKeys;
1838 b << fNbytesName;
1839 if (version > 1000) {
1840 b << fSeekDir;
1841 b << fSeekParent;
1842 b << fSeekKeys;
1843 } else {
1844 b << (Int_t)fSeekDir;
1845 b << (Int_t)fSeekParent;
1846 b << (Int_t)fSeekKeys;
1847 }
1848 fUUID.Streamer(b);
1849 if (version <=1000) for (Int_t i=0;i<3;i++) b << Int_t(0);
1850 }
1851 }
1852}
1853
1854////////////////////////////////////////////////////////////////////////////////
1855/// Write all objects in memory to disk.
1856///
1857/// Loop on all objects in memory (including subdirectories).
1858/// A new key is created in the keys linked list for each object.
1859/// For allowed options see TObject::Write().
1860/// The directory header info is rewritten on the directory header record.
1862Int_t TDirectoryFile::Write(const char *, Int_t opt, Int_t bufsize)
1863{
1864 if (!IsWritable()) return 0;
1865 TDirectory::TContext ctxt(this);
1866
1867 // Loop on all objects (including subdirs)
1868 TIter next(fList);
1869 TObject *obj;
1870 Int_t nbytes = 0;
1871 while ((obj=next())) {
1872 nbytes += obj->Write(0,opt,bufsize);
1873 }
1874 if (R__likely(!(opt & kOnlyPrepStep)))
1875 SaveSelf(kTRUE); // force save itself
1876
1877 return nbytes;
1878}
1879
1880////////////////////////////////////////////////////////////////////////////////
1881/// One can not save a const TDirectory object.
1883Int_t TDirectoryFile::Write(const char *n, Int_t opt, Int_t bufsize) const
1884{
1885 Error("Write const","A const TDirectory object should not be saved. We try to proceed anyway.");
1886 return const_cast<TDirectoryFile*>(this)->Write(n, opt, bufsize);
1887}
1888
1889////////////////////////////////////////////////////////////////////////////////
1890/// Write object obj to this directory.
1891///
1892/// The data structure corresponding to this object is serialized.
1893/// The corresponding buffer is written to this directory
1894/// with an associated key with name "name".
1895///
1896/// Writing an object to a file involves the following steps:
1897/// - Creation of a support TKey object in the directory. The TKey object
1898/// creates a TBuffer object.
1899/// - The TBuffer object is filled via the class::Streamer function.
1900/// - If the file is compressed (default) a second buffer is created to hold
1901/// the compressed buffer.
1902/// - Reservation of the corresponding space in the file by looking in the
1903/// TFree list of free blocks of the file.
1904/// - The buffer is written to the file.
1905///
1906/// By default, the buffersize will be taken from the average buffer size
1907/// of all objects written to the current file so far.
1908/// Use TDirectoryFile::SetBufferSize to force a given buffer size.
1909///
1910/// If a name is specified, it will be the name of the key.
1911/// If name is not given, the name of the key will be the name as returned
1912/// by obj->GetName().
1913///
1914/// The option can be a combination of:
1915/// - "SingleKey"
1916/// - "Overwrite"
1917/// - "WriteDelete"
1918/// Using the "Overwrite" option a previous key with the same name is
1919/// overwritten. The previous key is deleted before writing the new object.
1920/// Using the "WriteDelete" option a previous key with the same name is
1921/// deleted only after the new object has been written. This option
1922/// is safer than kOverwrite but it is slower.
1923/// The "SingleKey" option is only used by TCollection::Write() to write
1924/// a container with a single key instead of each object in the container
1925/// with its own key.
1926/// An object is read from this directory via TDirectoryFile::Get.
1927/// The function returns the total number of bytes written to the directory.
1928/// It returns 0 if the object cannot be written.
1929///
1930/// WARNING: avoid special characters like '^','$','.' in the name as they
1931/// are used by the regular expression parser (see TRegexp).
1933Int_t TDirectoryFile::WriteTObject(const TObject *obj, const char *name, Option_t *option, Int_t bufsize)
1934{
1935 TDirectory::TContext ctxt(this);
1936
1937 if (fFile==0) {
1938 const char *objname = "no name specified";
1939 if (name) objname = name;
1940 else if (obj) objname = obj->GetName();
1941 Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.",GetName(),objname);
1942 return 0;
1943 }
1944
1945 if (!fFile->IsWritable()) {
1947 // Do not print the error if the file already had a SysError.
1948 Error("WriteTObject","Directory %s is not writable", fFile->GetName());
1949 }
1950 return 0;
1951 }
1952
1953 if (!obj) return 0;
1954
1955 TString opt = option;
1956 opt.ToLower();
1957
1958 TKey *key=0, *oldkey=0;
1959 Int_t bsize = GetBufferSize();
1960 if (bufsize > 0) bsize = bufsize;
1961
1962 const char *oname;
1963 if (name && *name)
1964 oname = name;
1965 else
1966 oname = obj->GetName();
1967
1968 // Remove trailing blanks in object name
1969 Int_t nch = strlen(oname);
1970 char *newName = nullptr;
1971 if (nch && oname[nch-1] == ' ') {
1972 Warning("WriteTObject", "The key name '%s' will be stored in file without the trailing blanks.", obj->GetName());
1973 // See https://github.com/root-project/root/issues/17003
1974 newName = new char[nch+1];
1975 strlcpy(newName,oname,nch+1);
1976 for (Int_t i=0;i<nch;i++) {
1977 if (newName[nch-i-1] != ' ') break;
1978 newName[nch-i-1] = 0;
1979 }
1980 oname = newName;
1981 }
1982
1983 if (opt.Contains("overwrite")) {
1984 //One must use GetKey. FindObject would return the lowest cycle of the key!
1985 //key = (TKey*)gDirectory->GetListOfKeys()->FindObject(oname);
1986 key = GetKey(oname);
1987 if (key) {
1988 key->Delete();
1989 delete key;
1990 }
1991 }
1992 if (opt.Contains("writedelete")) {
1993 oldkey = GetKey(oname);
1994 }
1995 key = fFile->CreateKey(this, obj, oname, bsize);
1996 if (newName) delete [] newName;
1997
1998 if (!key->GetSeekKey()) {
1999 fKeys->Remove(key);
2000 delete key;
2001 if (bufsize) fFile->SetBufferSize(bufsize);
2002 return 0;
2003 }
2004 fFile->SumBuffer(key->GetObjlen());
2005 Int_t nbytes = key->WriteFile(0);
2007 if (bufsize) fFile->SetBufferSize(bufsize);
2008 return 0;
2009 }
2010 if (oldkey) {
2011 oldkey->Delete();
2012 delete oldkey;
2013 }
2014 if (bufsize) fFile->SetBufferSize(bufsize);
2015
2016 return nbytes;
2017}
2019Int_t TDirectoryFile::WriteObjectAny(const void *obj, const TClass *cl,
2020 std::pair<const char *, const char *> nameAndTitle, Option_t *option,
2021 Int_t bufsize)
2022{
2023 const auto [name, title] = nameAndTitle;
2024
2025 TDirectory::TContext ctxt(this);
2026
2027 if (!fFile) return 0;
2028
2029 if (!cl) {
2030 Error("WriteObject","Unknown type for %s, it can not be written.",name);
2031 return 0;
2032 }
2033
2034 if (!fFile->IsWritable()) {
2036 // Do not print the error if the file already had a SysError.
2037 Error("WriteObject","File %s is not writable", fFile->GetName());
2038 }
2039 return 0;
2040 }
2041
2042 if (!obj) return 0;
2043
2044 const char *className = cl->GetName();
2045 const char *oname;
2046 if (name && *name)
2047 oname = name;
2048 else
2049 oname = className;
2050
2051 if (cl && cl->GetCollectionProxy() && dynamic_cast<TEmulatedCollectionProxy*>(cl->GetCollectionProxy())) {
2052 Error("WriteObjectAny",
2053 "The class requested (%s) for the key name \"%s\""
2054 " is an instance of an stl collection and does not have a compiled CollectionProxy."
2055 " Please generate the dictionary for this collection (%s). No data will be written.",
2056 className, oname, className);
2057 return 0;
2058 }
2059
2060 TKey *key, *oldkey = nullptr;
2061 Int_t bsize = GetBufferSize();
2062 if (bufsize > 0) bsize = bufsize;
2063
2064 TString opt = option;
2065 opt.ToLower();
2066
2067 // Remove trailing blanks in object name
2068 Int_t nch = strlen(oname);
2069 char *newName = nullptr;
2070 if (nch && oname[nch-1] == ' ') {
2071 newName = new char[nch+1];
2072 strlcpy(newName,oname,nch+1);
2073 for (Int_t i=0;i<nch;i++) {
2074 if (newName[nch-i-1] != ' ') break;
2075 newName[nch-i-1] = 0;
2076 }
2077 oname = newName;
2078 }
2079
2080 if (opt.Contains("overwrite")) {
2081 //One must use GetKey. FindObject would return the lowest cycle of the key!
2082 //key = (TKey*)gDirectory->GetListOfKeys()->FindObject(oname);
2083 key = GetKey(oname);
2084 if (key) {
2085 key->Delete();
2086 delete key;
2087 }
2088 }
2089 if (opt.Contains("writedelete")) {
2090 oldkey = GetKey(oname);
2091 }
2092 key = fFile->CreateKey(this, obj, cl, oname, bsize);
2093 key->SetTitle(title);
2094 if (newName) delete [] newName;
2095
2096 if (!key->GetSeekKey()) {
2097 fKeys->Remove(key);
2098 delete key;
2099 return 0;
2100 }
2101 fFile->SumBuffer(key->GetObjlen());
2102 Int_t nbytes = key->WriteFile(0);
2103 if (fFile->TestBit(TFile::kWriteError)) return 0;
2104
2105 if (oldkey) {
2106 oldkey->Delete();
2107 delete oldkey;
2108 }
2109
2110 return nbytes;
2111}
2112
2113////////////////////////////////////////////////////////////////////////////////
2114/// Write object from pointer of class classname in this directory.
2115///
2116/// obj may not derive from TObject. See TDirectoryFile::WriteTObject for comments
2117///
2118/// ## Very important note
2119/// The value passed as 'obj' needs to be from a pointer to the type described by classname.
2120/// For example:
2121/// ~~~{.cpp}
2122/// TopClass *top;
2123/// BottomClass *bottom;
2124/// top = bottom;
2125/// ~~~
2126/// you can do:
2127/// ~~~{.cpp}
2128/// directory->WriteObjectAny(top,"top","name of object");
2129/// directory->WriteObjectAny(bottom,"bottom","name of object");
2130/// ~~~
2131/// <b>BUT YOU CAN NOT DO</b> the following since it will fail with multiple inheritance:
2132/// ~~~{.cpp}
2133/// directory->WriteObjectAny(top,"bottom","name of object");
2134/// ~~~
2135/// We <b>STRONGLY</b> recommend to use
2136/// ~~~{.cpp}
2137/// TopClass *top = ....;
2138/// directory->WriteObject(top,"name of object")
2139/// ~~~
2140/// See also remarks in TDirectoryFile::WriteTObject
2142Int_t TDirectoryFile::WriteObjectAny(const void *obj, const char *classname, const char *name, Option_t *option, Int_t bufsize)
2143{
2144 TClass *cl = TClass::GetClass(classname);
2145 if (!cl) {
2146 TObject *info_obj = *(TObject**)obj;
2147 TVirtualStreamerInfo *info = dynamic_cast<TVirtualStreamerInfo*>(info_obj);
2148 if (!info) {
2149 Error("WriteObjectAny","Unknown class: %s",classname);
2150 return 0;
2151 } else {
2152 cl = info->GetClass();
2153 }
2154 }
2155 return WriteObjectAny(obj,cl,name,option,bufsize);
2156}
2157
2158////////////////////////////////////////////////////////////////////////////////
2159/// Write object of class with dictionary cl in this directory.
2160///
2161/// obj may not derive from TObject
2162/// To get the TClass* cl pointer, one can use
2163///
2164/// TClass *cl = TClass::GetClass("classname");
2165///
2166/// An alternative is to call the function WriteObjectAny above.
2167/// see TDirectoryFile::WriteTObject for comments
2169Int_t TDirectoryFile::WriteObjectAny(const void *obj, const TClass *cl, const char *name, Option_t *option, Int_t bufsize)
2170{
2171 return WriteObjectAny(obj, cl, {name, ""}, option, bufsize);
2172}
2173
2174////////////////////////////////////////////////////////////////////////////////
2175/// Overwrite the Directory header record.
2178{
2179 TFile* f = GetFile();
2180 if (!f) return;
2181
2182 if (!f->IsBinary()) {
2183 fDatimeM.Set();
2184 f->DirWriteHeader(this);
2185 return;
2186 }
2187
2188 Int_t nbytes = TDirectoryFile::Sizeof(); //Warning ! TFile has a Sizeof()
2189 char *header = new char[nbytes];
2190 char *buffer = header;
2191 fDatimeM.Set();
2193 Long64_t pointer = fSeekDir + fNbytesName; // do not overwrite the name/title part
2194 fModified = kFALSE;
2195 f->Seek(pointer);
2196 f->WriteBuffer(header, nbytes);
2197 if (f->MustFlush()) f->Flush();
2198 delete [] header;
2199}
2200
2201////////////////////////////////////////////////////////////////////////////////
2202/// Write Keys linked list on the file.
2203///
2204/// The linked list of keys (fKeys) is written as a single data record
2207{
2208 TFile* f = GetFile();
2209 if (!f) return;
2210
2211 if (!f->IsBinary()) {
2212 f->DirWriteKeys(this);
2213 return;
2214 }
2215
2216//*-* Delete the old keys structure if it exists
2217 if (fSeekKeys != 0) {
2218 f->MakeFree(fSeekKeys, fSeekKeys + fNbytesKeys -1);
2219 }
2220//*-* Write new keys record
2221 TIter next(fKeys);
2222 TKey *key;
2223 Int_t nkeys = fKeys->GetSize();
2224 Int_t nbytes = sizeof nkeys; //*-* Compute size of all keys
2225 if (f->GetEND() > TFile::kStartBigFile) nbytes += 8;
2226 while ((key = (TKey*)next())) {
2227 nbytes += key->Sizeof();
2228 }
2229 TKey *headerkey = new TKey(fName,fTitle,IsA(),nbytes,this);
2230 if (headerkey->GetSeekKey() == 0) {
2231 delete headerkey;
2232 return;
2233 }
2234 char *buffer = headerkey->GetBuffer();
2235 next.Reset();
2236 tobuf(buffer, nkeys);
2237 while ((key = (TKey*)next())) {
2238 key->FillBuffer(buffer);
2239 }
2240
2241 fSeekKeys = headerkey->GetSeekKey();
2242 fNbytesKeys = headerkey->GetNbytes();
2243 headerkey->WriteFile();
2244 delete headerkey;
2245}
void frombuf(char *&buf, Bool_t *x)
Definition Bytes.h:270
void tobuf(char *&buf, Bool_t x)
Definition Bytes.h:55
std::string className
Definition JSONIO.cxx:31
#define R__likely(expr)
Definition RConfig.hxx:569
#define SafeDelete(p)
Definition RConfig.hxx:507
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
short Version_t
Class version identifier (short)
Definition RtypesCore.h:80
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:132
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:84
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
#define BIT(n)
Definition Rtypes.h:90
const Bool_t kIterBackward
Definition TCollection.h:43
const Int_t kMaxLen
const UInt_t kIsBigFile
const Int_t kMaxLen
#define gDirectory
Definition TDirectory.h:385
#define gFile
Definition TFile.h:441
Option_t Option_t option
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 mask
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 filename
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void reg
char name[80]
Definition TGX11.cxx:142
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:792
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:417
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
#define R__LOCKGUARD(mutex)
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Definition TBufferFile.h:47
void MapObject(const TObject *obj, UInt_t offset=1) override
Add object to the fMap container.
void ResetMap() override
Delete existing fMap and reset map counter.
static Int_t ExportToFile(const char *filename, const TObject *obj, const char *option=nullptr)
Convert object into JSON and store in text file Returns size of the produce file Used in TObject::Sav...
Buffer base class used for serializing objects.
Definition TBuffer.h:43
@ kWrite
Definition TBuffer.h:73
void SetBufferOffset(Int_t offset=0)
Definition TBuffer.h:93
void SetReadMode()
Set buffer in read mode.
Definition TBuffer.cxx:301
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:5107
ROOT::DirAutoAdd_t GetDirectoryAutoAdd() const
Return the wrapper around the directory auto add function.
Definition TClass.cxx:7729
void BuildRealData(void *pointer=nullptr, Bool_t isTransient=kFALSE)
Build a full list of persistent data members.
Definition TClass.cxx:2043
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition TClass.cxx:6114
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0, Bool_t isTransient=kFALSE) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist,...
Definition TClass.cxx:4716
Int_t GetBaseClassOffset(const TClass *toBase, void *address=nullptr, bool isDerivedObject=true)
Definition TClass.cxx:2817
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition TClass.cxx:2923
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.
Definition TClass.cxx:2999
static TClass * Class()
virtual bool UseRWLock(Bool_t enable=true)
Set this collection to use a RW lock upon access, making it thread safe.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
void FillBuffer(char *&buffer)
Encode Date/Time into buffer, used by I/O system.
Definition TDatime.cxx:225
const char * AsSQLString() const
Return the date & time in SQL compatible string format, like: 1997-01-15 20:16:28.
Definition TDatime.cxx:148
Int_t Sizeof() const
Definition TDatime.h:81
virtual void Streamer(TBuffer &)
Stream a object of type TDatime.
Definition TDatime.cxx:412
void Set()
Set Date/Time to current time as reported by the system.
Definition TDatime.cxx:285
void ReadBuffer(char *&buffer)
Decode Date/Time from output buffer, used by I/O system.
Definition TDatime.cxx:274
A ROOT file is structured in Directories (like a file system).
void SetBufferSize(Int_t bufsize) override
Set the default buffer size when creating new TKeys.
void SetTRefAction(TObject *ref, TObject *parent) override
Find the action to be executed in the dictionary of the parent class and store the corresponding exec...
void Close(Option_t *option="") override
Delete all objects from memory and directory structure itself.
Bool_t cd() override
Change current directory to "this" directory.
TFile * fFile
Pointer to current file in memory.
void Browse(TBrowser *b) override
Browse the content of the directory.
void Append(TObject *obj, Bool_t replace=kFALSE) override
Append object to this directory.
void SaveSelf(Bool_t force=kFALSE) override
Save Directory keys and header.
static TClass * Class()
Bool_t IsWritable() const override
void Streamer(TBuffer &) override
Stream a class object.
void Delete(const char *namecycle="") override
Delete Objects or/and keys in the current directory.
virtual void ResetAfterMerge(TFileMergeInfo *)
Reset the TDirectory after its content has been merged into another Directory.
Int_t AppendKey(TKey *key) override
Insert key in the linked list of keys of this directory.
Int_t ReadKeys(Bool_t forceRead=kTRUE) override
Read the linked list of keys.
TDatime fDatimeM
Date and time of last modification.
void * GetObjectUnchecked(const char *namecycle) override
Return pointer to object identified by namecycle.
TKey * FindKey(const char *keyname) const override
Find key with name keyname in the current directory.
TKey * GetKey(const char *name, Short_t cycle=9999) const override
Return pointer to key with name,cycle.
void * GetObjectChecked(const char *namecycle, const char *classname) override
See documentation of TDirectoryFile::GetObjectChecked(const char*,const TClass*).
void InitDirectoryFile(TClass *cl=nullptr)
Initialize the key associated with this directory (and the related data members.
void Purge(Short_t nkeep=1) override
Purge lowest key cycles in a directory.
void Save() override
Save recursively all directory keys and headers.
~TDirectoryFile() override
Destructor.
TObject * FindObjectAnyFile(const char *name) const override
Scan the memory lists of all files for an object with name.
Int_t fNbytesKeys
Number of bytes for the keys.
Bool_t fModified
True if directory has been modified.
TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE) override
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
TList * GetListOfKeys() const override
void CleanTargets()
Clean the pointers to this object (gDirectory, TContext, etc.)
TObject * FindObjectAny(const char *name) const override
Find object by name in the list of memory objects of the current directory or its sub-directories.
Long64_t fSeekKeys
Location of Keys record on file.
void WriteKeys() override
Write Keys linked list on the file.
TFile * GetFile() const override
Int_t fBufferSize
Default buffer size to create new TKeys.
Int_t Sizeof() const override
Return the size in bytes of the directory header.
TObject * CloneObject(const TObject *obj, Bool_t autoadd=kTRUE) override
Make a clone of an object using the Streamer facility.
TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory") override
Find a directory named "apath".
Long64_t fSeekParent
Location of parent directory on file.
Int_t WriteObjectAny(const void *obj, const char *classname, const char *name, Option_t *option="", Int_t bufsize=0) override
Write object from pointer of class classname in this directory.
void BuildDirectoryFile(TFile *motherFile, TDirectory *motherDir)
Initialise directory to defaults.
void rmdir(const char *name) override
Removes subdirectory from the directory.
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override
Write all objects in memory to disk.
Long64_t fSeekDir
Location of directory on file.
Int_t fNbytesName
Number of bytes in TNamed at creation time.
TDatime fDatimeC
Date and time when directory is created.
Bool_t fWritable
True if directory is writable.
Int_t WriteTObject(const TObject *obj, const char *name=nullptr, Option_t *option="", Int_t bufsize=0) override
Write object obj to this directory.
Int_t ReadTObject(TObject *obj, const char *keyname) override
Read object with keyname from the current directory.
TFile * OpenFile(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0) override
Interface to TFile::Open.
Int_t GetBufferSize() const override
Return the buffer size to create new TKeys.
Int_t SaveObjectAs(const TObject *obj, const char *filename="", Option_t *option="") const override
Save object in filename.
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
static constexpr Version_t Class_Version()
TDirectoryFile()
Default TDirectoryFile constructor.
TKey * FindKeyAny(const char *keyname) const override
Find key with name keyname in the current directory or its subdirectories.
void FillBuffer(char *&buffer) override
Encode directory header into output buffer.
void WriteDirHeader() override
Overwrite the Directory header record.
void SetWritable(Bool_t writable=kTRUE) override
Set the new value of fWritable recursively.
TClass * IsA() const override
void ReadAll(Option_t *option="") override
Read objects from a ROOT file directory into memory.
TList * fKeys
Pointer to keys list in memory.
void ls(Option_t *option="") const override
List Directory contents.
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
Describe directory structure in memory.
Definition TDirectory.h:45
virtual Long64_t GetSeekDir() const
Definition TDirectory.h:229
static TClass * Class()
void Delete(const char *namecycle="") override
Delete Objects or/and keys in a directory.
virtual TList * GetList() const
Definition TDirectory.h:223
virtual Int_t AppendKey(TKey *)
Definition TDirectory.h:185
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual void ReadAll(Option_t *="")
Definition TDirectory.h:248
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
static size_t DecodeNameCycle(const char *namecycle, char *name, Short_t &cycle, const size_t namesize=0)
Decode a namecycle "aap;2" contained in the null-terminated string buffer into name "aap" and cycle 2...
void CleanTargets()
Clean the pointers to this object (gDirectory, TContext, etc.).
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
virtual TFile * GetFile() const
Definition TDirectory.h:221
TObject * FindObject(const char *name) const override
Find object by name in the list of memory objects.
virtual Bool_t cd()
Change current directory to "this" directory.
TUUID fUUID
Unique identifier.
Definition TDirectory.h:143
TDirectory * GetMotherDir() const
Definition TDirectory.h:226
TObject * fMother
pointer to mother of the directory
Definition TDirectory.h:141
void GetObject(const char *namecycle, T *&ptr)
Get an object with proper type checking.
Definition TDirectory.h:213
virtual void * GetObjectChecked(const char *namecycle, const char *classname)
See documentation of TDirectory::GetObjectCheck(const char *namecycle, const TClass *cl)
TList * fList
List of objects in memory.
Definition TDirectory.h:142
virtual TKey * FindKeyAny(const char *) const
Definition TDirectory.h:199
virtual TObject * FindObjectAny(const char *name) const
Find object by name in the list of memory objects of the current directory or its sub-directories.
Streamer around an arbitrary STL like container, which implements basic container functionality.
A class to pass information from the TFileMerger to the objects being merged.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Seek to a specific position in the file. Pos it either kBeg, kCur or kEnd.
Definition TFile.cxx:2341
@ kStartBigFile
Definition TFile.h:278
Int_t GetVersion() const
Definition TFile.h:335
Bool_t IsBinary() const
Definition TFile.h:349
virtual Int_t DirReadKeys(TDirectory *)
Definition TFile.h:242
TList * GetListOfFree() const
Definition TFile.h:327
Int_t GetBestBuffer() const
Return the best buffer size of objects on this file.
Definition TFile.cxx:1208
virtual TKey * CreateKey(TDirectory *mother, const TObject *obj, const char *name, Int_t bufsize)
Creates key for object and converts data to buffer.
Definition TFile.cxx:1089
virtual Long64_t GetSize() const
Returns the current file size.
Definition TFile.cxx:1372
virtual Long64_t GetEND() const
Definition TFile.h:321
void SumBuffer(Int_t bufsize)
Increment statistics for buffer sizes of objects in this file.
Definition TFile.cxx:2484
static TFile *& CurrentFile()
Return the current ROOT file if any.
Definition TFile.cxx:1109
virtual const TUrl * GetEndpointUrl() const
Definition TFile.h:325
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:3804
@ kReproducible
Definition TFile.h:271
@ kWriteError
Definition TFile.h:268
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read a buffer from the file.
Definition TFile.cxx:1837
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
void Reset()
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
void Delete(Option_t *option="") override
Delete an object from the file.
Definition TKey.cxx:592
virtual Long64_t GetSeekKey() const
Definition TKey.h:91
Int_t Sizeof() const override
Return the size in bytes of the key header structure.
Definition TKey.cxx:1504
Int_t GetKeylen() const
Definition TKey.h:86
Int_t GetObjlen() const
Definition TKey.h:89
Int_t GetNbytes() const
Definition TKey.h:88
Short_t GetKeep() const
Returns the "KEEP" status.
Definition TKey.cxx:647
virtual const char * GetClassName() const
Definition TKey.h:77
virtual Bool_t ReadFile()
Read the key structure from the file.
Definition TKey.cxx:1436
void ReadKeyBuffer(char *&buffer)
Decode input buffer.
Definition TKey.cxx:1235
virtual Long64_t GetSeekPdir() const
Definition TKey.h:92
void SetMotherDir(TDirectory *dir)
Definition TKey.h:115
virtual void ls(Bool_t current) const
List Key contents.
Definition TKey.cxx:748
Short_t GetCycle() const
Return cycle number associated to this key.
Definition TKey.cxx:631
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition TKey.cxx:812
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=nullptr)
Write the encoded object supported by this key.
Definition TKey.cxx:1622
virtual char * GetBuffer() const
Definition TKey.h:80
void FillBuffer(char *&buffer) override
Encode key header into output buffer.
Definition TKey.cxx:655
A doubly linked list.
Definition TList.h:38
TObject * Before(const TObject *obj) const override
Returns the object before object obj.
Definition TList.cxx:501
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:708
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:952
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:789
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
Definition TList.cxx:193
virtual TObjLink * FirstLink() const
Definition TList.h:107
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:600
This class implements a shared memory region mapped to a file.
Definition TMapFile.h:26
static TClass * Class()
void Add(const TObject *obj, const char *name="")
Add an object to the list of objects to be stored in shared memory.
Definition TMapFile.cxx:610
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
TString fTitle
Definition TNamed.h:33
TString fName
Definition TNamed.h:32
TClass * IsA() const override
Definition TNamed.h:60
Mother of all ROOT objects.
Definition TObject.h:42
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
Definition TObject.cxx:578
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:461
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
@ kOnlyPrepStep
Used to request that the class specific implementation of TObject::Write just prepare the objects to ...
Definition TObject.h:115
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:995
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:226
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:424
static TClass * Class()
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition TObject.cxx:987
virtual void Delete(Option_t *option="")
Delete this object.
Definition TObject.cxx:267
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:886
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:548
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1096
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1124
virtual TClass * IsA() const
Definition TObject.h:248
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
Definition TObject.cxx:597
void ResetBit(UInt_t f)
Definition TObject.h:203
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
@ kIsReferenced
if object is referenced by a TRef or TRefArray
Definition TObject.h:74
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1070
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition TROOT.cxx:3060
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:3068
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition TROOT.cxx:2917
Regular expression class.
Definition TRegexp.h:31
Describe one element (data member) to be Streamed.
Int_t GetOffset() const
virtual Int_t GetExecID() const
Returns the TExec id for the EXEC instruction in the comment field of a TRef data member.
Describes a persistent version of a class.
TObjArray * GetElements() const override
Basic string class.
Definition TString.h:137
Ssiz_t Length() const
Definition TString.h:426
void ToLower()
Change string to lower-case.
Definition TString.cxx:1190
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition TString.cxx:1171
const char * Data() const
Definition TString.h:385
@ kBoth
Definition TString.h:283
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:633
Bool_t IsNull() const
Definition TString.h:423
virtual void Streamer(TBuffer &)
Stream a string object.
Definition TString.cxx:1493
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2438
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:642
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:661
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1319
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
Definition TUUID.h:42
virtual void Streamer(TBuffer &)
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
Definition TUUID.cxx:602
Int_t Sizeof() const
Definition TUUID.h:90
void FillBuffer(char *&buffer)
Stream UUID into output buffer.
Definition TUUID.cxx:306
void StreamerV1(TBuffer &b)
Stream UUID from input buffer.
Definition TUUID.cxx:340
Abstract Interface class describing Streamer information for one class.
virtual TClass * GetClass() const =0
const Int_t n
Definition legend1.C:16
void(* DirAutoAdd_t)(void *, TDirectory *)
Definition Rtypes.h:119
TCanvas * slash()
Definition slash.C:1