CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
PthrReaderBufPool< Reader, PoolSize > Class Template Reference

#include <PthrReaderBufPool.h>

+ Inheritance diagram for PthrReaderBufPool< Reader, PoolSize >:

Public Member Functions

 PthrReaderBufPool (typename Reader::ReaderArgType &arg)
 
virtual ~PthrReaderBufPool ()
 
const uint32_t * nextEvent ()
 
const uint32_t * currentEvent () const
 
uint32_t runNo ()
 
std::string currentFile ()
 
uint32_t stat ()
 
- Public Member Functions inherited from IRawReader
virtual ~IRawReader ()
 
virtual const uint32_t * nextEvent ()=0
 
virtual const uint32_t * currentEvent () const =0
 
virtual uint32_t runNo ()=0
 
virtual std::string currentFile ()=0
 
virtual uint32_t stat ()=0
 

Detailed Description

template<typename Reader, int PoolSize = 8>
class PthrReaderBufPool< Reader, PoolSize >

Definition at line 13 of file PthrReaderBufPool.h.

Constructor & Destructor Documentation

◆ PthrReaderBufPool()

template<typename Reader , int PoolSize>
PthrReaderBufPool< Reader, PoolSize >::PthrReaderBufPool ( typename Reader::ReaderArgType &  arg)

Definition at line 19 of file PthrReaderBufPool.cc.

20 : m_inLoop(-1),
21 m_outLoop(-1),
22 m_RawFileException(0)
23{
24 if ( PoolSize < 2 ) {
25 std::cout << "[PthrReaderBufPool] The PoolSize of buffer must > 1" << std::endl;
26 exit(1);
27 }
28
29 // use(PoolSize-1) to protect the current event buffer
30 sem_init(&m_semIn, 0, (PoolSize-1));
31 sem_init(&m_semOut, 0, 0);
32 pthread_mutex_init(&m_lock, NULL);
33
34 sem_init(&m_semSyn, 0, 0);
35
36 for ( int i = 0; i < PoolSize; ++i ) {
37 // buffer in the loop for each event
38 m_buf[i] = new AutoEnlargeBuffer(128*1024);
39 }
40
41 m_reader = new Reader(arg);
42
43 // create an individual thread to fill to buffer
44 pthread_create(&m_tid, NULL, thread_filling, (void*)this);
45}
double arg(const EvtComplex &c)
Definition: EvtComplex.hh:227

◆ ~PthrReaderBufPool()

template<typename Reader , int PoolSize>
PthrReaderBufPool< Reader, PoolSize >::~PthrReaderBufPool
virtual

Definition at line 48 of file PthrReaderBufPool.cc.

49{
50 for ( int i = 0; i < PoolSize; ++i ) {
51 delete m_buf[i];
52 }
53
54 delete m_RawFileException;
55
56 sem_destroy(&m_semIn);
57 sem_destroy(&m_semOut);
58
59 delete m_reader;
60}

Member Function Documentation

◆ currentEvent()

template<typename Reader , int PoolSize>
const uint32_t * PthrReaderBufPool< Reader, PoolSize >::currentEvent
inlinevirtual

Implements IRawReader.

Definition at line 92 of file PthrReaderBufPool.cc.

93{
94 //can't be called before any nextEvent() call
95 const uint32_t* pevt = (uint32_t*)m_buf[ m_outLoop%PoolSize ]->data();
96 return pevt;
97}
TTree * data

◆ currentFile()

template<typename Reader , int PoolSize>
std::string PthrReaderBufPool< Reader, PoolSize >::currentFile
inlinevirtual

Implements IRawReader.

Definition at line 106 of file PthrReaderBufPool.cc.

107{
108 return m_reader->currentFile();
109}

Referenced by main().

◆ nextEvent()

template<typename Reader , int PoolSize>
const uint32_t * PthrReaderBufPool< Reader, PoolSize >::nextEvent
inlinevirtual

Implements IRawReader.

Definition at line 63 of file PthrReaderBufPool.cc.

64{
65 if ( m_outLoop < 0 ) sem_post(&m_semSyn);
66
67 // the ahead event buffer is ready for update now
68 sem_post(&m_semIn);
69 // waiting for a ready to use event
70 sem_wait(&m_semOut);
71
72 pthread_mutex_lock(&m_lock);
73 int inLoop = m_inLoop;
74 pthread_mutex_unlock(&m_lock);
75
76 if ( m_RawFileException != 0 && m_outLoop >= inLoop ) {
77 if ( dynamic_cast<RawExMessage*>(m_RawFileException) ) {
78 throw RawExMessage(*(RawExMessage*)m_RawFileException);
79 }
80 if ( dynamic_cast<ReachEndOfFileList*>(m_RawFileException) ) {
81 throw ReachEndOfFileList(*(ReachEndOfFileList*)m_RawFileException);
82 }
83 }
84
85 ++m_outLoop;
86
87 const uint32_t* pevt = (uint32_t*)m_buf[ m_outLoop%PoolSize ]->data();
88 return pevt;
89}

Referenced by main().

◆ runNo()

template<typename Reader , int PoolSize>
uint32_t PthrReaderBufPool< Reader, PoolSize >::runNo
inlinevirtual

Implements IRawReader.

Definition at line 100 of file PthrReaderBufPool.cc.

101{
102 return m_reader->runNo();
103}

◆ stat()

template<typename Reader , int PoolSize>
uint32_t PthrReaderBufPool< Reader, PoolSize >::stat
inlinevirtual

Implements IRawReader.

Definition at line 112 of file PthrReaderBufPool.cc.

113{
114 return m_reader->stat();
115}

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