#include <DbiBinaryFile.h>
Public Member Functions | |
| DbiBinaryFile (const char *fileName="", Bool_t input=kTRUE) | |
| ~DbiBinaryFile () | |
| string | GetFileName () const |
| Bool_t | IsOK () const |
| Bool_t | IsReading () const |
| Bool_t | IsWriting () const |
| void | Close () |
| DbiBinaryFile & | operator>> (Bool_t &num) |
| DbiBinaryFile & | operator<< (const Bool_t &num) |
| DbiBinaryFile & | operator>> (Int_t &num) |
| DbiBinaryFile & | operator<< (const Int_t &num) |
| DbiBinaryFile & | operator>> (UInt_t &num) |
| DbiBinaryFile & | operator<< (const UInt_t &num) |
| DbiBinaryFile & | operator>> (Double_t &num) |
| DbiBinaryFile & | operator<< (const Double_t &num) |
| DbiBinaryFile & | operator>> (VldTimeStamp &ts) |
| DbiBinaryFile & | operator<< (const VldTimeStamp &ts) |
| DbiBinaryFile & | operator>> (string &str) |
| DbiBinaryFile & | operator<< (const string &str) |
| DbiBinaryFile & | operator>> (VldRange &vr) |
| DbiBinaryFile & | operator<< (const VldRange &vr) |
| DbiBinaryFile & | operator>> (vector< DbiTableRow * > &arr) |
| DbiBinaryFile & | operator<< (vector< DbiTableRow * > &arr) |
| char * | ReleaseArrayBuffer () |
Static Public Member Functions | |
| Bool_t | CanReadL2Cache () |
| Bool_t | CanWriteL2Cache () |
| void | SetWorkDir (const string &dir) |
| void | SetReadAccess (Bool_t access=kTRUE) |
| void | SetWriteAccess (Bool_t access=kTRUE) |
Private Member Functions | |
| Bool_t | CanRead () |
| Bool_t | CanWrite () |
| void | CheckFileStatus () |
| Bool_t | Read (char *bytes, UInt_t numBytes) |
| Bool_t | Write (const char *bytes, UInt_t numBytes) |
Private Attributes | |
| fstream * | fFile |
| Associated file, may be null. | |
| Bool_t | fReading |
| Bool_t | fHasErrors |
| char * | fArrayBuffer |
| string | fFileName |
Static Private Attributes | |
| string | fgWorkDir |
| Bool_t | fgReadAccess = kTRUE |
| Bool_t | fgWriteAccess = kTRUE |
DatabaseInterface
Contact: n.west1@physics.ox.ac.uk
Definition at line 45 of file DbiBinaryFile.h.
|
||||||||||||
|
Definition at line 54 of file DbiBinaryFile.cxx. References fFile, fFileName, fgReadAccess, fgWorkDir, fHasErrors, and MSG. 00054 : 00055 fFile(0), 00056 fReading(input), 00057 fHasErrors(kFALSE), 00058 fArrayBuffer(0) 00059 { 00060 // 00061 // 00062 // Purpose: Default Constructor. 00063 // 00064 // Arguments: 00065 // fileName in File name (default: "" => file is a dummy) 00066 // input in true if reading (default = kTRUE) 00067 00068 // Specification:- 00069 // ============= 00070 // 00071 // If file name or fgWorkDir is dummy, or the appropriate access is not set 00072 // then name is set to dummy otherwise fgWorkDir is prepended to the name. 00073 00074 // Complete the file name. 00075 fFileName = fileName; 00076 if ( fFileName != "" ) { 00077 Bool_t access = input ? fgReadAccess : fgWriteAccess; 00078 if ( fgWorkDir == "" || ! access ) fFileName = ""; 00079 else fFileName = fgWorkDir + fFileName; 00080 } 00081 00082 // Open the file. 00083 ios_base::openmode mode = ios_base::in|ios_base::binary; 00084 if ( ! input ) mode = ios_base::out|ios_base::binary; 00085 00086 if ( fFileName == "" ) fHasErrors = kTRUE; 00087 else { 00088 fFile = new fstream(fFileName.c_str(),mode); 00089 if ( ! fFile->is_open() || ! fFile->good() ) { 00090 MSG("Dbi",Msg::kDebug) << "Cannot open " << fFileName 00091 << "; all I/O will fail." << endl; 00092 fHasErrors = kTRUE; 00093 } 00094 } 00095 00096 } //.....................................................................
|
|
|
Definition at line 99 of file DbiBinaryFile.cxx. References Close(), fArrayBuffer, and fFile. 00100 {
00101 //
00102 //
00103 // Purpose: Default Destructor.
00104
00105 delete[] fArrayBuffer;
00106 fArrayBuffer = 0;
00107 this->Close();
00108 delete fFile;
00109 fFile = 0;
00110
00111 }
|
|
|
Definition at line 402 of file DbiBinaryFile.cxx. References IsOK(), and MAXMSG. Referenced by operator>>(), and Read(). 00402 {
00403
00404 if ( ! fReading ) {
00405 MAXMSG("Dbi",Msg::kError,20) << "Attempting to read from a write-only file" << endl;
00406 return kFALSE;
00407 }
00408 return this->IsOK();
00409
00410 }
|
|
|
Definition at line 104 of file DbiBinaryFile.h. Referenced by DbiTableProxy::CanReadL2Cache(). 00104 { return fgWorkDir.size() && fgReadAccess; }
|
|
|
Definition at line 413 of file DbiBinaryFile.cxx. References IsOK(), and MAXMSG. Referenced by operator<<(), and Write(). 00413 {
00414
00415 if ( fReading ) {
00416 MAXMSG("Dbi",Msg::kError,20) << "Attempting to write to a read-only file" << endl;
00417 return kFALSE;
00418 }
00419 return this->IsOK();
00420
00421 }
|
|
|
Definition at line 105 of file DbiBinaryFile.h. Referenced by DbiTableProxy::CanWriteL2Cache(). 00105 { return fgWorkDir.size() && fgWriteAccess; }
|
|
|
Definition at line 425 of file DbiBinaryFile.cxx. References Close(), fFile, fFileName, fHasErrors, gSystem(), and MAXMSG. Referenced by operator>>(), Read(), and Write(). 00425 {
00426
00427 // If file was good but has just gone bad, report and close it.
00428 // Delete it if writing.
00429
00430 if ( fFile
00431 && ! fHasErrors
00432 && ( ! fFile->is_open() || ! fFile->good() ) ) {
00433 MAXMSG("Dbi",Msg::kError,20) << "File not open or has gone bad,"
00434 << " all further I/O will fail." << endl;
00435 fHasErrors = kTRUE;
00436 this->Close();
00437
00438 //Delete file if writing.
00439 if ( ! fReading ) {
00440 MAXMSG("Dbi",Msg::kError,20) << "Erasing " << fFileName << endl;
00441 gSystem->Unlink(fFileName.c_str());
00442 }
00443
00444 }
00445
00446 }
|
|
|
Definition at line 114 of file DbiBinaryFile.cxx. References fFile. Referenced by CheckFileStatus(), operator>>(), and ~DbiBinaryFile(). 00115 {
00116 //
00117 //
00118 // Purpose: Close file.
00119
00120 if ( fFile ) fFile->close();
00121 }
|
|
|
Definition at line 56 of file DbiBinaryFile.h. 00056 { return fFileName; }
|
|
|
Definition at line 57 of file DbiBinaryFile.h. Referenced by CanRead(), and CanWrite(). 00057 { return ! fHasErrors;}
|
|
|
Definition at line 58 of file DbiBinaryFile.h. References RunStatus::IsOK(). Referenced by DbiValidityRec::Streamer(), DbiResultNonAgg::Streamer(), and DbiResult::Streamer(). 00058 { return this->IsOK() && fReading; }
|
|
|
Definition at line 59 of file DbiBinaryFile.h. References RunStatus::IsOK(). Referenced by DbiValidityRec::Streamer(), DbiResultNonAgg::Streamer(), and DbiResult::Streamer(). 00059 { return this->IsOK() && ! fReading; }
|
|
|
Definition at line 349 of file DbiBinaryFile.cxx. 00349 {
00350 //
00351 //
00352 // Purpose: Write a vector of objects inheriting from DbiTableRow.
00353
00354 // Format of record:-
00355 //
00356 // Int_t StartMarker Start of record marker = 0xaabbccdd
00357 // Int_t arrSize Size of vector
00358 //
00359 // If size of vector > 0 this is folowed by:-
00360 //
00361 // string objName Name of object
00362 // Int_t objSize Size of object
00363 // char* The data arrSize*objSize bytes long
00364 //
00365 // The record concludes:-
00366 //
00367 // Int_t EndMarker End of record marker = 0xddbbccaa
00368
00369
00370 if ( ! this->CanWrite() ) return *this;
00371
00372 UInt_t marker = StartMarker;
00373 (*this) << marker;
00374 Int_t arrSize = arr.size();
00375 (*this) << arrSize;
00376
00377 if ( arrSize ) {
00378 DbiTableRow* obj = arr[0];
00379 Int_t objSize = obj->IsA()->Size();
00380 string objName = obj->ClassName();
00381 (*this) << objName << objSize;
00382 for (int row = 0; row < arrSize; ++row ) {
00383 obj = arr[row];
00384 const char* p = reinterpret_cast<const char*>(arr[row]);
00385 this->Write(p,objSize);
00386 }
00387
00388 }
00389
00390 marker = EndMarker;
00391 (*this) << marker;
00392
00393 return *this;
00394
00395 }
|
|
|
Definition at line 224 of file DbiBinaryFile.cxx. References CanWrite(), VldRange::GetDataSource(), VldRange::GetDetectorMask(), VldRange::GetSimMask(), VldRange::GetTimeEnd(), and VldRange::GetTimeStart(). 00224 {
00225
00226 if ( this->CanWrite() ) {
00227 string str(vr.GetDataSource().Data());
00228 (*this) << vr.GetDetectorMask()
00229 << vr.GetSimMask()
00230 << vr.GetTimeStart()
00231 << vr.GetTimeEnd()
00232 << str;
00233 }
00234 return *this;
00235 }
|
|
|
Definition at line 194 of file DbiBinaryFile.cxx. References Write(). 00194 {
00195
00196 UInt_t numBytes = str.size()+1;
00197 this->Write(str.c_str(),numBytes);
00198 return *this;
00199 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 242 of file DbiBinaryFile.cxx. References CanRead(), CheckFileStatus(), Close(), fArrayBuffer, GetVTptr(), MAXMSG, MSG, Read(), and SetVTptr(). 00242 {
00243 //
00244 //
00245 // Purpose: Read a vector of objects inheriting from DbiTableRow.
00246
00247 // NB: On entry, array must be empty.
00248 //
00249 //
00250 // The objects are written into a buffer that is a contiguous
00251 // area of memory that is allocated to receive it. After a
00252 // successful read the user must call ReleaseArrayBuffer to take
00253 // control over this buffer as it will be automatically release
00254 // when the next array input occurs otherwise.
00255
00256 // For the format of record see the operator <<.
00257
00258 if ( ! this->CanRead() ) return *this;
00259
00260 if ( arr.size() ) {
00261 MAXMSG("Dbi",Msg::kError,20) << "Attempting to read into non-empty array" << endl;
00262 return *this;
00263 }
00264
00265 // Check for start of array marker.
00266
00267 UInt_t marker = 0;
00268 (*this) >> marker;
00269 if ( marker != StartMarker ) {
00270 MAXMSG("Dbi",Msg::kError,20) << "Cannot find start of array marker" << endl;
00271 this->Close();
00272 this->CheckFileStatus();
00273 return *this;
00274 }
00275
00276 // Get array size and deal with non-empty arrays.
00277
00278 Int_t arrSize = 0;
00279 (*this) >> arrSize;
00280
00281 if ( arrSize ) {
00282 Int_t objSize = 0;
00283 string objName;
00284 (*this) >> objName >> objSize;
00285
00286 // Ensure that sizes look sensible and use ROOT to instatiate
00287 // an example object so that we can get the address of the
00288 // virtual table.
00289
00290 TClass objClass(objName.c_str());
00291 Int_t objSizefromRoot = objClass.Size();
00292 void* obj = objClass.New();
00293 void* vt = GetVTptr(obj);
00294 // This only works if the address of the sub-class object is the same
00295 // as the underlying base class, which should be true in this simple case.
00296 DbiTableRow* tr = reinterpret_cast<DbiTableRow*>(obj);
00297 delete tr;
00298
00299 MSG("Dbi",Msg::kVerbose)
00300 << "Restoring array of " << arrSize << " "
00301 << objName << " objects"
00302 << " VTaddr " << hex << vt << dec
00303 << " object size " << objSize << "(from file) "
00304 << objSizefromRoot << "(from ROOT)"
00305 << endl;
00306
00307 if ( arrSize < 0 || objSize != objSizefromRoot ) {
00308 MAXMSG("Dbi",Msg::kError,20) << "Illegal array size ("<< arrSize
00309 << ") or object size(" << objSize
00310 << "," << objSizefromRoot << ")" << endl;
00311 this->Close();
00312 this->CheckFileStatus();
00313 return *this;
00314 }
00315
00316 // Allocate buffer and load in array.
00317 delete[] fArrayBuffer;
00318 Int_t buffSize = arrSize*objSize;
00319 fArrayBuffer = new char[buffSize];
00320 this->Read(fArrayBuffer,buffSize);
00321
00322 // Fix up VT pointers and populate the vector.
00323
00324 char* elem = fArrayBuffer;
00325 arr.reserve(arrSize);
00326 for (int row = 0; row < arrSize; ++row ) {
00327 SetVTptr(elem,vt);
00328 arr.push_back(reinterpret_cast<DbiTableRow*>(elem));
00329 elem += objSize;
00330 }
00331
00332 }
00333
00334 // Check for end of array marker.
00335
00336 (*this) >> marker;
00337 if ( marker != EndMarker ) {
00338 MAXMSG("Dbi",Msg::kError,20) << "Cannot find end of array marker" << endl;
00339 this->Close();
00340 this->CheckFileStatus();
00341 }
00342
00343 return *this;
00344
00345 }
|
|
|
Definition at line 203 of file DbiBinaryFile.cxx. References CanRead(). 00203 {
00204
00205 if ( this->CanRead() ) {
00206 Int_t detectorMask;
00207 Int_t simMask;
00208 VldTimeStamp timeStart;
00209 VldTimeStamp timeEnd;
00210 string str;
00211 (*this) >> detectorMask
00212 >> simMask
00213 >> timeStart
00214 >> timeEnd
00215 >> str;
00216 TString dataSource(str.c_str());
00217 VldRange tmp(detectorMask,simMask,timeStart,timeEnd,dataSource);
00218 vr = tmp;
00219 }
00220 return *this;
00221 }
|
|
|
Definition at line 184 of file DbiBinaryFile.cxx. 00184 {
00185
00186 if ( this->CanRead() ) {
00187 getline(*fFile,str,'\0');
00188 this->CheckFileStatus();
00189 }
00190 return *this;
00191 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||
|
Definition at line 450 of file DbiBinaryFile.cxx. References CanRead(), CheckFileStatus(), and fFile. Referenced by operator>>(). 00450 {
00451 //
00452 //
00453 // Purpose: Low-level I/O with error checking.
00454 //
00455
00456 if ( ! this->CanRead() ) return kFALSE;
00457
00458 fFile->read(bytes,numBytes);
00459 this->CheckFileStatus();
00460 return ! fHasErrors;
00461 }
|
|
|
Definition at line 98 of file DbiBinaryFile.h. Referenced by DbiResultNonAgg::Streamer(). 00098 { char* buff = fArrayBuffer;
00099 fArrayBuffer = 0;
00100 return buff; }
|
|
|
Definition at line 108 of file DbiBinaryFile.h. 00108 { fgReadAccess = access; }
|
|
|
Definition at line 106 of file DbiBinaryFile.h. Referenced by DbiTableProxyRegistry::Config().
|
|
|
Definition at line 109 of file DbiBinaryFile.h. 00109 { fgWriteAccess = access; }
|
|
||||||||||||
|
Definition at line 465 of file DbiBinaryFile.cxx. References CanWrite(), CheckFileStatus(), and fFile. Referenced by operator<<(). 00465 {
00466 //
00467 //
00468 // Purpose: Low-level I/O with error checking.
00469 //
00470
00471 if ( ! this->CanWrite() ) return kFALSE;
00472
00473 fFile->write(bytes,numBytes);
00474 this->CheckFileStatus();
00475 return ! fHasErrors;
00476 }
|
|
|
Definition at line 131 of file DbiBinaryFile.h. Referenced by operator>>(), and ~DbiBinaryFile(). |
|
|
Associated file, may be null.
Definition at line 126 of file DbiBinaryFile.h. Referenced by CheckFileStatus(), Close(), DbiBinaryFile(), Read(), Write(), and ~DbiBinaryFile(). |
|
|
Definition at line 132 of file DbiBinaryFile.h. Referenced by CheckFileStatus(), and DbiBinaryFile(). |
|
|
Definition at line 42 of file DbiBinaryFile.cxx. Referenced by DbiBinaryFile(). |
|
|
Definition at line 41 of file DbiBinaryFile.cxx. Referenced by DbiBinaryFile(). |
|
|
Definition at line 43 of file DbiBinaryFile.cxx. |
|
|
Definition at line 130 of file DbiBinaryFile.h. Referenced by CheckFileStatus(), and DbiBinaryFile(). |
|
|
Definition at line 129 of file DbiBinaryFile.h. |
1.3.9.1