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 
16 using namespace std;
17 using namespace edm;
18 
20 // initialize static data members
22 
24 
25 
27 // construction/destruction
29 
30 //______________________________________________________________________________
32  : queueSize_(0)
33  , eventQueue_(0)
34  , runNumber_(0)
35  , evtNumber_(0)
36  , count_(0)
37  , writeIndex_(0)
38  , readIndex_(0)
39  , freeToEof_(false)
40  , filesClosed_(false)
41  , destroying_(false)
42 {
43  queueSize_=iConfig.getUntrackedParameter<unsigned int>("queueSize",32);
44  sem_init(&lock_,0,1);
45  sem_init(&writeSem_,0,queueSize_);
46  sem_init(&readSem_,0,0);
47  runNumber_ =new unsigned int[queueSize_];
48  evtNumber_ =new unsigned int[queueSize_];
50  for (unsigned int i=0;i<queueSize_;i++) eventQueue_[i]=0;
51  edm::LogInfo("PbImpl") << "Created Concrete RawData Provider 0x"<< hex << (unsigned long) this << dec << endl;
52  instance_=this;
53 }
54 
55 
56 //______________________________________________________________________________
58 {
59  if (0!=runNumber_) delete [] runNumber_;
60  if (0!=evtNumber_) delete [] evtNumber_;
61  if (0!=eventQueue_) {
62  for (unsigned int i=0;i<queueSize_;i++)
63  if (0!=eventQueue_[i]) delete eventQueue_[i];
64  delete [] eventQueue_;
65  }
66  edm::LogInfo("PbImpl") << "Destroyed Concrete RawData Provider 0x"<< hex << (unsigned long) this << dec << endl;
67  instance_=0;
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 
79 
81 // implementation of member functions
83 
84 //______________________________________________________________________________
86  const EventSetup& iSetup)
87 {
88  if(freeToEof_) return;
89  waitWriteSem();
90  if(freeToEof_) return;
91  runNumber_[writeIndex_]=iEvent.id().run();
92  evtNumber_[writeIndex_]=iEvent.id().event();
93 
95  iEvent.getByLabel("rawDataCollector", pRawData);
96 
97  if (!pRawData.isValid()) {
98  edm::LogError("InvalidHandle")<<"no raw data found!"<<endl;
99  return;
100  }
101 
102 
103  // copy the raw data collection into rawData_, retrievable via getFEDRawData()
104  assert(0==eventQueue_[writeIndex_]);
106  for (unsigned int i=0;i<(unsigned int)FEDNumbering::MAXFEDID+1;i++) {
107  unsigned int fedSize=pRawData->FEDData(i).size();
108  if (fedSize>0) {
110  fedData.resize(fedSize);
111  memcpy(fedData.data(),pRawData->FEDData(i).data(),fedSize);
112  }
113  }
114 
115  lock();
116  writeIndex_=(writeIndex_+1)%queueSize_;
117  count_++;
118  unlock();
119 
120  postReadSem();
121 
122  return;
123 }
124 
125 
126 //______________________________________________________________________________
128 {
129 
130 }
131 
132 //______________________________________________________________________________
134 {
135  edm::LogInfo("Summary")<<count_<<" events read."<<endl;
136 }
137 
138 //______________________________________________________________________________
140 {
141  filesClosed_ = true;
142 }
143 
144 //______________________________________________________________________________
146 {
148  waitReadSem();
149  //do not read data if destructor is called
150  if (destroying_) return 0;
151  lock();
152  result = eventQueue_[readIndex_];
155  unlock();
156 
157  postWriteSem();
158  return result;
159 }
160 
161 
162 //______________________________________________________________________________
164  unsigned int& evtNumber)
165 {
166 
168  waitReadSem();
169  //do not read data if destructor is called
170  if (destroying_) return 0;
171  lock();
172  runNumber=runNumber_[readIndex_];
173  evtNumber=evtNumber_[readIndex_];
174  result=eventQueue_[readIndex_];
175  // assert(0!=result);
178 
179  unlock();
180 
181  postWriteSem();
182  return result;
183 }
184 
185 
186 //______________________________________________________________________________
188 {
189  lock();
190  int wsem,rsem;
191  sem_getvalue(&writeSem_,&wsem);
192  sem_getvalue(&readSem_,&rsem);
193  cout<<"sem_print():"
194  <<" wsem="<<wsem
195  <<" rsem="<<rsem
196  <<" writeIndex="<<writeIndex_
197  <<" readIndex="<<readIndex_
198  <<endl;
199  unlock();
200 }
201 
203 {
204  // cout << " PlaybackRawDataProvider::setFreeToEof()" << endl;
205  freeToEof_ = true;
206  // cout << " PlaybackRawDataProvider::setFreeToEof() call postReadSem" << endl;
207  postWriteSem();
208 }
209 
211 {
212  return filesClosed_;
213 }
215 // framework module implementation macro
217 
RunNumber_t run() const
Definition: EventID.h:42
static const char runNumber_[]
FEDRawDataCollection ** eventQueue_
EventNumber_t event() const
Definition: EventID.h:44
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:243
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
static PlaybackRawDataProvider * instance_
void resize(size_t newsize)
Definition: FEDRawData.cc:33
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:361
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:29
tuple cout
Definition: gather_cfg.py:121