Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | 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 Head & getHeader ()
 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...
 

Protected Attributes

JFileScanner< JNullTypescanner
 
unsigned int index
 
counter_type counter
 
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 getHeader which returns the sum of all Headers.

Definition at line 291 of file JMonteCarloFileSupportkit.hh.

Member Typedef Documentation

Definition at line 202 of file JMultipleFileScanner.hh.

Definition at line 203 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 312 of file JMonteCarloFileSupportkit.hh.

Member Function Documentation

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

Rewind.

Reimplemented from JSUPPORT::JMultipleFileScanner<>.

Definition at line 324 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 336 of file JMonteCarloFileSupportkit.hh.

337  {
338  if (do_next) {
339 
340  using namespace JLANG;
341  using JAANET::JHead;
342 
343  JHead header;
344 
345  do_next = false;
346 
347  unsigned int count = 0;
348 
350 
351  for (const_iterator i = this->begin(); i != this->end(); ++i) {
352 
353  scanner.open(i->c_str());
354 
355  if (scanner.hasNext()) {
356 
357  const JHead buffer = *scanner.next();
358 
359  if (count == 0)
360  header = buffer;
361  else if (header.equals(buffer))
362  header.add(buffer);
363  else
364  THROW(JException, "JMultipleFileScanner<Head>::setObject(): inconsistent headers.");
365 
366  ++count;
367  }
368 
369  scanner.close();
370  }
371 
372  copy(header, object);
373 
374  if (count != 0 && count != this->size()) {
375  THROW(JException, "JMultipleFileScanner<Head>::setObject(): missing header(s): " << count << " != " << this->size());
376  }
377 
378  return count != 0;
379 
380  } else {
381 
382  return false;
383  }
384  }
General exception.
Definition: JException.hh:40
virtual void open(const char *file_name)
Open file.
Definition: JFileScanner.hh:64
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
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:727
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:40
Object reading from file.
Definition: JFileScanner.hh:34
const Head& JSUPPORT::JMultipleFileScanner< Head >::getHeader ( )
inline

Get Monte Carlo Header.

Returns
header

Definition at line 392 of file JMonteCarloFileSupportkit.hh.

393  {
394  const Head* p = NULL;
395 
396  if (!this->hasNext() || (p = this->next()) == NULL) {
397  throw JNullPointerException("JMultipleFileScanner<Head>::getHeader(): Missing Header.");
398  }
399 
400  rewind();
401 
402  return *p;
403  }
virtual const pointer_type & next()
Get next element.
Exception for null pointer operation.
Definition: JException.hh:198
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 251 of file JMultipleFileScanner.hh.

252  {
253  return this->at(index);
254  }
counter_type JSUPPORT::JMultipleFileScanner< JNullType >::getCounter ( ) const
inlineinherited

Get counter.

Returns
counter

Definition at line 262 of file JMultipleFileScanner.hh.

263  {
264  return counter;
265  }
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 289 of file JMultipleFileScanner.hh.

290  {
291  if (is_valid()) {
292 
293  if (counter < getUpperLimit() && index != this->size()) {
294 
295  // first time around
296 
297  if (!scanner.is_open()) {
298  scanner.open(getFilename().c_str());
299  }
300 
301  if (counter < getLowerLimit()) {
302  counter += scanner.skip(getLowerLimit() - counter);
303  }
304 
305  if (!scanner.hasNext()) {
306 
307  scanner.close();
308 
309  ++index;
310 
311  return hasNext();
312  }
313 
314  return true;
315 
316  } else {
317 
318  // last time around
319 
320  if (scanner.is_open()) {
321  scanner.close();
322  }
323 
324  scanner.reset();
325  }
326  }
327 
328  return false;
329  }
virtual void open(const char *file_name)
Open file.
Definition: JFileScanner.hh:64
virtual skip_type skip(const skip_type ns)
Skip items.
virtual bool is_open() const
Check is device is open.
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.
bool is_valid(const T &value)
Check validity of given value.
Definition: JHead.hh:711
virtual const pointer_type& JSUPPORT::JMultipleFileScanner< JNullType >::next ( )
inlinevirtualinherited

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 337 of file JMultipleFileScanner.hh.

338  {
339  ++counter;
340 
341  return scanner.next();
342  }
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 351 of file JMultipleFileScanner.hh.

352  {
353  skip_type i = 0;
354 
355  while (this->hasNext() && i != ns) {
356  i += scanner.skip(ns - i);
357  }
358 
359  counter += i;
360 
361  return i;
362  }
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

Set object.

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

Implemented in JNET::JControlHostObjectIterator< T >, JNET::JLigierObjectIterator< T >, JSUPPORT::JDAQFileReader< T, true >, JIO::JReaderObjectIterator< T >, and JLANG::JStreamObjectIterator< T >.

Member Data Documentation

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

Definition at line 407 of file JMonteCarloFileSupportkit.hh.

Definition at line 366 of file JMultipleFileScanner.hh.

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

Definition at line 367 of file JMultipleFileScanner.hh.

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

Definition at line 368 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: