A generic class to read a file containing an ASDM table as a stream. More...
#include <TableStreamReader.h>
Public Member Functions | |
TableStreamReader () | |
An empty constructor. | |
virtual | ~TableStreamReader () |
The destructor. | |
void | open (const std::string &directory) |
Opens a file expected to contain an ASDM table of type T with rows of type R. | |
void | reset () |
Repositions the read head to the beginning of the table. | |
const std::vector< R * > & | nextNRows (unsigned int nRows) |
Reads at most n rows in the file, creates as many memory representations of these rows and return the reference of a vector of pointers on these representations. | |
const std::vector< R * > & | untilNBytes (unsigned int nBytes) |
Reads as many rows as possible in the file, keeps their in memory representation until the number of read bytes is greater or equal a number of bytes, n, passed as a parameter to the method. | |
bool | hasRows () |
Returns true if the end of the file has not been reached. | |
void | close () |
Releases all the resources allocated to the instance which can be reused with another file. | |
Private Types | |
enum | State { S_CLOSED, S_OPENED } |
enum | Transition { T_OPEN, T_CHECK, T_RESET, T_READ, T_CLOSE } |
Private Member Functions | |
void | checkState (Transition t, const std::string &methodName) const |
void | clear () |
Empty the local storage containing the rows obtained during the last read operation. | |
void | skipUntilEmptyLine (int maxSkips) |
std::string | nextLine () |
pair< std::string, std::string > | headerField2Pair (const std::string &hf) |
std::string | requireMIMEHeader () |
pair< std::string, std::string > | requireHeaderField (const std::string &hf) |
void | requireBoundary (const std::string &boundary, int maxLines) |
std::string | accumulateUntilBoundary (const std::string &boundary, int maxLines) |
std::string | requireBoundaryInCT (const std::string &ctValue) |
string | unquote (const string &s, string &unquoted) |
Private Attributes | |
std::string | tablePath |
std::ifstream | tableFile |
std::string | currentLine |
std::string | boundary_1 |
off_t | fileSizeInBytes |
asdm::EndianIFStream | eifs |
std::vector< std::string > | attributesSeq |
asdm::ASDM | asdm |
std::vector< R * > | rows |
char * | readBuffer |
streampos | whereRowsStart |
State | currentState |
A generic class to read a file containing an ASDM table as a stream.
The purpose of this class is to provide the programmer with a way to read a file containing an ASDM table by successive slices. Each slice is transformed into the in memory representation of the rows which have been read. A slice can be specified in two ways :
Remarks
getXXXX
(e.g. getAntenna
of getPointing
) which load entirely the tables into memory. T | The parameter T must be the type of one of the tables which can be found in an ASDM (e.g. AntennaTable) | |
R | The parameter R must be the type of the rows which make the content of a table of type T (e.g. AntennaRow is T is AntennaTable). |
Definition at line 39 of file TableStreamReader.h.
enum asdm::TableStreamReader::State [private] |
Definition at line 250 of file TableStreamReader.h.
enum asdm::TableStreamReader::Transition [private] |
Definition at line 251 of file TableStreamReader.h.
asdm::TableStreamReader< T, R >::TableStreamReader | ( | ) | [inline] |
An empty constructor.
Definition at line 44 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::boundary_1, asdm::TableStreamReader< T, R >::currentState, asdm::TableStreamReader< T, R >::readBuffer, READBUFFERSIZE, and asdm::TableStreamReader< T, R >::S_CLOSED.
virtual asdm::TableStreamReader< T, R >::~TableStreamReader | ( | ) | [inline, virtual] |
The destructor.
Definition at line 49 of file TableStreamReader.h.
std::string asdm::TableStreamReader< T, R >::accumulateUntilBoundary | ( | const std::string & | boundary, | |
int | maxLines | |||
) | [inline, private] |
cout << "Entering accumulateUntilBoundary with maxLines = " << maxLines << endl;
Definition at line 375 of file TableStreamReader.h.
References casa::name(), asdm::TableStreamReader< T, R >::nextLine(), and casacore::trim().
Referenced by asdm::TableStreamReader< T, R >::open().
void asdm::TableStreamReader< T, R >::checkState | ( | Transition | t, | |
const std::string & | methodName | |||
) | const [inline, private] |
Definition at line 254 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::currentState, casa::name(), asdm::TableStreamReader< T, R >::S_CLOSED, asdm::TableStreamReader< T, R >::S_OPENED, asdm::TableStreamReader< T, R >::T_CHECK, asdm::TableStreamReader< T, R >::T_CLOSE, asdm::TableStreamReader< T, R >::T_OPEN, asdm::TableStreamReader< T, R >::T_READ, and asdm::TableStreamReader< T, R >::T_RESET.
Referenced by asdm::TableStreamReader< T, R >::close(), asdm::TableStreamReader< T, R >::hasRows(), asdm::TableStreamReader< T, R >::nextNRows(), asdm::TableStreamReader< T, R >::open(), asdm::TableStreamReader< T, R >::reset(), and asdm::TableStreamReader< T, R >::untilNBytes().
void asdm::TableStreamReader< T, R >::clear | ( | ) | [inline, private] |
Empty the local storage containing the rows obtained during the last read operation.
Definition at line 267 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::rows.
Referenced by asdm::TableStreamReader< T, R >::close(), asdm::TableStreamReader< T, R >::nextNRows(), asdm::TableStreamReader< T, R >::reset(), and asdm::TableStreamReader< T, R >::untilNBytes().
void asdm::TableStreamReader< T, R >::close | ( | ) | [inline] |
Releases all the resources allocated to the instance which can be reused with another file.
Update the state.
Definition at line 225 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::currentState, free(), asdm::TableStreamReader< T, R >::readBuffer, asdm::TableStreamReader< T, R >::S_CLOSED, asdm::TableStreamReader< T, R >::T_CLOSE, and asdm::TableStreamReader< T, R >::tableFile.
bool asdm::TableStreamReader< T, R >::hasRows | ( | ) | [inline] |
Returns true if the end of the file has not been reached.
Definition at line 217 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::fileSizeInBytes, asdm::TableStreamReader< T, R >::T_CHECK, and asdm::TableStreamReader< T, R >::tableFile.
Referenced by asdm::TableStreamReader< T, R >::nextNRows(), and asdm::TableStreamReader< T, R >::untilNBytes().
pair<std::string, std::string> asdm::TableStreamReader< T, R >::headerField2Pair | ( | const std::string & | hf | ) | [inline, private] |
Definition at line 303 of file TableStreamReader.h.
References casa::name(), casacore::trim(), and casacore::value().
Referenced by asdm::TableStreamReader< T, R >::requireHeaderField(), and asdm::TableStreamReader< T, R >::requireMIMEHeader().
std::string asdm::TableStreamReader< T, R >::nextLine | ( | ) | [inline, private] |
cout << "nextLine has read '" << currentLine << "'" << endl;
Definition at line 291 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::currentLine, casa::name(), asdm::TableStreamReader< T, R >::tableFile, and asdm::TableStreamReader< T, R >::tablePath.
Referenced by asdm::TableStreamReader< T, R >::accumulateUntilBoundary(), asdm::TableStreamReader< T, R >::requireBoundary(), asdm::TableStreamReader< T, R >::requireHeaderField(), asdm::TableStreamReader< T, R >::requireMIMEHeader(), and asdm::TableStreamReader< T, R >::skipUntilEmptyLine().
const std::vector<R*>& asdm::TableStreamReader< T, R >::nextNRows | ( | unsigned int | nRows | ) | [inline] |
Reads at most n rows in the file, creates as many memory representations of these rows and return the reference of a vector of pointers on these representations.
nRows | the maximum number of rows to read. |
Definition at line 180 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::asdm, asdm::TableStreamReader< T, R >::attributesSeq, asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::eifs, asdm::ASDM::getTable(), asdm::TableStreamReader< T, R >::hasRows(), casa::name(), asdm::TableStreamReader< T, R >::rows, and asdm::TableStreamReader< T, R >::T_READ.
void asdm::TableStreamReader< T, R >::open | ( | const std::string & | directory | ) | [inline] |
Opens a file expected to contain an ASDM table of type T with rows of type R.
directory | the path to the directory containing the file. |
Open the file.
Determine the size of the file.
And start parsing the content.
cout << "boundary_1 = " << boundary_1 << endl;
We have the xmlHeader , let's parse it.
Then it's an "old fashioned" MIME file for tables. Just try to deserialize it with Big_Endian for the bytes ordering.
It's a new (and correct) MIME file for tables.
1st ) Look for a BulkStoreRef element with an attribute byteOrder.
Skip the two first children (Entity and ContainerEntity).
We found BulkStoreRef, now look for its attribute byteOrder.
2nd) Look for the Attributes element and grab the names of the elements it contains.
Create an EndianIFStream from the substring containing the binary part.
We do nothing with that but we have to read it.
Let's read numRows but ignore it and rely on the value specified in the ASDM.xml file.
Memorize the starting point of rows.
Update the state
Definition at line 58 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::accumulateUntilBoundary(), asdm::TableStreamReader< T, R >::attributesSeq, asdm::ByteOrder::Big_Endian, asdm::TableStreamReader< T, R >::boundary_1, asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::currentState, asdm::TableStreamReader< T, R >::eifs, asdm::TableStreamReader< T, R >::fileSizeInBytes, asdm::Entity::fromBin(), asdm::ByteOrder::fromString(), casa::name(), asdm::TableStreamReader< T, R >::requireBoundary(), asdm::TableStreamReader< T, R >::requireMIMEHeader(), asdm::TableStreamReader< T, R >::S_OPENED, asdm::TableStreamReader< T, R >::skipUntilEmptyLine(), asdm::TableStreamReader< T, R >::T_OPEN, asdm::TableStreamReader< T, R >::tableFile, asdm::TableStreamReader< T, R >::tablePath, and asdm::TableStreamReader< T, R >::whereRowsStart.
void asdm::TableStreamReader< T, R >::requireBoundary | ( | const std::string & | boundary, | |
int | maxLines | |||
) | [inline, private] |
cout << "Entering require boundary with boundary == '" << boundary << "' and maxLines = " << maxLines << endl;
Definition at line 358 of file TableStreamReader.h.
References casa::name(), and asdm::TableStreamReader< T, R >::nextLine().
Referenced by asdm::TableStreamReader< T, R >::open().
std::string asdm::TableStreamReader< T, R >::requireBoundaryInCT | ( | const std::string & | ctValue | ) | [inline, private] |
Definition at line 395 of file TableStreamReader.h.
References casa::name(), casacore::split(), and asdm::TableStreamReader< T, R >::unquote().
Referenced by asdm::TableStreamReader< T, R >::requireMIMEHeader().
pair<std::string, std::string> asdm::TableStreamReader< T, R >::requireHeaderField | ( | const std::string & | hf | ) | [inline, private] |
Definition at line 347 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::currentLine, asdm::TableStreamReader< T, R >::headerField2Pair(), casa::name(), and asdm::TableStreamReader< T, R >::nextLine().
Referenced by asdm::TableStreamReader< T, R >::requireMIMEHeader().
std::string asdm::TableStreamReader< T, R >::requireMIMEHeader | ( | ) | [inline, private] |
MIME-Version
cout << name_value.first << "=" << name_value.second << endl; if (currentLine != "MIME-Version: 1.0") // a work around for the case when the very first character is not the expected "M" (happened with some corrupted data).
Content-Type
cout << "boundary_1 =" << boundary_1 << endl;
Content-Description name_value = requireHeaderField("CONTENT-DESCRIPTION");
Content-Location name_value = requireHeaderField("CONTENT-LOCATION");
Look for an empty line in the at most 10 subsequent lines.
Definition at line 322 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::boundary_1, asdm::TableStreamReader< T, R >::currentLine, asdm::TableStreamReader< T, R >::headerField2Pair(), casa::name(), asdm::TableStreamReader< T, R >::nextLine(), asdm::TableStreamReader< T, R >::requireBoundaryInCT(), asdm::TableStreamReader< T, R >::requireHeaderField(), casacore::C::second, asdm::TableStreamReader< T, R >::skipUntilEmptyLine(), and asdm::TableStreamReader< T, R >::tablePath.
Referenced by asdm::TableStreamReader< T, R >::open().
void asdm::TableStreamReader< T, R >::reset | ( | ) | [inline] |
Repositions the read head to the beginning of the table.
The internal storage containing the result of the last read operation is cleared.
Definition at line 168 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::T_RESET, asdm::TableStreamReader< T, R >::tableFile, and asdm::TableStreamReader< T, R >::whereRowsStart.
void asdm::TableStreamReader< T, R >::skipUntilEmptyLine | ( | int | maxSkips | ) | [inline, private] |
cout << "Entering skipUntilEmptyLine" << endl;
cout << "Exiting skipUntilEmptyLine" << endl;
Definition at line 273 of file TableStreamReader.h.
References casa::name(), asdm::TableStreamReader< T, R >::nextLine(), and casacore::trim().
Referenced by asdm::TableStreamReader< T, R >::open(), and asdm::TableStreamReader< T, R >::requireMIMEHeader().
string asdm::TableStreamReader< T, R >::unquote | ( | const string & | s, | |
string & | unquoted | |||
) | [inline, private] |
Definition at line 409 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::requireBoundaryInCT().
const std::vector<R*>& asdm::TableStreamReader< T, R >::untilNBytes | ( | unsigned int | nBytes | ) | [inline] |
Reads as many rows as possible in the file, keeps their in memory representation until the number of read bytes is greater or equal a number of bytes, n, passed as a parameter to the method.
n | the number of read bytes which is used as an upper limit to the read operation. |
Definition at line 200 of file TableStreamReader.h.
References asdm::TableStreamReader< T, R >::asdm, asdm::TableStreamReader< T, R >::attributesSeq, asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::eifs, asdm::ASDM::getTable(), asdm::TableStreamReader< T, R >::hasRows(), casa::name(), asdm::TableStreamReader< T, R >::rows, asdm::TableStreamReader< T, R >::T_READ, and asdm::TableStreamReader< T, R >::tableFile.
asdm::ASDM asdm::TableStreamReader< T, R >::asdm [private] |
Definition at line 243 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::nextNRows(), and asdm::TableStreamReader< T, R >::untilNBytes().
std::vector<std::string> asdm::TableStreamReader< T, R >::attributesSeq [private] |
Definition at line 242 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::nextNRows(), asdm::TableStreamReader< T, R >::open(), and asdm::TableStreamReader< T, R >::untilNBytes().
std::string asdm::TableStreamReader< T, R >::boundary_1 [private] |
Definition at line 238 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::open(), asdm::TableStreamReader< T, R >::requireMIMEHeader(), and asdm::TableStreamReader< T, R >::TableStreamReader().
std::string asdm::TableStreamReader< T, R >::currentLine [private] |
Definition at line 237 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::nextLine(), asdm::TableStreamReader< T, R >::requireHeaderField(), and asdm::TableStreamReader< T, R >::requireMIMEHeader().
State asdm::TableStreamReader< T, R >::currentState [private] |
Definition at line 252 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::close(), asdm::TableStreamReader< T, R >::open(), and asdm::TableStreamReader< T, R >::TableStreamReader().
asdm::EndianIFStream asdm::TableStreamReader< T, R >::eifs [private] |
Definition at line 241 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::nextNRows(), asdm::TableStreamReader< T, R >::open(), and asdm::TableStreamReader< T, R >::untilNBytes().
off_t asdm::TableStreamReader< T, R >::fileSizeInBytes [private] |
Definition at line 240 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::hasRows(), and asdm::TableStreamReader< T, R >::open().
char* asdm::TableStreamReader< T, R >::readBuffer [private] |
Definition at line 246 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::close(), and asdm::TableStreamReader< T, R >::TableStreamReader().
std::vector<R*> asdm::TableStreamReader< T, R >::rows [private] |
Definition at line 244 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::nextNRows(), and asdm::TableStreamReader< T, R >::untilNBytes().
std::ifstream asdm::TableStreamReader< T, R >::tableFile [private] |
Definition at line 236 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::close(), asdm::TableStreamReader< T, R >::hasRows(), asdm::TableStreamReader< T, R >::nextLine(), asdm::TableStreamReader< T, R >::open(), asdm::TableStreamReader< T, R >::reset(), and asdm::TableStreamReader< T, R >::untilNBytes().
std::string asdm::TableStreamReader< T, R >::tablePath [private] |
Definition at line 235 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::nextLine(), asdm::TableStreamReader< T, R >::open(), and asdm::TableStreamReader< T, R >::requireMIMEHeader().
streampos asdm::TableStreamReader< T, R >::whereRowsStart [private] |
Definition at line 248 of file TableStreamReader.h.
Referenced by asdm::TableStreamReader< T, R >::open(), and asdm::TableStreamReader< T, R >::reset().