// RootHistogramDataset.h #ifndef dset__RootHistogramDataset_H #define dset__RootHistogramDataset_H // David Adams // April 2004 // Update October 2004. // // Dataset consisting of a ROOT file with histograms. // Inherits from GenericDataset. // Content and location are explicit. #include #include #include "TFile.h" #include "dataset_file/FileManagementSystem.h" #include "dataset_base/GenericDataset.h" namespace dset { class RootHistogramDataset : public GenericDataset { private: // data // Staged file. // The SE file is in the location. mutable Url m_file; // ROOT file. mutable TFile* m_phfile; // Flag indicating that a readonly replica of the file // has been staged. // The name of that replica is in m_pfile. mutable bool m_stage_read; // Flag indicating that a writeable replica of the file // has been staged. // The name of that replica is in m_pfile. mutable bool m_stage_write; // File catalog for dataset created from physical file. FileManagementSystem* m_pfms; private: // functions // Hide assignment. RootHistogramDataset& operator=(const RootHistogramDataset& rhs); // Return the physical file. // If write is true, this is a writeable file and it will be put // in the FMS when the dataset is locked. Url internal_file(std::string dir, bool write) const; // Return a ROOT file constructed from the above physical file. TFile& internal_root_file(std::string dir, bool write) const; // Return the SE file. // Invalid if this file is not yet defined. Url internal_se_file() const; // Close the root file. // This deletes the TFile object (but not the physical file). void internal_close_root_file() const; // Release the staged replica. void internal_release_staged() const; public: // static functions // Cast. static const RootHistogramDataset* cast(const Dataset* pdst); public: // functions // Constructor from a URL. // If lock is true, it is assumed the file is in already in an SE // and can be staged for access with FMS get (for reading) or copy // (for writing). The dataset is locked as part of construction. // If lock is false, it is assumed the file specified by the URL is // accessible for reading by root. The dataset is left unlocked until // the lock method is called. At that time, the staged file is copied // to the SE. // If lock is false, the dataset owns the input file and may modify // it. Ownership is passed to the first clone or the file is deleted // upon destruction. The file is renamed to avoid conflicts when // writing back to the SE. // Content is one block with type "RootHistogramDataset" and label // content_label. RootHistogramDataset(Url file, std::string content_label, FileManagementSystem* pfms =0, DatasetId parent =DatasetId(), bool lock =true); // Constructor from a generic dataset. RootHistogramDataset(const GenericDataset& gdst); // Copy constructor. // Copy is invalid. RootHistogramDataset(const RootHistogramDataset& rhs); // Destructor. ~RootHistogramDataset(); // Return the SE file. Url se_file() const; // Return the staged file. // For an unlocked dataset, this file *may* have been modified. // Caller should *not* modify this file. Url staged_file() const; // Return the ROOT file (ROOT view of the staged file). // For an unlocked dataset, this file *may* have been modified. // Caller should *not* modify this TFile. TFile& root_file() const; public: // virtual functions // Clone. RootHistogramDataset* clone(std::string dir ="") const; // Lock // Must be unlocked. // File is put into the SE. int lock(); // Merge another dataset into this one. // Must be of the same type. // Returns nonzero for error. int merge(const Dataset& dst, std::string dir =""); }; } // end namespace dset #endif