Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00008
00009
00010 #include "EventFilter/Playback/interface/PlaybackRawDataProvider.h"
00011 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00014 #include <cstring>
00015
00016 using namespace std;
00017 using namespace edm;
00018
00020
00022
00023 PlaybackRawDataProvider* PlaybackRawDataProvider::instance_=0;
00024
00025
00027
00029
00030
00031 PlaybackRawDataProvider::PlaybackRawDataProvider(const ParameterSet& iConfig)
00032 : queueSize_(0)
00033 , eventQueue_(0)
00034 , runNumber_(0)
00035 , evtNumber_(0)
00036 , count_(0)
00037 , writeIndex_(0)
00038 , readIndex_(0)
00039 , freeToEof_(false)
00040 {
00041 queueSize_=iConfig.getUntrackedParameter<unsigned int>("queueSize",32);
00042 sem_init(&lock_,0,1);
00043 sem_init(&writeSem_,0,queueSize_);
00044 sem_init(&readSem_,0,0);
00045 runNumber_ =new unsigned int[queueSize_];
00046 evtNumber_ =new unsigned int[queueSize_];
00047 eventQueue_=new FEDRawDataCollection*[queueSize_];
00048 for (unsigned int i=0;i<queueSize_;i++) eventQueue_[i]=0;
00049 edm::LogInfo("PbImpl") << "Created Concrete RawData Provider 0x"<< hex << (unsigned long) this << dec << endl;
00050 instance_=this;
00051 }
00052
00053
00054
00055 PlaybackRawDataProvider::~PlaybackRawDataProvider()
00056 {
00057 if (0!=runNumber_) delete [] runNumber_;
00058 if (0!=evtNumber_) delete [] evtNumber_;
00059 if (0!=eventQueue_) {
00060 for (unsigned int i=0;i<queueSize_;i++)
00061 if (0!=eventQueue_[i]) delete eventQueue_[i];
00062 delete [] eventQueue_;
00063 }
00064 edm::LogInfo("PbImpl") << "Destroyed Concrete RawData Provider 0x"<< hex << (unsigned long) this << dec << endl;
00065 instance_=0;
00066 }
00067
00068
00070
00072
00073
00074 void PlaybackRawDataProvider::analyze(const Event& iEvent,
00075 const EventSetup& iSetup)
00076 {
00077 if(freeToEof_) return;
00078 waitWriteSem();
00079 if(freeToEof_) return;
00080 runNumber_[writeIndex_]=iEvent.id().run();
00081 evtNumber_[writeIndex_]=iEvent.id().event();
00082
00083 Handle<FEDRawDataCollection> pRawData;
00084 iEvent.getByType(pRawData);
00085
00086 if (!pRawData.isValid()) {
00087 edm::LogError("InvalidHandle")<<"no raw data found!"<<endl;
00088 return;
00089 }
00090
00091
00092
00093 assert(0==eventQueue_[writeIndex_]);
00094 eventQueue_[writeIndex_]=new FEDRawDataCollection();
00095 for (unsigned int i=0;i<(unsigned int)FEDNumbering::MAXFEDID+1;i++) {
00096 unsigned int fedSize=pRawData->FEDData(i).size();
00097 if (fedSize>0) {
00098 FEDRawData& fedData=eventQueue_[writeIndex_]->FEDData(i);
00099 fedData.resize(fedSize);
00100 memcpy(fedData.data(),pRawData->FEDData(i).data(),fedSize);
00101 }
00102 }
00103
00104 lock();
00105 writeIndex_=(writeIndex_+1)%queueSize_;
00106 count_++;
00107 unlock();
00108
00109 postReadSem();
00110
00111 return;
00112 }
00113
00114
00115
00116 void PlaybackRawDataProvider::beginJob()
00117 {
00118
00119 }
00120
00121
00122
00123 void PlaybackRawDataProvider::endJob()
00124 {
00125 edm::LogInfo("Summary")<<count_<<" events read."<<endl;
00126 }
00127
00128
00129
00130 FEDRawDataCollection* PlaybackRawDataProvider::getFEDRawData()
00131 {
00132 FEDRawDataCollection* result = 0;
00133 waitReadSem();
00134 lock();
00135 result = eventQueue_[readIndex_];
00136 eventQueue_[readIndex_]=0;
00137 readIndex_=(readIndex_+1)%queueSize_;
00138 unlock();
00139
00140 postWriteSem();
00141 return result;
00142 }
00143
00144
00145
00146 FEDRawDataCollection* PlaybackRawDataProvider::getFEDRawData(unsigned int& runNumber,
00147 unsigned int& evtNumber)
00148 {
00149
00150 FEDRawDataCollection* result = 0;
00151 waitReadSem();
00152 lock();
00153 runNumber=runNumber_[readIndex_];
00154 evtNumber=evtNumber_[readIndex_];
00155 result=eventQueue_[readIndex_];
00156
00157 eventQueue_[readIndex_]=0;
00158 readIndex_=(readIndex_+1)%queueSize_;
00159
00160 unlock();
00161
00162 postWriteSem();
00163 return result;
00164 }
00165
00166
00167
00168 void PlaybackRawDataProvider::sem_print()
00169 {
00170 lock();
00171 int wsem,rsem;
00172 sem_getvalue(&writeSem_,&wsem);
00173 sem_getvalue(&readSem_,&rsem);
00174 cout<<"sem_print():"
00175 <<" wsem="<<wsem
00176 <<" rsem="<<rsem
00177 <<" writeIndex="<<writeIndex_
00178 <<" readIndex="<<readIndex_
00179 <<endl;
00180 unlock();
00181 }
00182
00183 void PlaybackRawDataProvider::setFreeToEof()
00184 {
00185
00186 freeToEof_ = true;
00187
00188 postWriteSem();
00189 }
00191
00193