CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
9 
14 #include <cstring>
15 #include <iostream>
16 
17 using namespace std;
18 using namespace edm;
19 
21 // initialize static data members
23 
25 
26 
28 // construction/destruction
30 
31 //______________________________________________________________________________
33  : queueSize_(0)
34  , eventQueue_(0)
35  , runNumber_(0)
36  , evtNumber_(0)
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]=0;
52  edm::LogInfo("PbImpl") << "Created Concrete RawData Provider 0x"<< hex << (unsigned long) this << dec << endl;
53  instance_=this;
54 }
55 
56 
57 //______________________________________________________________________________
59 {
60  if (0!=runNumber_) delete [] runNumber_;
61  if (0!=evtNumber_) delete [] evtNumber_;
62  if (0!=eventQueue_) {
63  for (unsigned int i=0;i<queueSize_;i++)
64  if (0!=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_=0;
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 }
79 
80 
82 // implementation of member functions
84 
85 //______________________________________________________________________________
87  const EventSetup& iSetup)
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(0==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();
117  writeIndex_=(writeIndex_+1)%queueSize_;
118  count_++;
119  unlock();
120 
121  postReadSem();
122 
123  return;
124 }
125 
126 
127 //______________________________________________________________________________
129 {
130 
131 }
132 
133 //______________________________________________________________________________
135 {
136  edm::LogInfo("Summary")<<count_<<" events read."<<endl;
137 }
138 
139 //______________________________________________________________________________
141 {
142  filesClosed_ = true;
143 }
144 
145 //______________________________________________________________________________
147 {
149  waitReadSem();
150  //do not read data if destructor is called
151  if (destroying_) return 0;
152  lock();
153  result = eventQueue_[readIndex_];
156  unlock();
157 
158  postWriteSem();
159  return result;
160 }
161 
162 
163 //______________________________________________________________________________
165  unsigned int& evtNumber)
166 {
167 
169  waitReadSem();
170  //do not read data if destructor is called
171  if (destroying_) return 0;
172  lock();
173  runNumber=runNumber_[readIndex_];
174  evtNumber=evtNumber_[readIndex_];
175  result=eventQueue_[readIndex_];
176  // assert(0!=result);
179 
180  unlock();
181 
182  postWriteSem();
183  return result;
184 }
185 
186 
187 //______________________________________________________________________________
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 }
202 
204 {
205  // cout << " PlaybackRawDataProvider::setFreeToEof()" << endl;
206  freeToEof_ = true;
207  // cout << " PlaybackRawDataProvider::setFreeToEof() call postReadSem" << endl;
208  postWriteSem();
209 }
210 
212 {
213  return filesClosed_;
214 }
216 // framework module implementation macro
218 
RunNumber_t run() const
Definition: EventID.h:39
static const char runNumber_[]
FEDRawDataCollection ** eventQueue_
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
PlaybackRawDataProvider(const edm::ParameterSet &)
virtual FEDRawDataCollection * getFEDRawData()
int iEvent
Definition: GenABIO.cc:230
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
static PlaybackRawDataProvider * instance_
void resize(size_t newsize)
Definition: FEDRawData.cc:32
tuple result
Definition: query.py:137
virtual void respondToCloseInputFile(edm::FileBlock const &fb)
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
virtual void analyze(const edm::Event &, const edm::EventSetup &)
edm::EventID id() const
Definition: EventBase.h:56
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false