CMS 3D CMS Logo

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

List of all members.

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
bool areFilesClosed ()
virtual void beginJob ()
virtual void endJob ()
virtual FEDRawDataCollectiongetFEDRawData (unsigned int &runNumber, unsigned int &evtNumber)
virtual FEDRawDataCollectiongetFEDRawData ()
 PlaybackRawDataProvider (const edm::ParameterSet &)
virtual void respondToCloseInputFile (edm::FileBlock const &fb)
void setFreeToEof ()
virtual ~PlaybackRawDataProvider ()

Static Public Member Functions

static PlaybackRawDataProviderinstance ()

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

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_.

  : queueSize_(0)
  , eventQueue_(0)
  , runNumber_(0)
  , evtNumber_(0)
  , count_(0)
  , writeIndex_(0)
  , readIndex_(0)
  , freeToEof_(false)
  , filesClosed_(false)
  , destroying_(false)
{
  queueSize_=iConfig.getUntrackedParameter<unsigned int>("queueSize",32);
  sem_init(&lock_,0,1);
  sem_init(&writeSem_,0,queueSize_);
  sem_init(&readSem_,0,0);
  runNumber_ =new unsigned int[queueSize_];
  evtNumber_ =new unsigned int[queueSize_];
  eventQueue_=new FEDRawDataCollection*[queueSize_];
  for (unsigned int i=0;i<queueSize_;i++) eventQueue_[i]=0;
  edm::LogInfo("PbImpl") << "Created Concrete RawData Provider 0x"<< hex << (unsigned long) this << dec << endl;
  instance_=this;
}
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_.

{
  if (0!=runNumber_) delete [] runNumber_;
  if (0!=evtNumber_) delete [] evtNumber_;
  if (0!=eventQueue_) {
    for (unsigned int i=0;i<queueSize_;i++)
      if (0!=eventQueue_[i]) delete eventQueue_[i];
    delete [] eventQueue_;
  }
  edm::LogInfo("PbImpl") << "Destroyed Concrete RawData Provider 0x"<< hex << (unsigned long) this << dec << endl;
  instance_=0;

  destroying_=true;
  postReadSem();
  postWriteSem();
  unlock(); 
  sem_destroy(&lock_);
  sem_destroy(&writeSem_);
  sem_destroy(&readSem_);
  usleep(10000);
}

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_.

{
  if(freeToEof_) return;
  waitWriteSem();
  if(freeToEof_) return;
  runNumber_[writeIndex_]=iEvent.id().run();
  evtNumber_[writeIndex_]=iEvent.id().event();

  Handle<FEDRawDataCollection> pRawData;
  iEvent.getByLabel("rawDataCollector", pRawData);
  
  if (!pRawData.isValid()) {
    edm::LogError("InvalidHandle")<<"no raw data found!"<<endl;
    return;
  }
  
  
  // copy the raw data collection into rawData_, retrievable via getFEDRawData()
  assert(0==eventQueue_[writeIndex_]);
  eventQueue_[writeIndex_]=new FEDRawDataCollection();
  for (unsigned int i=0;i<(unsigned int)FEDNumbering::MAXFEDID+1;i++) {
    unsigned int fedSize=pRawData->FEDData(i).size();
    if (fedSize>0) {
      FEDRawData& fedData=eventQueue_[writeIndex_]->FEDData(i);
      fedData.resize(fedSize);
      memcpy(fedData.data(),pRawData->FEDData(i).data(),fedSize);
    }
  }
  
  lock();
  writeIndex_=(writeIndex_+1)%queueSize_;
  count_++;
  unlock();
  
  postReadSem();

  return;
}
bool PlaybackRawDataProvider::areFilesClosed ( )

Definition at line 210 of file PlaybackRawDataProvider.cc.

References filesClosed_.

{
  return filesClosed_;
}
void PlaybackRawDataProvider::beginJob ( void  ) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 127 of file PlaybackRawDataProvider.cc.

{
  
}
void PlaybackRawDataProvider::endJob ( void  ) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 133 of file PlaybackRawDataProvider.cc.

References count_.

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

Definition at line 145 of file PlaybackRawDataProvider.cc.

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

{
  FEDRawDataCollection* result = 0;
  waitReadSem();
  //do not read data if destructor is called
  if (destroying_) return 0;
  lock();
  result = eventQueue_[readIndex_];
  eventQueue_[readIndex_]=0;
  readIndex_=(readIndex_+1)%queueSize_;
  unlock();
  
  postWriteSem();
  return result;
}
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().

{

  FEDRawDataCollection* result = 0;
  waitReadSem();
  //do not read data if destructor is called
  if (destroying_) return 0;
  lock();
  runNumber=runNumber_[readIndex_];
  evtNumber=evtNumber_[readIndex_];
  result=eventQueue_[readIndex_];
  //  assert(0!=result);
  eventQueue_[readIndex_]=0;
  readIndex_=(readIndex_+1)%queueSize_;

  unlock();
  
  postWriteSem();
  return result;
}
PlaybackRawDataProvider * PlaybackRawDataProvider::instance ( ) [inline, static]
void PlaybackRawDataProvider::lock ( void  ) [inline, private]

Definition at line 44 of file PlaybackRawDataProvider.h.

References lock_.

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

{ sem_wait(&lock_); }
void PlaybackRawDataProvider::postReadSem ( ) [inline, private]

Definition at line 49 of file PlaybackRawDataProvider.h.

References readSem_.

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

{ sem_post(&readSem_); }
void PlaybackRawDataProvider::postWriteSem ( ) [inline, private]

Definition at line 47 of file PlaybackRawDataProvider.h.

References writeSem_.

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

{ 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_.

{
  filesClosed_ = true;
}
void PlaybackRawDataProvider::sem_print ( ) [private]

Definition at line 187 of file PlaybackRawDataProvider.cc.

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

{
  lock();
  int wsem,rsem;
  sem_getvalue(&writeSem_,&wsem);
  sem_getvalue(&readSem_,&rsem);
  cout<<"sem_print():"
      <<" wsem="<<wsem
      <<" rsem="<<rsem
      <<" writeIndex="<<writeIndex_
      <<" readIndex="<<readIndex_
      <<endl;
  unlock();
}
void PlaybackRawDataProvider::setFreeToEof ( )

Definition at line 202 of file PlaybackRawDataProvider.cc.

References freeToEof_, and postWriteSem().

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

{ 
  //  cout << "  PlaybackRawDataProvider::setFreeToEof()" << endl;
  freeToEof_ = true; 
  //  cout << "  PlaybackRawDataProvider::setFreeToEof() call postReadSem" << endl;  
  postWriteSem(); 
}
void PlaybackRawDataProvider::unlock ( void  ) [inline, private]

Definition at line 45 of file PlaybackRawDataProvider.h.

References lock_.

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

{ sem_post(&lock_); }
void PlaybackRawDataProvider::waitReadSem ( ) [inline, private]

Definition at line 48 of file PlaybackRawDataProvider.h.

References readSem_.

Referenced by getFEDRawData().

{ sem_wait(&readSem_);}
void PlaybackRawDataProvider::waitWriteSem ( ) [inline, private]

Definition at line 46 of file PlaybackRawDataProvider.h.

References writeSem_.

Referenced by analyze().

{ sem_wait(&writeSem_); }

Member Data Documentation

unsigned int PlaybackRawDataProvider::count_ [private]

Definition at line 63 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and endJob().

Definition at line 72 of file PlaybackRawDataProvider.h.

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

unsigned int* PlaybackRawDataProvider::evtNumber_ [private]

Definition at line 71 of file PlaybackRawDataProvider.h.

Referenced by areFilesClosed(), and respondToCloseInputFile().

Definition at line 70 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and setFreeToEof().

unsigned int PlaybackRawDataProvider::queueSize_ [private]
unsigned int PlaybackRawDataProvider::readIndex_ [private]

Definition at line 69 of file PlaybackRawDataProvider.h.

Referenced by getFEDRawData(), and sem_print().

unsigned int* PlaybackRawDataProvider::runNumber_ [private]
unsigned int PlaybackRawDataProvider::writeIndex_ [private]

Definition at line 68 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and sem_print().