Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

TMidasFile.cxx

Go to the documentation of this file.
00001 //  TMidasFile.cxx.
00010 #include <iostream>
00011 
00012 #include <Rtypes.h>
00013 
00014 #include "TMidasFile.h"
00015 #include "TMidasEvent.h"
00016 
00017 using std::cerr;
00018 using std::endl;
00019 using std::ios;
00020 
00021 TMidasFile::TMidasFile()
00022 {
00025 
00026   //
00027   // check for the endian, as we may need to byte swap the event header
00028   //
00029   Long_t endian = 0x12345678;
00030 
00031   fByteSwap = *(reinterpret_cast<char *> (&endian)) == 0x78 ? false : true;
00032 }
00033 
00034 TMidasFile::~TMidasFile()
00035 {
00038 }
00039 
00040 const Char_t * TMidasFile::GetFilename() const
00041 {
00045   return fFileName.c_str();
00046 }
00047 
00048 Bool_t TMidasFile::Open(const Char_t *fileName)
00049 {
00054   Bool_t status = true;
00055   fFileName = fileName;
00056   open(fFileName.c_str(), ios::binary);
00057   if (! is_open()) {
00058     cerr << "Open: ERROR - cannot open file \"" << fFileName
00059          << "\", exception = " << exceptions()  << endl;
00060     status = false;
00061   }
00062   return status;
00063 }
00064 
00065 Bool_t TMidasFile::Read(TMidasEvent *midasEvent)
00066 {
00071   Bool_t status = false;
00072 
00073   read(reinterpret_cast<Char_t *>(midasEvent->GetEventHeader()),
00074        sizeof(EventHeader_t));
00075   if (fByteSwap)
00076     midasEvent->SwapBytesEventHeader();
00077 
00078   if (! eof()) {
00079     //
00080     // check to make sure we're still OK
00081     //
00082     if (fail())
00083       cerr << "Read: Unexpected failure reading file \""
00084            << fFileName << "\"" << endl;
00085     else {
00086       //
00087       // check data-size
00088       //
00089       if (midasEvent->IsGoodSize()) {
00090         midasEvent->AllocateData();
00091         read(midasEvent->GetData(), midasEvent->GetDataSize());
00092         //
00093         // check we're still ok
00094         //
00095         if (good())
00096           status = true;
00097         else
00098           cerr << "Read: Unexpected error reading file \""
00099                << fFileName << "\"" << endl;
00100       } else {
00101         cerr << "Read: Invalid event size "      << midasEvent->GetDataSize()
00102              << " bytes in file \"" << fFileName << "\"" << endl;
00103       }
00104     }
00105   }
00106   return status;
00107 }
00108 
00109 void TMidasFile::Close()
00110 {
00113   if (is_open())
00114     close();
00115 }

Generated on Mon Jan 8 11:54:31 2007 for DragonRoot by  doxygen 1.3.9.1