#include <PerFile.h>
Public Member Functions | |
| PerFile (string fullfilepathname, Per::EAccessMode accessmode) | |
| virtual | ~PerFile () |
| string | GetFullFilePathName () const |
| UInt_t | GetNumClient () const |
| Per::EAccessMode | GetAccessMode () const |
| TFile * | GetTFile () const |
| Per::EErrorCode | GetErrorCode () const |
| bool | HasFileEndKey () const |
| bool | IsRemote () const |
| bool | IsOpen () const |
| std::ostream & | Print (std::ostream &s) const |
| bool | AddNewClient (Per::EAccessMode accessmode) |
| UInt_t | Close (bool kForce=false) |
| void | ChangeFile (std::string fullfilepathname, TFile *fileptr) |
Private Attributes | |
| string | fFullFilePathName |
| Per::EAccessMode | fAccessMode |
| TFile * | fTFile |
| UInt_t | fNumClient |
| bool | fRemote |
| Per::EErrorCode | fErrorCode |
|
||||||||||||
|
Definition at line 148 of file PerFile.cxx. References Per::AsString(), fErrorCode, fNumClient, fRemote, fTFile, GetErrorCode(), gSystem(), HasFileEndKey(), and MSG. 00148 : 00149 fFullFilePathName(fullfilepathname),fAccessMode(accessmode),fTFile(0), 00150 fNumClient(0),fRemote(false),fErrorCode(Per::kErrSuccess) { 00151 // 00152 // Purpose: PerFile constructor. Opens ROOT TFile with requested 00153 // filename and accessmode. Uses the static TFile::Open 00154 // method to open both local and remote files transparently. 00155 // User should use PerFile::IsOpen() to check to see if 00156 // file was opened successfully. 00157 // 00158 // Arguments: 00159 // fullfilepathname: full file path name to be opened. If file is 00160 // remote, must follow protocol as defined in 00161 // the TFile::Open method. Specifically for remote 00162 // files served by the rootd server daemon, the 00163 // file name is prefaced by "root:" or "roots:" 00164 // and the node name as in: 00165 // "root://urheim.hep.umn.edu/~minos/filename.dat" 00166 // See the TNetFile class description or 00167 // http://root.cern.ch/root/NetFile.html for more 00168 // information on the remote file name format. 00169 // accessmode: enumerated access mode of type EAccessMode (defined in 00170 // Per.h) in which file is to be opened: 00171 // kRead = open file in read only mode. 00172 // kNew = open new file in read/write. If file exists 00173 // previously, do not overwrite. 00174 // kRecreate = same as kNew, but if file exists previously 00175 // overwrite. 00176 // kUpdate = open existing file in read/write mode. 00177 // 00178 // Return: n/a. 00179 // 00180 // Notes: Authorization for remote access follows the protocol 00181 // discussed in http://root.cern.ch/root/NetFile.html with 00182 // useage dependent on how the rootd server was configured on 00183 // the remote site. 00184 // One approach, when not using secure authentication, is 00185 // to store the username&password required for remote access in 00186 // a .netrc file located in the user's home directory. The format 00187 // for a line in the .netrc file is: 00188 // machine <machine name> login <username> password <password> 00189 // e.g. 00190 // machine urheim.hep.umn.edu login myusername password mypassword 00191 // 00192 // If the constructor fails to open the file successfully, 00193 // PerFile::GetErrorCode can be used to determine the reason 00194 // for the failure. 00195 // 00196 // Contact: S. Kasahara 00197 // 00198 00199 gSystem -> ResetErrno(); 00200 00201 // Open File assuming default compression mode. May want to specify 00202 // eventually both the compression mode and a job related title. 00203 // Determine if file is remote 00204 if ( fullfilepathname.find("root:") == 0 00205 || fullfilepathname.find("roots:") == 0 ) { 00206 fRemote = true; 00207 // Assumes that user has correctly set up authorization according to 00208 // instructions in http://root.cern.ch/root/NetFile.html 00209 // Use of TNetFile is enforced instead of relying on TFile::Open, because 00210 // TFile::Open defaults to TFile even if the user has specified "root:" 00211 // if it determines that access is local and parses the file string to 00212 // determine the local file path. This does not result in 00213 // a correct file path if rootd has been set up for anonymous useage. 00214 // Update: 9/25/2005, SK/GMI The TEnv configuration variable 00215 // "TFile.ForceRemote" is now set true in the PerFileManager, so 00216 // that TFile::Open can be used in all cases. The old line: 00217 // fTFile =new TNetFile(fullfilepathname.c_str(),Per::AsString(accessmode), 00218 // "Persistency file"); 00219 // has been replaced by: 00220 fTFile = TFile::Open(fullfilepathname.c_str(),Per::AsString(accessmode), 00221 "Persistency file"); 00222 } 00223 else { 00224 fTFile = TFile::Open(fullfilepathname.c_str(),Per::AsString(accessmode), 00225 "Persistency file"); 00226 } 00227 00228 00229 if (fTFile == (TFile*)0 || fTFile -> IsZombie() || !fTFile ->IsOpen()) { 00230 // File did not open successfully 00231 MSG("Per", Msg::kInfo) << "Unable to open " << fullfilepathname 00232 << " with accessmode " << Per::AsString(accessmode) << endl; 00233 fErrorCode = Per::kErrFileError; 00234 if ( fTFile && fRemote ) { 00235 TNetFile* netfile = dynamic_cast<TNetFile*>(fTFile); 00236 if (netfile) { 00237 switch ( netfile -> GetErrorCode() ) { 00238 case kErrFileExists: 00239 fErrorCode = Per::kErrFileExists; break; 00240 case kErrNoFile: 00241 fErrorCode = Per::kErrFileNotFound; break; 00242 case kErrNoSpace: 00243 fErrorCode = Per::kErrFileNoSpace; break; 00244 default: 00245 break; 00246 } 00247 } 00248 } 00249 else if (fTFile) { 00250 // Local file, determine why file failed to open through system calls 00251 if (accessmode == Per::kNew && 00252 !(gSystem -> AccessPathName(fullfilepathname.c_str(),kFileExists))) { 00253 // New file failed to open due to existing file of same name 00254 fErrorCode = Per::kErrFileExists; 00255 } 00256 else if (accessmode == Per::kRead && 00257 (gSystem -> AccessPathName(fullfilepathname.c_str(),kFileExists))) { 00258 // File failed to open because it does not exist 00259 fErrorCode = Per::kErrFileNotFound; 00260 } 00261 else { 00262 switch (fTFile -> GetErrno()) { 00263 // TFile::TFile runs its own error checking so all file open errors 00264 // won't appear in errno 00265 case ENOSPC: 00266 fErrorCode = Per::kErrFileNoSpace; break; 00267 default: 00268 break; 00269 } 00270 } 00271 } 00272 if(fTFile) delete fTFile; fTFile = 0; 00273 } 00274 else { 00275 fNumClient++; 00276 // fRemote is used to describe rootd served files only 00277 // rootd files that are not closed will not UseCache because 00278 // of dispatcher service concerns 00279 if ( !fRemote || HasFileEndKey() ) fTFile->UseCache(); 00280 } 00281 00282 }
|
|
|
Definition at line 284 of file PerFile.cxx. References Close(), fNumClient, fTFile, and IsOpen(). 00284 {
00285 //
00286 // Purpose: PerFile destructor. Closes ROOT TFile and retrieves
00287 // allocated memory.
00288 //
00289 // Contact: S. Kasahara
00290 //
00291
00292 if (IsOpen()) {
00293 fTFile -> Close();
00294 delete fTFile; fTFile = 0;
00295 }
00296 fNumClient = 0;
00297
00298 }
|
|
|
Definition at line 44 of file PerFile.cxx. 00044 {
00045 //
00046 // Purpose: Add new client to the previously opened file if new requested
00047 // accessmode is compatible with the accessmode in which the file
00048 // was originally opened. If successful fNumClient is incremented.
00049 //
00050 // Arguments:
00051 // accessmode: enumerated file access mode of type EAccessMode (defined
00052 // in Per.h).
00053 //
00054 // Return: true means client was successfully added to file.
00055 // false means new accessmode was incompatible with original
00056 // accessmode.
00057 //
00058 // Contact: S. Kasahara
00059 //
00060 // Notes: access modes kNew & kRecreate are considered compatible,
00061 // all other mode combinations are considered incompatible.
00062
00063 bool accessok = false;
00064
00065 if(fAccessMode == accessmode) {
00066 accessok = true;
00067 }
00068 else {
00069 if((fAccessMode == Per::kNew || fAccessMode == Per::kRecreate) &&
00070 (accessmode == Per::kNew || accessmode == Per::kRecreate)) {
00071 accessok = true;
00072 }
00073 }
00074
00075 if(accessok) fNumClient++;
00076 return accessok;
00077 }
|
|
||||||||||||
|
Definition at line 48 of file PerFile.h. 00049 { fFullFilePathName = fullfilepathname; fTFile = fileptr; }
|
|
|
Definition at line 79 of file PerFile.cxx. References fNumClient, fTFile, and IsOpen(). Referenced by ~PerFile(). 00079 {
00080 //
00081 // Purpose: Decrement the number of clients to open file, and close
00082 // file if number of clients reaches zero. Argument kForce set
00083 // true forces closure of file regardless of number of clients
00084 // (default is kForce==false).
00085 //
00086 // Arguments:
00087 // kForce: bool to force file closure regardless of number of clients.
00088 // (by default kForce is set false).
00089 //
00090 // Return: number of clients of file remaining after method completes.
00091 //
00092 // Contact: S. Kasahara
00093 //
00094
00095 if (!kForce) {
00096 if(fNumClient > 0) fNumClient--; // decrement number of clients by one
00097 }
00098 else {
00099 fNumClient=0; // user requested forced file closure.
00100 }
00101
00102 if( !fNumClient ) {
00103 // No clients left, close file
00104 if (IsOpen()) {
00105 if (fTFile -> IsWritable()) {
00106 // Write out Key with name "FileEnd" as final object to file.
00107 // This marker is used by a reader of an open file to determine
00108 // when a file has actually been closed by the writer.
00109 TDirectory *savedir = gDirectory;
00110 fTFile -> cd(); // change to file directory
00111 TNamed *isend = new TNamed("FileEnd","PerFile End Key");
00112 isend -> Write(NULL,TObject::kOverwrite);
00113 delete isend;
00114 savedir -> cd(); // change back to users directory
00115 }
00116 fTFile -> Close();
00117 delete fTFile;
00118 fTFile = 0;
00119 }
00120 }
00121
00122 return fNumClient;
00123 }
|
|
|
Definition at line 35 of file PerFile.h. 00035 {return fAccessMode;}
|
|
|
Definition at line 37 of file PerFile.h. Referenced by PerFile(). 00037 {return fErrorCode;}
|
|
|
Definition at line 33 of file PerFile.h. 00033 {return fFullFilePathName;}
|
|
|
Definition at line 34 of file PerFile.h. 00034 {return fNumClient;}
|
|
|
Definition at line 36 of file PerFile.h. 00036 {return fTFile;}
|
|
|
Definition at line 125 of file PerFile.cxx. References fTFile, and IsOpen(). Referenced by PerFile(). 00125 {
00126 //
00127 // Purpose: Determine if file has been closed by the writer. This
00128 // is determined by the presence or absence of a "FileEnd"
00129 // Key.
00130 //
00131 // Arguments: none.
00132 //
00133 // Return: true if "FileEnd" Key is present, else false.
00134 //
00135 // Contact: S. Kasahara
00136 //
00137 // Notes: This method is used by a reader of an open file to determine
00138 // when that file has actually been closed by the writer.
00139 //
00140
00141 if ( IsOpen() && (fTFile -> Get("FileEnd")) )
00142 return true;
00143 else
00144 return false;
00145
00146 }
|
|
|
Definition at line 40 of file PerFile.h. Referenced by Close(), HasFileEndKey(), Print(), and ~PerFile(). 00040 {return (fTFile != (TFile*)0) ? true : false;}
|
|
|
Definition at line 39 of file PerFile.h. Referenced by Print(). 00039 {return fRemote;}
|
|
|
Definition at line 300 of file PerFile.cxx. References Per::AsString(), fAccessMode, fNumClient, IsOpen(), and IsRemote(). Referenced by operator<<(). 00300 {
00301 //
00302 // Purpose: Print status of file on ostream.
00303 //
00304 // Arguments: ms ostream to display on.
00305 //
00306 // Return: ostream reference.
00307 //
00308 // Contact: S. Kasahara
00309 //
00310
00311
00312 ms << (IsRemote() ? "Remote" : "Local") << " File " << fFullFilePathName;
00313
00314 if (IsOpen()) {
00315 ms << " is open with accessmode " << Per::AsString(fAccessMode)
00316 << " and " << fNumClient << " client(s)."<< endl;
00317 }
00318 else {
00319 ms << " was not opened successfully with accessmode "
00320 << Per::AsString(fAccessMode) << "."<<endl;
00321 }
00322
00323 return ms;
00324
00325 }
|
|
|
Definition at line 55 of file PerFile.h. Referenced by Print(). |
|
|
Definition at line 59 of file PerFile.h. Referenced by PerFile(). |
|
|
|
|
|
Definition at line 57 of file PerFile.h. Referenced by Close(), PerFile(), Print(), and ~PerFile(). |
|
|
Definition at line 58 of file PerFile.h. Referenced by PerFile(). |
|
|
Definition at line 56 of file PerFile.h. Referenced by Close(), HasFileEndKey(), PerFile(), and ~PerFile(). |
1.3.9.1