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 &)
virtual void beginJob ()
virtual void endJob ()
virtual FEDRawDataCollectiongetFEDRawData (unsigned int &runNumber, unsigned int &evtNumber)
virtual FEDRawDataCollectiongetFEDRawData ()
 PlaybackRawDataProvider (const edm::ParameterSet &)
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_
FEDRawDataCollection ** eventQueue_
unsigned int * evtNumber_
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)
{
  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 55 of file PlaybackRawDataProvider.cc.

References eventQueue_, evtNumber_, i, instance_, queueSize_, and runNumber_.

{
  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;
}

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 74 of file PlaybackRawDataProvider.cc.

References count_, FEDRawData::data(), edm::EventID::event(), eventQueue_, evtNumber_, FEDRawDataCollection::FEDData(), ExpressReco_HICollisions_FallBack::FEDRawDataCollection, freeToEof_, edm::Event::getByType(), 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.getByType(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;
}
void PlaybackRawDataProvider::beginJob ( void  ) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 116 of file PlaybackRawDataProvider.cc.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 123 of file PlaybackRawDataProvider.cc.

References count_.

{
  edm::LogInfo("Summary")<<count_<<" events read."<<endl;
}
FEDRawDataCollection * PlaybackRawDataProvider::getFEDRawData ( ) [virtual]
FEDRawDataCollection * PlaybackRawDataProvider::getFEDRawData ( unsigned int &  runNumber,
unsigned int &  evtNumber 
) [virtual]
PlaybackRawDataProvider * PlaybackRawDataProvider::instance ( void  ) [inline, static]
void PlaybackRawDataProvider::lock ( void  ) [inline, private]

Definition at line 42 of file PlaybackRawDataProvider.h.

References lock_.

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

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

Definition at line 47 of file PlaybackRawDataProvider.h.

References readSem_.

Referenced by analyze().

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

Definition at line 45 of file PlaybackRawDataProvider.h.

References writeSem_.

Referenced by getFEDRawData(), and setFreeToEof().

{ sem_post(&writeSem_); }
void PlaybackRawDataProvider::sem_print ( ) [private]

Definition at line 168 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 183 of file PlaybackRawDataProvider.cc.

References freeToEof_, and postWriteSem().

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

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

Definition at line 43 of file PlaybackRawDataProvider.h.

References lock_.

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

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

Definition at line 46 of file PlaybackRawDataProvider.h.

References readSem_.

Referenced by getFEDRawData().

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

Definition at line 44 of file PlaybackRawDataProvider.h.

References writeSem_.

Referenced by analyze().

{ sem_wait(&writeSem_); }

Member Data Documentation

unsigned int PlaybackRawDataProvider::count_ [private]

Definition at line 61 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and endJob().

unsigned int* PlaybackRawDataProvider::evtNumber_ [private]

Definition at line 68 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and setFreeToEof().

Definition at line 63 of file PlaybackRawDataProvider.h.

Referenced by lock(), PlaybackRawDataProvider(), and unlock().

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

Definition at line 67 of file PlaybackRawDataProvider.h.

Referenced by getFEDRawData(), and sem_print().

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

Definition at line 66 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and sem_print().