16 #include <QtCore/QFileInfo>
47 : _filename(filename),
48 _file(filename.c_str(), ios::binary | ios::in),
53 _read = FileReader::instance(_filename);
54 _read->loadSettings();
55 Log::add(Log::INFO,
"FileProcessor(): processing file '" + _filename +
56 "' with file reader type '" + _read->type() +
"'");
57 _file.seekg (0, ios::end);
58 _filesize = _file.tellg();
59 _file.seekg (0, ios::beg);
60 _read->readHeaderInfo(_file);
67 InputBase::shared_pointer::element_type&
input(InputBase::reference());
70 vector<CASSEvent::id_t> ids;
73 while((!input.shouldQuit()) && (_file.tellg() < _filesize))
77 if (rbItem == input.ringbuffer().end())
81 bool isGood((*_read)(_file,*rbItem->element));
85 Log::add(Log::WARNING,
"FileProcessor::run(): Event with id '"+
86 toString(rbItem->element->id()) +
"' is bad: skipping Event");
92 if (find(ids.begin(), ids.end(), id) != ids.end())
94 string output(
"File '"+_filename+
"' has duplicate id '" +
96 if (_read->type() ==
"xtc")
98 uint32_t seconds(static_cast<uint32_t>((
id & 0xFFFFFFFF00000000) >> 32));
99 uint32_t fiducial(static_cast<uint32_t>((
id & 0x00000000FFFFFFFF) >> 8));
100 output += (
"(seconds '" +
toString(seconds) +
"', fiducial '" +
103 Log::add(Log::ERROR,output);
113 ids.push_back(rbItem->element->id());
117 rbItem->element->setFilename(_filename.c_str());
118 input.newEventAdded(rbItem->element->datagrambuffer().size());
119 input.ringbuffer().doneFilling(rbItem, isGood);
130 return ((_file.tellg() == -1) ? 1. :
131 (static_cast<double>(_file.tellg()) /
132 static_cast<double>(_filesize)));
169 void FileInput::instance(
string filelistname,
176 throw logic_error(
"FileInput::instance(): The instance of the base class is already initialized");
180 FileInput::FileInput(
string filelistname,
185 :
InputBase(ringbuffer,ratemeter,loadmeter,parent),
186 _quitWhenDone(quitWhenDone),
187 _filelistname(filelistname)
209 if (!filelistfile.is_open())
210 throw invalid_argument(
"FileInput::run(): filelist '" +
_filelistname +
211 "' could not be opened");
212 vector<string> filelist(tokenize(filelistfile));
213 filelistfile.close();
218 vector<string>::const_iterator filelistIt(filelist.begin());
219 vector<string>::const_iterator filelistEnd(filelist.end());
220 for (;filelistIt != filelistEnd; ++filelistIt)
222 string filename(*filelistIt);
243 fileProcessors_t::iterator pIt(
_fProcs.begin());
244 fileProcessors_t::iterator pEnd(
_fProcs.end());
245 for (;(!
shouldQuit()) && (pIt != pEnd); ++pIt)
257 for (; pIt != pEnd; ++pIt)
260 (*pIt)->rethrowException();
261 eventcounter += (*pIt)->nEventsProcessed();
275 double progressSum(0.);
276 for (fileProcessors_t::const_iterator it(
_fProcs.begin()); it !=
_fProcs.end(); ++it)
277 progressSum += (*it)->progress();
278 return (progressSum /
_fProcs.size());
284 for (fileProcessors_t::const_iterator it(
_fProcs.begin()); it !=
_fProcs.end(); ++it)
285 counter += (*it)->nEventsProcessed();
292 for (fileProcessors_t::const_iterator it(
_fProcs.begin()); it !=
_fProcs.end(); ++it)
293 counter += (*it)->nSkippedEvents();
class calculating a rate in Hz.
sleep(unsigned long secs)
void runthis()
process the file
status_t _status
the internal status of the thread
std::tr1::shared_ptr< FileProcessor > shared_pointer
define the shared pointer of this
uint64_t nSkippedEvents()
retrieve the number of skipped events by this thread
file contains declaration of the CASSEvent
uint64_t id_t
define the id type
uint64_t nEventsProcessed()
retrieve the number of events processed by this thread
streampos _filesize
the size of the file
static void add(Level level, const std::string &line)
add a string to the log
ifstream _file
the file stream
fromStdString(const std::string &str)
A Ringbuffer, handles communication between Input and Worker Threads.
FileReader::shared_pointer _read
shared pointer to the actual reader
bool shouldQuit() const
query whether this thread is told to quit
tokenize to return all lines of an ascii file in a vector
std::string toString(const Type &t)
convert any type to a string
uint64_t _skippedcounter
a counter for the skipped events
value(const QString &key, const QVariant &defaultValue=QVariant()
uint64_t _counter
a counter for the events
double progress()
retrieve the progess within the file
FileProcessor(const string &filename)
constructor
file contains specialized class that do the settings for cass
string _filename
the filename to work on
Example of how to use the sacla online input
std::tr1::shared_ptr< FileReader > shared_pointer
typedef the shared pointer of this
contains a logger for cass
beginGroup(const QString &prefix)
A QThread that has the ability to be paused and resumed.