Jpp  pmt_effective_area_update_2
the software that should make you happy
 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 () override
 Rewind. More...
 
virtual bool setObject (Head &object) override
 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 () 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...
 
virtual bool hasNext () override
 Check availability of next element. More...
 
virtual const pointer_typenext () override
 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 337 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 358 of file JMonteCarloFileSupportkit.hh.

Member Function Documentation

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

Rewind.

Reimplemented from JSUPPORT::JMultipleFileScanner<>.

Definition at line 370 of file JMonteCarloFileSupportkit.hh.

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

Set object.

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

Definition at line 382 of file JMonteCarloFileSupportkit.hh.

383  {
384  if (do_next) {
385 
386  using namespace JLANG;
387 
388  JHead header;
389 
390  do_next = false;
391 
392  unsigned int count = 0;
393 
395 
396  for (const_iterator i = this->begin(); i != this->end(); ++i) {
397 
398  scanner.open(i->c_str());
399 
400  if (scanner.hasNext()) {
401 
402  const JHead buffer = *scanner.next();
403 
404  if (count == 0)
405  header = buffer;
406  else if (header.match(buffer))
407  header.add(buffer);
408  else
409  THROW(JException, "JMultipleFileScanner<Head>::setObject(): inconsistent headers.");
410 
411  ++count;
412  }
413 
414  scanner.close();
415  }
416 
417  copy(header, object);
418 
419  if (count != 0 && count != this->size()) {
420  if (!merge) {
421  THROW(JException, "JMultipleFileScanner<Head>::setObject(): missing header(s): " << count << " != " << this->size());
422  }
423  }
424 
425  return count != 0;
426 
427  } else {
428 
429  return false;
430  }
431  }
General exception.
Definition: JException.hh:23
#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:1345
static bool merge
Allow merging of files w/o header.
virtual void open(const char *file_name) override
Open file.
Definition: JFileScanner.hh:66
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:1113
virtual void close() override
Close device.
std::vector< int > count
Definition: JAlgorithm.hh:180
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
Object reading from file.
Definition: JFileScanner.hh:36
const Head& JSUPPORT::JMultipleFileScanner< Head >::getHeader ( )
inline

Get Monte Carlo Header.

Returns
header

Definition at line 439 of file JMonteCarloFileSupportkit.hh.

440  {
441  const Head* p = NULL;
442 
443  if (!this->hasNext() || (p = this->next()) == NULL) {
444  throw JNullPointerException("JMultipleFileScanner<Head>::getHeader(): Missing Header.");
445  }
446 
447  rewind();
448 
449  return *p;
450  }
Exception for null pointer operation.
Definition: JException.hh:216
virtual bool hasNext() override
Check availability of next element.
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:67
virtual const pointer_type & next() override
Get 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 325 of file JMultipleFileScanner.hh.

326  {
327  return this->at(index);
328  }
counter_type JSUPPORT::JMultipleFileScanner< JNullType >::getCounter ( ) const
inlineinherited

Get counter.

Returns
counter

Definition at line 336 of file JMultipleFileScanner.hh.

337  {
338  return counter;
339  }
virtual bool JSUPPORT::JMultipleFileScanner< JNullType >::hasNext ( )
inlineoverridevirtualinherited

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 363 of file JMultipleFileScanner.hh.

364  {
365  if (is_valid()) {
366 
367  if (counter < getUpperLimit() && index != this->size()) {
368 
369  // first time around
370 
371  if (!scanner.is_open()) {
372  scanner.open(getFilename().c_str());
373  }
374 
375  if (counter < getLowerLimit()) {
376  counter += scanner.skip(getLowerLimit() - counter);
377  }
378 
379  if (!scanner.hasNext()) {
380 
381  scanner.close();
382 
383  ++index;
384 
385  return hasNext();
386  }
387 
388  return true;
389 
390  } else {
391 
392  // last time around
393 
394  if (scanner.is_open()) {
395  scanner.close();
396  }
397 
398  scanner.reset();
399  }
400  }
401 
402  return false;
403  }
virtual skip_type skip(const skip_type ns)
Skip items.
virtual void open(const char *file_name) override
Open file.
Definition: JFileScanner.hh:66
virtual bool hasNext() override
Check availability of next element.
bool is_valid(const json &js)
Check validity of JSon data.
virtual bool hasNext()=0
Check availability of next element.
virtual bool is_open() const override
Check is device is open.
const std::string & getFilename() const
Get current file name.
virtual void close() override
Close device.
virtual void reset() override
Reset pointer.
virtual const pointer_type& JSUPPORT::JMultipleFileScanner< JNullType >::next ( )
inlineoverridevirtualinherited

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 411 of file JMultipleFileScanner.hh.

412  {
413  ++counter;
414 
415  return scanner.next();
416  }
virtual const pointer_type & next()=0
Get next element.
virtual skip_type JSUPPORT::JMultipleFileScanner< JNullType >::skip ( const skip_type  ns)
inlineoverridevirtualinherited

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

426  {
427  skip_type i = 0;
428 
429  while (this->hasNext() && i != ns) {
430  i += scanner.skip(ns - i);
431  }
432 
433  counter += i;
434 
435  return i;
436  }
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() 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< 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 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.
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 ( )
inlineoverridevirtualinherited

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 ( )
inlineoverridevirtualinherited

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() override
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 452 of file JMonteCarloFileSupportkit.hh.

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

Definition at line 455 of file JMonteCarloFileSupportkit.hh.

Definition at line 440 of file JMultipleFileScanner.hh.

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

Definition at line 441 of file JMultipleFileScanner.hh.

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

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