CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
PlaybackRawDataProvider Class Reference

#include <PlaybackRawDataProvider.h>

Inheritance diagram for PlaybackRawDataProvider:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
bool areFilesClosed ()
 
virtual void beginJob ()
 
virtual void endJob ()
 
virtual FEDRawDataCollectiongetFEDRawData ()
 
virtual FEDRawDataCollectiongetFEDRawData (unsigned int &runNumber, unsigned int &evtNumber)
 
 PlaybackRawDataProvider (const edm::ParameterSet &)
 
virtual void respondToCloseInputFile (edm::FileBlock const &fb)
 
void setFreeToEof ()
 
virtual ~PlaybackRawDataProvider ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Static Public Member Functions

static PlaybackRawDataProviderinstance ()
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 

Private Member Functions

void lock ()
 
void postReadSem ()
 
void postWriteSem ()
 
void sem_print ()
 
void unlock ()
 
void waitReadSem ()
 
void waitWriteSem ()
 

Private Attributes

unsigned int count_
 
bool destroying_
 
FEDRawDataCollection ** eventQueue_
 
unsigned int * evtNumber_
 
bool filesClosed_
 
bool freeToEof_
 
sem_t lock_
 
unsigned int queueSize_
 
unsigned int readIndex_
 
sem_t readSem_
 
unsigned int * runNumber_
 
unsigned int writeIndex_
 
sem_t writeSem_
 

Static Private Attributes

static PlaybackRawDataProviderinstance_ =0
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Protected Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 13 of file PlaybackRawDataProvider.h.

Constructor & Destructor Documentation

PlaybackRawDataProvider::PlaybackRawDataProvider ( const edm::ParameterSet iConfig)
explicit

Definition at line 31 of file PlaybackRawDataProvider.cc.

References eventQueue_, evtNumber_, edm::ParameterSet::getUntrackedParameter(), i, instance_, lock_, queueSize_, readSem_, runNumber_, and writeSem_.

32  : queueSize_(0)
33  , eventQueue_(0)
34  , runNumber_(0)
35  , evtNumber_(0)
36  , count_(0)
37  , writeIndex_(0)
38  , readIndex_(0)
39  , freeToEof_(false)
40  , filesClosed_(false)
41  , destroying_(false)
42 {
43  queueSize_=iConfig.getUntrackedParameter<unsigned int>("queueSize",32);
44  sem_init(&lock_,0,1);
45  sem_init(&writeSem_,0,queueSize_);
46  sem_init(&readSem_,0,0);
47  runNumber_ =new unsigned int[queueSize_];
48  evtNumber_ =new unsigned int[queueSize_];
50  for (unsigned int i=0;i<queueSize_;i++) eventQueue_[i]=0;
51  edm::LogInfo("PbImpl") << "Created Concrete RawData Provider 0x"<< hex << (unsigned long) this << dec << endl;
52  instance_=this;
53 }
FEDRawDataCollection ** eventQueue_
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
static PlaybackRawDataProvider * instance_
PlaybackRawDataProvider::~PlaybackRawDataProvider ( )
virtual

Definition at line 57 of file PlaybackRawDataProvider.cc.

References destroying_, eventQueue_, evtNumber_, i, instance_, lock_, postReadSem(), postWriteSem(), queueSize_, readSem_, runNumber_, unlock(), and writeSem_.

58 {
59  if (0!=runNumber_) delete [] runNumber_;
60  if (0!=evtNumber_) delete [] evtNumber_;
61  if (0!=eventQueue_) {
62  for (unsigned int i=0;i<queueSize_;i++)
63  if (0!=eventQueue_[i]) delete eventQueue_[i];
64  delete [] eventQueue_;
65  }
66  edm::LogInfo("PbImpl") << "Destroyed Concrete RawData Provider 0x"<< hex << (unsigned long) this << dec << endl;
67  instance_=0;
68 
69  destroying_=true;
70  postReadSem();
71  postWriteSem();
72  unlock();
73  sem_destroy(&lock_);
74  sem_destroy(&writeSem_);
75  sem_destroy(&readSem_);
76  usleep(10000);
77 }
FEDRawDataCollection ** eventQueue_
int i
Definition: DBlmapReader.cc:9
static PlaybackRawDataProvider * instance_

Member Function Documentation

void PlaybackRawDataProvider::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDAnalyzer.

Definition at line 85 of file PlaybackRawDataProvider.cc.

References count_, FEDRawData::data(), edm::EventID::event(), eventQueue_, evtNumber_, FEDRawDataCollection::FEDData(), freeToEof_, edm::Event::getByLabel(), i, edm::EventBase::id(), edm::HandleBase::isValid(), lock(), FEDNumbering::MAXFEDID, postReadSem(), queueSize_, FEDRawData::resize(), edm::EventID::run(), runNumber_, unlock(), waitWriteSem(), and writeIndex_.

87 {
88  if(freeToEof_) return;
89  waitWriteSem();
90  if(freeToEof_) return;
91  runNumber_[writeIndex_]=iEvent.id().run();
92  evtNumber_[writeIndex_]=iEvent.id().event();
93 
95  iEvent.getByLabel("rawDataCollector", pRawData);
96 
97  if (!pRawData.isValid()) {
98  edm::LogError("InvalidHandle")<<"no raw data found!"<<endl;
99  return;
100  }
101 
102 
103  // copy the raw data collection into rawData_, retrievable via getFEDRawData()
104  assert(0==eventQueue_[writeIndex_]);
106  for (unsigned int i=0;i<(unsigned int)FEDNumbering::MAXFEDID+1;i++) {
107  unsigned int fedSize=pRawData->FEDData(i).size();
108  if (fedSize>0) {
110  fedData.resize(fedSize);
111  memcpy(fedData.data(),pRawData->FEDData(i).data(),fedSize);
112  }
113  }
114 
115  lock();
117  count_++;
118  unlock();
119 
120  postReadSem();
121 
122  return;
123 }
RunNumber_t run() const
Definition: EventID.h:42
FEDRawDataCollection ** eventQueue_
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
Definition: FEDRawData.cc:33
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
edm::EventID id() const
Definition: EventBase.h:56
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
bool PlaybackRawDataProvider::areFilesClosed ( )

Definition at line 210 of file PlaybackRawDataProvider.cc.

References filesClosed_.

211 {
212  return filesClosed_;
213 }
void PlaybackRawDataProvider::beginJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 127 of file PlaybackRawDataProvider.cc.

128 {
129 
130 }
void PlaybackRawDataProvider::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 133 of file PlaybackRawDataProvider.cc.

References count_.

134 {
135  edm::LogInfo("Summary")<<count_<<" events read."<<endl;
136 }
FEDRawDataCollection * PlaybackRawDataProvider::getFEDRawData ( )
virtual

Definition at line 145 of file PlaybackRawDataProvider.cc.

References destroying_, eventQueue_, lock(), postWriteSem(), queueSize_, readIndex_, query::result, unlock(), and waitReadSem().

Referenced by evf::BU::generateEvent().

146 {
148  waitReadSem();
149  //do not read data if destructor is called
150  if (destroying_) return 0;
151  lock();
152  result = eventQueue_[readIndex_];
155  unlock();
156 
157  postWriteSem();
158  return result;
159 }
FEDRawDataCollection ** eventQueue_
tuple result
Definition: query.py:137
FEDRawDataCollection * PlaybackRawDataProvider::getFEDRawData ( unsigned int &  runNumber,
unsigned int &  evtNumber 
)
virtual

Definition at line 163 of file PlaybackRawDataProvider.cc.

References destroying_, eventQueue_, evtNumber_, lock(), postWriteSem(), queueSize_, readIndex_, query::result, runNumber_, unlock(), and waitReadSem().

165 {
166 
168  waitReadSem();
169  //do not read data if destructor is called
170  if (destroying_) return 0;
171  lock();
173  evtNumber=evtNumber_[readIndex_];
174  result=eventQueue_[readIndex_];
175  // assert(0!=result);
178 
179  unlock();
180 
181  postWriteSem();
182  return result;
183 }
FEDRawDataCollection ** eventQueue_
tuple result
Definition: query.py:137
PlaybackRawDataProvider * PlaybackRawDataProvider::instance ( )
inlinestatic

Definition at line 82 of file PlaybackRawDataProvider.h.

References instance_.

Referenced by evf::BU::actionPerformed(), evf::BU::enabling(), evf::BU::generateEvent(), evf::BU::halting(), and evf::BU::stopping().

83 {
84  return instance_;
85 }
static PlaybackRawDataProvider * instance_
void PlaybackRawDataProvider::lock ( void  )
inlineprivate

Definition at line 44 of file PlaybackRawDataProvider.h.

References lock_.

Referenced by analyze(), getFEDRawData(), and sem_print().

44 { sem_wait(&lock_); }
void PlaybackRawDataProvider::postReadSem ( )
inlineprivate

Definition at line 49 of file PlaybackRawDataProvider.h.

References readSem_.

Referenced by analyze(), and ~PlaybackRawDataProvider().

49 { sem_post(&readSem_); }
void PlaybackRawDataProvider::postWriteSem ( )
inlineprivate

Definition at line 47 of file PlaybackRawDataProvider.h.

References writeSem_.

Referenced by getFEDRawData(), setFreeToEof(), and ~PlaybackRawDataProvider().

47 { sem_post(&writeSem_); }
void PlaybackRawDataProvider::respondToCloseInputFile ( edm::FileBlock const &  fb)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 139 of file PlaybackRawDataProvider.cc.

References filesClosed_.

140 {
141  filesClosed_ = true;
142 }
void PlaybackRawDataProvider::sem_print ( )
private

Definition at line 187 of file PlaybackRawDataProvider.cc.

References gather_cfg::cout, lock(), readIndex_, readSem_, unlock(), writeIndex_, and writeSem_.

188 {
189  lock();
190  int wsem,rsem;
191  sem_getvalue(&writeSem_,&wsem);
192  sem_getvalue(&readSem_,&rsem);
193  cout<<"sem_print():"
194  <<" wsem="<<wsem
195  <<" rsem="<<rsem
196  <<" writeIndex="<<writeIndex_
197  <<" readIndex="<<readIndex_
198  <<endl;
199  unlock();
200 }
tuple cout
Definition: gather_cfg.py:121
void PlaybackRawDataProvider::setFreeToEof ( )

Definition at line 202 of file PlaybackRawDataProvider.cc.

References freeToEof_, and postWriteSem().

Referenced by evf::BU::generateEvent(), evf::BU::halting(), and evf::BU::stopping().

203 {
204  // cout << " PlaybackRawDataProvider::setFreeToEof()" << endl;
205  freeToEof_ = true;
206  // cout << " PlaybackRawDataProvider::setFreeToEof() call postReadSem" << endl;
207  postWriteSem();
208 }
void PlaybackRawDataProvider::unlock ( void  )
inlineprivate

Definition at line 45 of file PlaybackRawDataProvider.h.

References lock_.

Referenced by analyze(), getFEDRawData(), sem_print(), and ~PlaybackRawDataProvider().

45 { sem_post(&lock_); }
void PlaybackRawDataProvider::waitReadSem ( )
inlineprivate

Definition at line 48 of file PlaybackRawDataProvider.h.

References readSem_.

Referenced by getFEDRawData().

48 { sem_wait(&readSem_);}
void PlaybackRawDataProvider::waitWriteSem ( )
inlineprivate

Definition at line 46 of file PlaybackRawDataProvider.h.

References writeSem_.

Referenced by analyze().

46 { sem_wait(&writeSem_); }

Member Data Documentation

unsigned int PlaybackRawDataProvider::count_
private

Definition at line 63 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and endJob().

bool PlaybackRawDataProvider::destroying_
private

Definition at line 72 of file PlaybackRawDataProvider.h.

Referenced by getFEDRawData(), and ~PlaybackRawDataProvider().

FEDRawDataCollection** PlaybackRawDataProvider::eventQueue_
private
unsigned int* PlaybackRawDataProvider::evtNumber_
private
bool PlaybackRawDataProvider::filesClosed_
private

Definition at line 71 of file PlaybackRawDataProvider.h.

Referenced by areFilesClosed(), and respondToCloseInputFile().

bool PlaybackRawDataProvider::freeToEof_
private

Definition at line 70 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and setFreeToEof().

PlaybackRawDataProvider * PlaybackRawDataProvider::instance_ =0
staticprivate
sem_t PlaybackRawDataProvider::lock_
private
unsigned int PlaybackRawDataProvider::queueSize_
private
unsigned int PlaybackRawDataProvider::readIndex_
private

Definition at line 69 of file PlaybackRawDataProvider.h.

Referenced by getFEDRawData(), and sem_print().

sem_t PlaybackRawDataProvider::readSem_
private
unsigned int* PlaybackRawDataProvider::runNumber_
private
unsigned int PlaybackRawDataProvider::writeIndex_
private

Definition at line 68 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and sem_print().

sem_t PlaybackRawDataProvider::writeSem_
private