CMS 3D CMS Logo

PlaybackRawDataProvider.cc
Go to the documentation of this file.
1 //
3 // PlaybackRawDataProvider
4 // -----------------------
5 //
6 // 21/09/2006 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
8 
13 #include <cstring>
14 #include <iostream>
15 
16 using namespace std;
17 using namespace edm;
18 
20 // initialize static data members
22 
24 
26 // construction/destruction
28 
29 //______________________________________________________________________________
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 }
53 
54 //______________________________________________________________________________
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 }
78 
80 // implementation of member functions
82 
83 //______________________________________________________________________________
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 }
122 
123 //______________________________________________________________________________
125 
126 //______________________________________________________________________________
127 void PlaybackRawDataProvider::endJob() { edm::LogInfo("Summary") << count_ << " events read." << endl; }
128 
129 //______________________________________________________________________________
131 
132 //______________________________________________________________________________
134  FEDRawDataCollection* result = nullptr;
135  waitReadSem();
136  //do not read data if destructor is called
137  if (destroying_)
138  return nullptr;
139  lock();
141  eventQueue_[readIndex_] = nullptr;
142  readIndex_ = (readIndex_ + 1) % queueSize_;
143  unlock();
144 
145  postWriteSem();
146  return result;
147 }
148 
149 //______________________________________________________________________________
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_];
160  // assert(0!=result);
161  eventQueue_[readIndex_] = nullptr;
162  readIndex_ = (readIndex_ + 1) % queueSize_;
163 
164  unlock();
165 
166  postWriteSem();
167  return result;
168 }
169 
170 //______________________________________________________________________________
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 }
180 
182  // cout << " PlaybackRawDataProvider::setFreeToEof()" << endl;
183  freeToEof_ = true;
184  // cout << " PlaybackRawDataProvider::setFreeToEof() call postReadSem" << endl;
185  postWriteSem();
186 }
187 
190 // framework module implementation macro
FEDNumbering.h
PlaybackRawDataProvider::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: PlaybackRawDataProvider.cc:84
PlaybackRawDataProvider::beginJob
void beginJob() override
Definition: PlaybackRawDataProvider.cc:124
PlaybackRawDataProvider::PlaybackRawDataProvider
PlaybackRawDataProvider(const edm::ParameterSet &)
Definition: PlaybackRawDataProvider.cc:30
PlaybackRawDataProvider::writeIndex_
unsigned int writeIndex_
Definition: PlaybackRawDataProvider.h:62
mps_fire.i
i
Definition: mps_fire.py:428
PlaybackRawDataProvider::waitReadSem
void waitReadSem()
Definition: PlaybackRawDataProvider.h:44
PlaybackRawDataProvider::getFEDRawData
virtual FEDRawDataCollection * getFEDRawData()
Definition: PlaybackRawDataProvider.cc:133
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
PlaybackRawDataProvider::areFilesClosed
bool areFilesClosed()
Definition: PlaybackRawDataProvider.cc:188
PlaybackRawDataProvider::endJob
void endJob() override
Definition: PlaybackRawDataProvider.cc:127
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
PlaybackRawDataProvider::queueSize_
unsigned int queueSize_
Definition: PlaybackRawDataProvider.h:53
gather_cfg.cout
cout
Definition: gather_cfg.py:144
PlaybackRawDataProvider::count_
unsigned int count_
Definition: PlaybackRawDataProvider.h:57
cms::cuda::assert
assert(be >=bs)
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
PlaybackRawDataProvider::postReadSem
void postReadSem()
Definition: PlaybackRawDataProvider.h:45
PlaybackRawDataProvider::destroying_
bool destroying_
Definition: PlaybackRawDataProvider.h:66
FEDRawData
Definition: FEDRawData.h:19
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
edm::FileBlock
Definition: FileBlock.h:20
PlaybackRawDataProvider::lock
void lock()
Definition: PlaybackRawDataProvider.h:40
PlaybackRawDataProvider::readSem_
sem_t readSem_
Definition: PlaybackRawDataProvider.h:61
PlaybackRawDataProvider::lock_
sem_t lock_
Definition: PlaybackRawDataProvider.h:59
PlaybackRawDataProvider::unlock
void unlock()
Definition: PlaybackRawDataProvider.h:41
EcalFEDMonitor_cfi.FEDRawDataCollection
FEDRawDataCollection
Definition: EcalFEDMonitor_cfi.py:6
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
PlaybackRawDataProvider::instance_
static PlaybackRawDataProvider * instance_
Definition: PlaybackRawDataProvider.h:36
PlaybackRawDataProvider::respondToCloseInputFile
void respondToCloseInputFile(edm::FileBlock const &fb) override
Definition: PlaybackRawDataProvider.cc:130
PlaybackRawDataProvider::setFreeToEof
void setFreeToEof()
Definition: PlaybackRawDataProvider.cc:181
PlaybackRawDataProvider::postWriteSem
void postWriteSem()
Definition: PlaybackRawDataProvider.h:43
PlaybackRawDataProvider::freeToEof_
bool freeToEof_
Definition: PlaybackRawDataProvider.h:64
edm::ParameterSet
Definition: ParameterSet.h:47
PlaybackRawDataProvider.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
FEDRawDataCollection.h
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
PlaybackRawDataProvider::runNumber_
unsigned int * runNumber_
Definition: PlaybackRawDataProvider.h:55
std
Definition: JetResolutionObject.h:76
PlaybackRawDataProvider::~PlaybackRawDataProvider
~PlaybackRawDataProvider() override
Definition: PlaybackRawDataProvider.cc:55
PlaybackRawDataProvider::filesClosed_
bool filesClosed_
Definition: PlaybackRawDataProvider.h:65
FEDRawData::resize
void resize(size_t newsize)
Definition: FEDRawData.cc:28
PlaybackRawDataProvider::sem_print
void sem_print()
Definition: PlaybackRawDataProvider.cc:171
mps_fire.result
result
Definition: mps_fire.py:311
PlaybackRawDataProvider::readIndex_
unsigned int readIndex_
Definition: PlaybackRawDataProvider.h:63
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
PlaybackRawDataProvider::waitWriteSem
void waitWriteSem()
Definition: PlaybackRawDataProvider.h:42
edm::Event
Definition: Event.h:73
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
PlaybackRawDataProvider::writeSem_
sem_t writeSem_
Definition: PlaybackRawDataProvider.h:60
sistrip::runNumber_
static const char runNumber_[]
Definition: ConstantsForDqm.h:33
benchmark_cfg.fb
fb
Definition: benchmark_cfg.py:14
PlaybackRawDataProvider::evtNumber_
unsigned int * evtNumber_
Definition: PlaybackRawDataProvider.h:56
PlaybackRawDataProvider::eventQueue_
FEDRawDataCollection ** eventQueue_
Definition: PlaybackRawDataProvider.h:54
FEDNumbering::MAXFEDID
Definition: FEDNumbering.h:26
PlaybackRawDataProvider
Definition: PlaybackRawDataProvider.h:13