Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
JSUPPORT::JMultipleFileScanner< T > Class Template Reference

General purpose class for object reading from a list of file names. More...

#include <JMultipleFileScanner.hh>

Inheritance diagram for JSUPPORT::JMultipleFileScanner< T >:
JLANG::JRewindableObjectIterator< T > JLANG::JObjectIterator< T > JLANG::JRewindable< T >

Public Types

typedef
JMultipleFileScanner::input_type 
input_type
 
typedef
JRewindableObjectIterator< T >
::pointer_type 
pointer_type
 

Public Member Functions

 JMultipleFileScanner ()
 Default constructor. More...
 
template<class JTypelist_t >
 JMultipleFileScanner (const JMultipleFileScanner< JTypelist_t > &input)
 Copy constructor. More...
 
 JMultipleFileScanner (const input_type &file_list)
 Constructor. More...
 
 JMultipleFileScanner (const input_type &file_list, const JLimit &limit)
 Constructor. More...
 
const std::string & getFilename () const
 Get current file name. More...
 
counter_type getCounter () const
 Get counter. More...
 
virtual void rewind () override
 Rewind. More...
 
virtual bool hasNext () override
 Check availability of next element. More...
 
virtual const pointer_typenext () override
 Get next element. More...
 
virtual skip_type skip (const skip_type ns) override
 Skip items. More...
 
virtual skip_type skip (const skip_type ns)
 Skip items. More...
 

Protected Attributes

JFileScanner< Tscanner
 
unsigned int index
 
counter_type counter
 

Detailed Description

template<class T = JNullType>
class JSUPPORT::JMultipleFileScanner< T >

General purpose class for object reading from a list of file names.

Implementation of object reading for single data type from a list of file names.

This class extends the JMultipleFileScanner<JNullType> class and implements the JLANG::JRewindableObjectIterator interface.
When the method hasNext() is called, the next file in the list is opened when the previous file is exhausted.

Definition at line 202 of file JMultipleFileScanner.hh.

Member Typedef Documentation

template<class T = JNullType>
typedef JMultipleFileScanner ::input_type JSUPPORT::JMultipleFileScanner< T >::input_type

Definition at line 309 of file JMultipleFileScanner.hh.

Definition at line 310 of file JMultipleFileScanner.hh.

Constructor & Destructor Documentation

template<class T = JNullType>
JSUPPORT::JMultipleFileScanner< T >::JMultipleFileScanner ( )
inline

Default constructor.

Definition at line 315 of file JMultipleFileScanner.hh.

315  :
316  index (0),
317  counter(0)
318  {}
template<class T = JNullType>
template<class JTypelist_t >
JSUPPORT::JMultipleFileScanner< T >::JMultipleFileScanner ( const JMultipleFileScanner< JTypelist_t > &  input)
inline

Copy constructor.

Note that the counter limit is not copied and the index and counter are set to zero.

Parameters
inputinput

Definition at line 329 of file JMultipleFileScanner.hh.

329  :
330  index (0),
331  counter(0)
332  {
333  this->configure(input.getFilelist(), JLimit());
334  }
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
template<class T = JNullType>
JSUPPORT::JMultipleFileScanner< T >::JMultipleFileScanner ( const input_type file_list)
inline

Constructor.

Parameters
file_listlist of file names

Definition at line 342 of file JMultipleFileScanner.hh.

342  :
343  index (0),
344  counter(0)
345  {
346  configure(file_list, JLimit());
347  }
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
template<class T = JNullType>
JSUPPORT::JMultipleFileScanner< T >::JMultipleFileScanner ( const input_type file_list,
const JLimit limit 
)
inline

Constructor.

Parameters
file_listlist of file names
limitlimit

Definition at line 356 of file JMultipleFileScanner.hh.

356  :
357  index (0),
358  counter(0)
359  {
360  configure(file_list, limit);
361  }
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.

Member Function Documentation

template<class T = JNullType>
const std::string& JSUPPORT::JMultipleFileScanner< T >::getFilename ( ) const
inline

Get current file name.

Note that this method should only be called when method hasNext() returns true.

Returns
file name

Definition at line 371 of file JMultipleFileScanner.hh.

372  {
373  return this->at(index);
374  }
template<class T = JNullType>
counter_type JSUPPORT::JMultipleFileScanner< T >::getCounter ( ) const
inline

Get counter.

Returns
counter

Definition at line 382 of file JMultipleFileScanner.hh.

383  {
384  return counter;
385  }
template<class T = JNullType>
virtual void JSUPPORT::JMultipleFileScanner< T >::rewind ( )
inlineoverridevirtual

Rewind.

Implements JLANG::JRewindable< T >.

Reimplemented in JSUPPORT::JMultipleFileScanner< JTypeList< JHead_t, JTail_t > >, JSUPPORT::JMultipleFileScanner< Head >, and JSUPPORT::JMultipleFileScanner< JTriggerParameters >.

Definition at line 391 of file JMultipleFileScanner.hh.

392  {
393  if (scanner.is_open()) {
394  scanner.close();
395  }
396 
397  index = 0;
398  counter = 0;
399 
400  scanner.reset();
401  }
template<class T = JNullType>
virtual bool JSUPPORT::JMultipleFileScanner< T >::hasNext ( )
inlineoverridevirtual

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 409 of file JMultipleFileScanner.hh.

410  {
411  if (is_valid()) {
412 
413  if (counter < getUpperLimit() && index != this->size()) {
414 
415  // first time around
416 
417  if (!scanner.is_open()) {
418  scanner.open(getFilename().c_str());
419  }
420 
421  if (counter < getLowerLimit()) {
422  counter += scanner.skip(getLowerLimit() - counter);
423  }
424 
425  if (!scanner.hasNext()) {
426 
427  scanner.close();
428 
429  ++index;
430 
431  return hasNext();
432  }
433 
434  return true;
435 
436  } else {
437 
438  // last time around
439 
440  if (scanner.is_open()) {
441  scanner.close();
442  }
443 
444  scanner.reset();
445  }
446  }
447 
448  return false;
449  }
bool is_valid(const json &js)
Check validity of JSon data.
virtual bool hasNext() override
Check availability of next element.
const std::string & getFilename() const
Get current file name.
template<class T = JNullType>
virtual const pointer_type& JSUPPORT::JMultipleFileScanner< T >::next ( )
inlineoverridevirtual

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 457 of file JMultipleFileScanner.hh.

458  {
459  ++counter;
460 
461  return scanner.next();
462  }
template<class T = JNullType>
virtual skip_type JSUPPORT::JMultipleFileScanner< T >::skip ( const skip_type  ns)
inlineoverridevirtual

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

Reimplemented in JSUPPORT::JMultipleFileScanner< JTypeList< JHead_t, JTail_t > >.

Definition at line 471 of file JMultipleFileScanner.hh.

472  {
473  skip_type i = 0;
474 
475  while (this->hasNext() && i != ns) {
476  i += scanner.skip(ns - i);
477  }
478 
479  counter += i;
480 
481  return i;
482  }
unsigned int skip_type
Type definition for number of objects to skip.
std::vector< size_t > ns
virtual bool hasNext() override
Check availability of next element.
template<class T>
virtual skip_type JLANG::JObjectIterator< T >::skip ( const skip_type  ns)
inlinevirtualinherited

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

Reimplemented in JLANG::JPipe< T >, JLANG::JPipe< JTail_t >, JLANG::JPipe< JHead_t >, JLANG::JSTDObjectIterator< T >, JLANG::JAbstractObjectReader< T >, JLANG::JAbstractObjectReader< const event_type >, JLANG::JAbstractObjectReader< JNullType >, JLANG::JAbstractObjectReader< const T >, JLANG::JAbstractObjectReader< JTail_t >, JLANG::JAbstractObjectReader< JHead_t >, JLANG::JAbstractObjectReader< KM3NETDAQ::KM3NETDAQ::JDAQEvent >, and JLANG::JAbstractObjectReader< JDAQSummaryslice >.

Definition at line 90 of file JObjectIterator.hh.

91  {
92  skip_type i = 0;
93 
94  for ( ; i != ns && hasNext(); ++i) {
95  next();
96  }
97 
98  return i;
99  }
unsigned int skip_type
Type definition for number of objects to skip.
std::vector< size_t > ns
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.

Member Data Documentation

template<class T = JNullType>
JFileScanner<T> JSUPPORT::JMultipleFileScanner< T >::scanner
protected

Definition at line 486 of file JMultipleFileScanner.hh.

template<class T = JNullType>
unsigned int JSUPPORT::JMultipleFileScanner< T >::index
protected

Definition at line 487 of file JMultipleFileScanner.hh.

template<class T = JNullType>
counter_type JSUPPORT::JMultipleFileScanner< T >::counter
protected

Definition at line 488 of file JMultipleFileScanner.hh.


The documentation for this class was generated from the following file: