Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | Private Attributes | List of all members
JSUPPORT::JMultipleFileScanner< Head > Class Template Referenceabstract

Template specialisation of JMultipleFileScanner for Monte Carlo header. More...

#include <JMonteCarloFileSupportkit.hh>

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

Public Types

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

Public Member Functions

 JMultipleFileScanner ()
 Default constructor. More...
 
 JMultipleFileScanner (const JMultipleFileScanner_t &file_list)
 Copy constructor. More...
 
virtual void rewind ()
 Rewind. More...
 
virtual bool setObject (Head &object)
 Set object. More...
 
const HeadgetHeader ()
 Get Monte Carlo Header. More...
 
const std::string & getFilename () const
 Get current file name. More...
 
counter_type getCounter () const
 Get counter. More...
 
virtual bool hasNext ()
 Check availability of next element. More...
 
virtual const pointer_typenext ()
 Get next element. More...
 
virtual skip_type skip (const skip_type ns)
 Skip items. More...
 
virtual skip_type skip (const skip_type ns)
 Skip items. More...
 
virtual bool hasNext ()
 Check availability of next element. More...
 
virtual const pointer_typenext ()
 Get next element. More...
 
virtual bool setObject (T &object)=0
 Set object. More...
 

Static Public Attributes

static bool merge = false
 Allow merging of files w/o header. More...
 

Protected Attributes

JFileScanner< JNullTypescanner
 
unsigned int index
 
counter_type counter
 
T object
 object More...
 
bool has_next
 status More...
 

Private Attributes

bool do_next
 

Detailed Description

template<>
class JSUPPORT::JMultipleFileScanner< Head >

Template specialisation of JMultipleFileScanner for Monte Carlo header.

This class re-implements the methods rewind and setObject of the JLANG::JRewindableAbstractObjectIterator interface so that all header objects in the complete file list are read and added. It provides for the method JSUPPORT::getHeader which returns the sum of all headers.

Definition at line 324 of file JMonteCarloFileSupportkit.hh.

Member Typedef Documentation

Definition at line 263 of file JMultipleFileScanner.hh.

Definition at line 264 of file JMultipleFileScanner.hh.

template<class T>
typedef JObjectIterator<T>::pointer_type JLANG::JAbstractObjectIterator< T >::pointer_type
inherited

Definition at line 39 of file JAbstractObjectIterator.hh.

Constructor & Destructor Documentation

Copy constructor.

The file list is copied.

Parameters
file_listJMultipleFileScanner

Definition at line 345 of file JMonteCarloFileSupportkit.hh.

Member Function Documentation

virtual void JSUPPORT::JMultipleFileScanner< Head >::rewind ( )
inlinevirtual

Rewind.

Reimplemented from JSUPPORT::JMultipleFileScanner<>.

Definition at line 357 of file JMonteCarloFileSupportkit.hh.

virtual bool JSUPPORT::JMultipleFileScanner< Head >::setObject ( Head object)
inlinevirtual

Set object.

Parameters
objectreference to object to be set
Returns
true if set; else false

Definition at line 369 of file JMonteCarloFileSupportkit.hh.

370  {
371  if (do_next) {
372 
373  using namespace JLANG;
374 
375  JHead header;
376 
377  do_next = false;
378 
379  unsigned int count = 0;
380 
382 
383  for (const_iterator i = this->begin(); i != this->end(); ++i) {
384 
385  scanner.open(i->c_str());
386 
387  if (scanner.hasNext()) {
388 
389  const JHead buffer = *scanner.next();
390 
391  if (count == 0)
392  header = buffer;
393  else if (header.match(buffer))
394  header.add(buffer);
395  else
396  THROW(JException, "JMultipleFileScanner<Head>::setObject(): inconsistent headers.");
397 
398  ++count;
399  }
400 
401  scanner.close();
402  }
403 
404  copy(header, object);
405 
406  if (count != 0 && count != this->size()) {
407  if (!merge) {
408  THROW(JException, "JMultipleFileScanner<Head>::setObject(): missing header(s): " << count << " != " << this->size());
409  }
410  }
411 
412  return count != 0;
413 
414  } else {
415 
416  return false;
417  }
418  }
General exception.
Definition: JException.hh:23
virtual void open(const char *file_name)
Open file.
Definition: JFileScanner.hh:66
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JHead & add(const JHead &header)
Addition of headers.
Definition: JHead.hh:1035
static bool merge
Allow merging of files w/o header.
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.
Monte Carlo run header.
Definition: JHead.hh:836
std::vector< int > count
Definition: JAlgorithm.hh:184
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:153
Object reading from file.
Definition: JFileScanner.hh:36
const Head& JSUPPORT::JMultipleFileScanner< Head >::getHeader ( )
inline

Get Monte Carlo Header.

Returns
header

Definition at line 426 of file JMonteCarloFileSupportkit.hh.

427  {
428  const Head* p = NULL;
429 
430  if (!this->hasNext() || (p = this->next()) == NULL) {
431  throw JNullPointerException("JMultipleFileScanner<Head>::getHeader(): Missing Header.");
432  }
433 
434  rewind();
435 
436  return *p;
437  }
virtual const pointer_type & next()
Get next element.
Exception for null pointer operation.
Definition: JException.hh:216
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:66
virtual bool hasNext()
Check availability of next element.
const std::string& JSUPPORT::JMultipleFileScanner< JNullType >::getFilename ( ) const
inlineinherited

Get current file name.

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

Returns
file name

Definition at line 312 of file JMultipleFileScanner.hh.

313  {
314  return this->at(index);
315  }
counter_type JSUPPORT::JMultipleFileScanner< JNullType >::getCounter ( ) const
inlineinherited

Get counter.

Returns
counter

Definition at line 323 of file JMultipleFileScanner.hh.

324  {
325  return counter;
326  }
virtual bool JSUPPORT::JMultipleFileScanner< JNullType >::hasNext ( )
inlinevirtualinherited

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 350 of file JMultipleFileScanner.hh.

351  {
352  if (is_valid()) {
353 
354  if (counter < getUpperLimit() && index != this->size()) {
355 
356  // first time around
357 
358  if (!scanner.is_open()) {
359  scanner.open(getFilename().c_str());
360  }
361 
362  if (counter < getLowerLimit()) {
363  counter += scanner.skip(getLowerLimit() - counter);
364  }
365 
366  if (!scanner.hasNext()) {
367 
368  scanner.close();
369 
370  ++index;
371 
372  return hasNext();
373  }
374 
375  return true;
376 
377  } else {
378 
379  // last time around
380 
381  if (scanner.is_open()) {
382  scanner.close();
383  }
384 
385  scanner.reset();
386  }
387  }
388 
389  return false;
390  }
virtual void open(const char *file_name)
Open file.
Definition: JFileScanner.hh:66
virtual skip_type skip(const skip_type ns)
Skip items.
virtual bool is_open() const
Check is device is open.
bool is_valid(const json &js)
Check validity of JSon data.
virtual bool hasNext()=0
Check availability of next element.
const std::string & getFilename() const
Get current file name.
virtual bool hasNext()
Check availability of next element.
virtual void reset()
Reset pointer.
virtual const pointer_type& JSUPPORT::JMultipleFileScanner< JNullType >::next ( )
inlinevirtualinherited

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 398 of file JMultipleFileScanner.hh.

399  {
400  ++counter;
401 
402  return scanner.next();
403  }
virtual const pointer_type & next()=0
Get next element.
virtual skip_type JSUPPORT::JMultipleFileScanner< JNullType >::skip ( const skip_type  ns)
inlinevirtualinherited

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 412 of file JMultipleFileScanner.hh.

413  {
414  skip_type i = 0;
415 
416  while (this->hasNext() && i != ns) {
417  i += scanner.skip(ns - i);
418  }
419 
420  counter += i;
421 
422  return i;
423  }
unsigned int skip_type
Type definition for number of objects to skip.
virtual skip_type skip(const skip_type ns)
Skip items.
virtual bool hasNext()
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< JNullType >, JLANG::JAbstractObjectReader< const T >, JLANG::JAbstractObjectReader< JTail_t >, JLANG::JAbstractObjectReader< JHead_t >, JLANG::JAbstractObjectReader< KM3NETDAQ::KM3NETDAQ::JDAQEvent >, JLANG::JAbstractObjectReader< JDAQSummaryslice >, and JLANG::JAbstractObjectReader< JTypeList< JDAQEvent, JTypelist_t > >.

Definition at line 88 of file JObjectIterator.hh.

89  {
90  skip_type i = 0;
91 
92  for ( ; i != ns && hasNext(); ++i) {
93  next();
94  }
95 
96  return i;
97  }
unsigned int skip_type
Type definition for number of objects to skip.
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.
template<class T>
virtual bool JLANG::JAbstractObjectIterator< T >::hasNext ( )
inlinevirtualinherited

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 56 of file JAbstractObjectIterator.hh.

57  {
58  if (!has_next) {
59  has_next = this->setObject(object);
60  }
61 
62  return has_next;
63  }
virtual bool setObject(T &object)=0
Set object.
template<class T>
virtual const pointer_type& JLANG::JAbstractObjectIterator< T >::next ( )
inlinevirtualinherited

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 71 of file JAbstractObjectIterator.hh.

72  {
73  if (has_next)
74  ps.reset(&this->object);
75  else
76  ps.reset(NULL);
77 
78  has_next = false;
79 
80  return ps;
81  }
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
template<class T>
virtual bool JLANG::JAbstractObjectIterator< T >::setObject ( T object)
pure virtualinherited

Member Data Documentation

bool JSUPPORT::JMultipleFileScanner< Head >::merge = false
static

Allow merging of files w/o header.

Initialisation of merge option.

Definition at line 439 of file JMonteCarloFileSupportkit.hh.

bool JSUPPORT::JMultipleFileScanner< Head >::do_next
private

Definition at line 442 of file JMonteCarloFileSupportkit.hh.

Definition at line 427 of file JMultipleFileScanner.hh.

unsigned int JSUPPORT::JMultipleFileScanner< JNullType >::index
protectedinherited

Definition at line 428 of file JMultipleFileScanner.hh.

counter_type JSUPPORT::JMultipleFileScanner< JNullType >::counter
protectedinherited

Definition at line 429 of file JMultipleFileScanner.hh.

template<class T>
T JLANG::JAbstractObjectIterator< T >::object
protectedinherited

object

Definition at line 34 of file JAbstractObjectIterator.hh.

template<class T>
bool JLANG::JAbstractObjectIterator< T >::has_next
protectedinherited

status

Definition at line 35 of file JAbstractObjectIterator.hh.


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