CMS 3D CMS Logo

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

void analyze (const edm::Event &, const edm::EventSetup &) override
 
bool areFilesClosed ()
 
void beginJob () override
 
void endJob () override
 
virtual FEDRawDataCollectiongetFEDRawData ()
 
virtual FEDRawDataCollectiongetFEDRawData (unsigned int &runNumber, unsigned int &evtNumber)
 
 PlaybackRawDataProvider (const edm::ParameterSet &)
 
void respondToCloseInputFile (edm::FileBlock const &fb) override
 
void setFreeToEof ()
 
 ~PlaybackRawDataProvider () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

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 &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 

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
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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 32 of file PlaybackRawDataProvider.cc.

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

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

Definition at line 58 of file PlaybackRawDataProvider.cc.

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

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

Member Function Documentation

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

Definition at line 86 of file PlaybackRawDataProvider.cc.

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

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

Definition at line 211 of file PlaybackRawDataProvider.cc.

References filesClosed_.

212 {
213  return filesClosed_;
214 }
void PlaybackRawDataProvider::beginJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 128 of file PlaybackRawDataProvider.cc.

129 {
130 
131 }
void PlaybackRawDataProvider::endJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 134 of file PlaybackRawDataProvider.cc.

References count_.

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

Definition at line 146 of file PlaybackRawDataProvider.cc.

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

147 {
148  FEDRawDataCollection* result = nullptr;
149  waitReadSem();
150  //do not read data if destructor is called
151  if (destroying_) return nullptr;
152  lock();
153  result = eventQueue_[readIndex_];
154  eventQueue_[readIndex_]=nullptr;
156  unlock();
157 
158  postWriteSem();
159  return result;
160 }
FEDRawDataCollection ** eventQueue_
FEDRawDataCollection * PlaybackRawDataProvider::getFEDRawData ( unsigned int &  runNumber,
unsigned int &  evtNumber 
)
virtual

Definition at line 164 of file PlaybackRawDataProvider.cc.

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

166 {
167 
168  FEDRawDataCollection* result = nullptr;
169  waitReadSem();
170  //do not read data if destructor is called
171  if (destroying_) return nullptr;
172  lock();
174  evtNumber=evtNumber_[readIndex_];
175  result=eventQueue_[readIndex_];
176  // assert(0!=result);
177  eventQueue_[readIndex_]=nullptr;
179 
180  unlock();
181 
182  postWriteSem();
183  return result;
184 }
FEDRawDataCollection ** eventQueue_
PlaybackRawDataProvider * PlaybackRawDataProvider::instance ( )
inlinestatic

Definition at line 82 of file PlaybackRawDataProvider.h.

References instance_.

83 {
84  return instance_;
85 }
static PlaybackRawDataProvider * instance_
void PlaybackRawDataProvider::lock ( )
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_, and sem_print().

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)
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 140 of file PlaybackRawDataProvider.cc.

References filesClosed_.

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

Definition at line 188 of file PlaybackRawDataProvider.cc.

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

Referenced by postReadSem().

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

Definition at line 203 of file PlaybackRawDataProvider.cc.

References freeToEof_, and postWriteSem().

204 {
205  // cout << " PlaybackRawDataProvider::setFreeToEof()" << endl;
206  freeToEof_ = true;
207  // cout << " PlaybackRawDataProvider::setFreeToEof() call postReadSem" << endl;
208  postWriteSem();
209 }
void PlaybackRawDataProvider::unlock ( )
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