CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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

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
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex >
const & 
esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
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 wantsInputProcessBlocks ()
 
static bool wantsProcessBlocks ()
 
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_ = nullptr
 

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)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 13 of file PlaybackRawDataProvider.h.

Constructor & Destructor Documentation

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

Definition at line 30 of file PlaybackRawDataProvider.cc.

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

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

Definition at line 55 of file PlaybackRawDataProvider.cc.

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

55  {
56  if (nullptr != runNumber_)
57  delete[] runNumber_;
58  if (nullptr != evtNumber_)
59  delete[] evtNumber_;
60  if (nullptr != eventQueue_) {
61  for (unsigned int i = 0; i < queueSize_; i++)
62  if (nullptr != eventQueue_[i])
63  delete eventQueue_[i];
64  delete[] eventQueue_;
65  }
66  edm::LogInfo("PbImpl") << "Destroyed Concrete RawData Provider 0x" << hex << (unsigned long)this << dec << endl;
67  instance_ = nullptr;
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_
static PlaybackRawDataProvider * instance_
Log< level::Info, false > LogInfo

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 84 of file PlaybackRawDataProvider.cc.

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

84  {
85  if (freeToEof_)
86  return;
87  waitWriteSem();
88  if (freeToEof_)
89  return;
90  runNumber_[writeIndex_] = iEvent.id().run();
91  evtNumber_[writeIndex_] = iEvent.id().event();
92 
94  iEvent.getByLabel("rawDataCollector", pRawData);
95 
96  if (!pRawData.isValid()) {
97  edm::LogError("InvalidHandle") << "no raw data found!" << endl;
98  return;
99  }
100 
101  // copy the raw data collection into rawData_, retrievable via getFEDRawData()
102  assert(nullptr == eventQueue_[writeIndex_]);
104  for (unsigned int i = 0; i < (unsigned int)FEDNumbering::MAXFEDID + 1; i++) {
105  unsigned int fedSize = pRawData->FEDData(i).size();
106  if (fedSize > 0) {
108  fedData.resize(fedSize);
109  memcpy(fedData.data(), pRawData->FEDData(i).data(), fedSize);
110  }
111  }
112 
113  lock();
115  count_++;
116  unlock();
117 
118  postReadSem();
119 
120  return;
121 }
RunNumber_t run() const
Definition: EventID.h:38
FEDRawDataCollection ** eventQueue_
EventNumber_t event() const
Definition: EventID.h:40
Log< level::Error, false > LogError
assert(be >=bs)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
Definition: FEDRawData.cc:28
bool isValid() const
Definition: HandleBase.h:70
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
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:24
bool PlaybackRawDataProvider::areFilesClosed ( )

Definition at line 188 of file PlaybackRawDataProvider.cc.

References filesClosed_.

void PlaybackRawDataProvider::beginJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 124 of file PlaybackRawDataProvider.cc.

124 {}
void PlaybackRawDataProvider::endJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 127 of file PlaybackRawDataProvider.cc.

References count_.

127 { edm::LogInfo("Summary") << count_ << " events read." << endl; }
Log< level::Info, false > LogInfo
FEDRawDataCollection * PlaybackRawDataProvider::getFEDRawData ( )
virtual

Definition at line 133 of file PlaybackRawDataProvider.cc.

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

133  {
134  FEDRawDataCollection* result = nullptr;
135  waitReadSem();
136  //do not read data if destructor is called
137  if (destroying_)
138  return nullptr;
139  lock();
140  result = eventQueue_[readIndex_];
141  eventQueue_[readIndex_] = nullptr;
142  readIndex_ = (readIndex_ + 1) % queueSize_;
143  unlock();
144 
145  postWriteSem();
146  return result;
147 }
FEDRawDataCollection ** eventQueue_
tuple result
Definition: mps_fire.py:311
FEDRawDataCollection * PlaybackRawDataProvider::getFEDRawData ( unsigned int &  runNumber,
unsigned int &  evtNumber 
)
virtual

Definition at line 150 of file PlaybackRawDataProvider.cc.

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

150  {
151  FEDRawDataCollection* result = nullptr;
152  waitReadSem();
153  //do not read data if destructor is called
154  if (destroying_)
155  return nullptr;
156  lock();
158  evtNumber = evtNumber_[readIndex_];
159  result = eventQueue_[readIndex_];
160  // assert(0!=result);
161  eventQueue_[readIndex_] = nullptr;
162  readIndex_ = (readIndex_ + 1) % queueSize_;
163 
164  unlock();
165 
166  postWriteSem();
167  return result;
168 }
FEDRawDataCollection ** eventQueue_
tuple result
Definition: mps_fire.py:311
PlaybackRawDataProvider * PlaybackRawDataProvider::instance ( )
inlinestatic

Definition at line 74 of file PlaybackRawDataProvider.h.

References instance_.

74 { return instance_; }
static PlaybackRawDataProvider * instance_
void PlaybackRawDataProvider::lock ( )
inlineprivate

Definition at line 40 of file PlaybackRawDataProvider.h.

References lock_.

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

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

Definition at line 45 of file PlaybackRawDataProvider.h.

References readSem_.

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

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

Definition at line 43 of file PlaybackRawDataProvider.h.

References writeSem_.

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

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

Reimplemented from edm::EDAnalyzer.

Definition at line 130 of file PlaybackRawDataProvider.cc.

References filesClosed_.

void PlaybackRawDataProvider::sem_print ( )
private

Definition at line 171 of file PlaybackRawDataProvider.cc.

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

171  {
172  lock();
173  int wsem, rsem;
174  sem_getvalue(&writeSem_, &wsem);
175  sem_getvalue(&readSem_, &rsem);
176  cout << "sem_print():"
177  << " wsem=" << wsem << " rsem=" << rsem << " writeIndex=" << writeIndex_ << " readIndex=" << readIndex_ << endl;
178  unlock();
179 }
tuple cout
Definition: gather_cfg.py:144
void PlaybackRawDataProvider::setFreeToEof ( )

Definition at line 181 of file PlaybackRawDataProvider.cc.

References freeToEof_, and postWriteSem().

181  {
182  // cout << " PlaybackRawDataProvider::setFreeToEof()" << endl;
183  freeToEof_ = true;
184  // cout << " PlaybackRawDataProvider::setFreeToEof() call postReadSem" << endl;
185  postWriteSem();
186 }
void PlaybackRawDataProvider::unlock ( )
inlineprivate

Definition at line 41 of file PlaybackRawDataProvider.h.

References lock_.

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

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

Definition at line 44 of file PlaybackRawDataProvider.h.

References readSem_.

Referenced by getFEDRawData().

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

Definition at line 42 of file PlaybackRawDataProvider.h.

References writeSem_.

Referenced by analyze().

42 { sem_wait(&writeSem_); }

Member Data Documentation

unsigned int PlaybackRawDataProvider::count_
private

Definition at line 57 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and endJob().

bool PlaybackRawDataProvider::destroying_
private

Definition at line 66 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 65 of file PlaybackRawDataProvider.h.

Referenced by areFilesClosed(), and respondToCloseInputFile().

bool PlaybackRawDataProvider::freeToEof_
private

Definition at line 64 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and setFreeToEof().

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

Definition at line 63 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 62 of file PlaybackRawDataProvider.h.

Referenced by analyze(), and sem_print().

sem_t PlaybackRawDataProvider::writeSem_
private