23#include "iThembaDataVersion.h"
57 std::cout << R
"(Failed to open ")" << GetFilename() << "/" <<
Filename() << R
"("!)" << std::endl;
63 }
catch(std::exception& e) {
64 std::cout <<
"Caught " << e.what() << std::endl;
81 std::cout <<
"Successfully opened file with " <<
FileSize() <<
" bytes!" << std::endl;
113 std::cout <<
"Failed to read next 64k buffer, currently at " <<
BytesRead() <<
"/" <<
FileSize() << std::endl;
118 if(strncmp(
BufferData(),
"EBYEDATA", 8) != 0) {
119 std::cerr <<
BytesRead() <<
": Failed to find 'EBYEDATA' (or 0x45 42 59 45 44 41 54 41) at beginning of header (0x" << std::hex << std::setfill('0') << std::setw(8) << *reinterpret_cast<uint64_t*>(
BufferData()) << std::hex << std::setfill(
' ') <<
")" << std::endl;
123 std::static_pointer_cast<TTdrEvent>(tdrEvent)->SetHeader(
BufferData());
124 }
catch(std::exception& e) {
125 std::cout << e.what() << std::endl;
127 uint32_t dataSize = std::static_pointer_cast<TTdrEvent>(tdrEvent)->GetHeader().fDataLength;
128 if(24 + dataSize < 0x10000) {
130 std::static_pointer_cast<TTdrEvent>(tdrEvent)->SetData(std::vector<char>(
ReadBuffer().begin() + 24,
ReadBuffer().begin() + 24 + dataSize));
131 }
catch(std::exception& e) {
132 std::cout << e.what() << std::endl;
146 std::cerr << __PRETTY_FUNCTION__ <<
": input file is not open!" << std::endl;
150 fInputFile.seekg(nofEvents * 0x10000, std::ifstream::cur);
152 std::cout <<
"Failed to skip next " << nofEvents <<
" 64k buffer(s), currently at " <<
BytesRead() <<
"/" <<
FileSize() << std::endl;
164 std::size_t foundslash =
Filename().rfind(
'/');
165 std::size_t found =
Filename().rfind(
'R');
166 if(found < foundslash || found == std::string::npos) {
167 std::cout <<
"Warning, failed to find 'R' in filename '" <<
Filename() <<
"'!" << std::endl;
170 std::size_t found2 =
Filename().rfind(
'-');
171 if((found2 < foundslash && foundslash != std::string::npos) || found2 == std::string::npos) {
175 if(found2 < foundslash && foundslash != std::string::npos) {
176 found2 = std::string::npos;
179 if(found2 == std::string::npos) {
181 temp =
Filename().substr(found + 1);
184 temp =
Filename().substr(found + 1, found2 - (found + 1));
186 return atoi(temp.c_str());
196 std::size_t foundslash =
Filename().rfind(
'/');
197 std::size_t found =
Filename().rfind(
'-');
198 if((found < foundslash && foundslash != std::string::npos) || found == std::string::npos) {
201 if(found < foundslash && foundslash != std::string::npos) {
202 found = std::string::npos;
204 if(found != std::string::npos) {
205 std::string temp =
Filename().substr(found + 1);
206 return atoi(temp.c_str());
static void SetMnemonicClass(const TClassRef &cls)
std::vector< char > & ReadBuffer()
virtual const char * GetFilename() const
Get the name of this file.
virtual size_t FileSize()
virtual std::string Filename() const
Get the name of this file.
virtual size_t BytesRead()
void ResizeBuffer(size_t newSize)
static void ClearVersion()
static void SetRunInfo(int runnum=0, int subrunnum=-1)
static void SetVersion(const char *ver)
static void SetDetectorInformation(TDetectorInformation *inf)
Reader for MIDAS .mid files.
int Read(std::shared_ptr< TRawEvent > lstEvent) override
Read one event from the file.
void Close() override
Close input file.
std::string Status(bool long_file_description=true) override
bool Open(const char *filename) override
Open input file.
int GetRunNumber() override
int GetSubRunNumber() override
void Skip(size_t nofEvents) override
Skip nofEvents from the file.
~TTdrFile() override
destructor
TTdrFile()=default
default constructor