@@ -186,148 +186,6 @@ class FedRawDataInputSource : public edm::RawInputSource {
186186 std::mutex monlock_;
187187};
188188
189- struct InputChunk {
190- unsigned char * buf_;
191- InputChunk* next_ = nullptr ;
192- uint64_t size_;
193- uint64_t usedSize_ = 0 ;
194- // unsigned int index_;
195- uint64_t offset_;
196- unsigned int fileIndex_;
197- std::atomic<bool > readComplete_;
198-
199- InputChunk (uint64_t size) : size_(size) {
200- buf_ = new unsigned char [size_];
201- reset (0 , 0 , 0 );
202- }
203- void reset (uint64_t newOffset, uint64_t toRead, unsigned int fileIndex) {
204- offset_ = newOffset;
205- usedSize_ = toRead;
206- fileIndex_ = fileIndex;
207- readComplete_ = false ;
208- }
209-
210- bool resize (uint64_t wantedSize, uint64_t maxSize) {
211- if (wantedSize > maxSize)
212- return false ;
213- if (size_ < wantedSize) {
214- size_ = uint64_t (wantedSize * 1.05 );
215- delete[] buf_;
216- buf_ = new unsigned char [size_];
217- }
218- return true ;
219- }
220-
221- ~InputChunk () { delete[] buf_; }
222- };
223-
224- class InputFile {
225- public:
226- FedRawDataInputSource* parent_;
227- evf::EvFDaqDirector::FileStatus status_;
228- unsigned int lumi_;
229- std::string fileName_;
230- // used by DAQSource
231- std::vector<std::string> fileNames_;
232- std::vector<uint64_t > diskFileSizes_;
233- std::vector<uint64_t > bufferOffsets_;
234- std::vector<uint64_t > fileSizes_;
235- std::vector<unsigned int > fileOrder_;
236- bool deleteFile_;
237- int rawFd_;
238- uint64_t fileSize_;
239- uint16_t rawHeaderSize_;
240- uint16_t nChunks_;
241- uint16_t numFiles_;
242- int nEvents_;
243- unsigned int nProcessed_;
244-
245- tbb::concurrent_vector<InputChunk*> chunks_;
246-
247- uint32_t bufferPosition_ = 0 ;
248- uint32_t chunkPosition_ = 0 ;
249- unsigned int currentChunk_ = 0 ;
250-
251- InputFile (evf::EvFDaqDirector::FileStatus status,
252- unsigned int lumi = 0 ,
253- std::string const & name = std::string(),
254- bool deleteFile = true ,
255- int rawFd = -1 ,
256- uint64_t fileSize = 0 ,
257- uint16_t rawHeaderSize = 0 ,
258- uint16_t nChunks = 0 ,
259- int nEvents = 0 ,
260- FedRawDataInputSource* parent = nullptr )
261- : parent_(parent),
262- status_ (status),
263- lumi_(lumi),
264- fileName_(name),
265- deleteFile_(deleteFile),
266- rawFd_(rawFd),
267- fileSize_(fileSize),
268- rawHeaderSize_(rawHeaderSize),
269- nChunks_(nChunks),
270- numFiles_(1 ),
271- nEvents_(nEvents),
272- nProcessed_(0 ) {
273- fileNames_.push_back (name);
274- fileOrder_.push_back (fileOrder_.size ());
275- diskFileSizes_.push_back (fileSize);
276- fileSizes_.push_back (0 );
277- bufferOffsets_.push_back (0 );
278- chunks_.reserve (nChunks_);
279- for (unsigned int i = 0 ; i < nChunks; i++)
280- chunks_.push_back (nullptr );
281- }
282- virtual ~InputFile ();
283-
284- void setChunks (uint16_t nChunks) {
285- nChunks_ = nChunks;
286- chunks_.clear ();
287- chunks_.reserve (nChunks_);
288- for (unsigned int i = 0 ; i < nChunks_; i++)
289- chunks_.push_back (nullptr );
290- }
291-
292- void appendFile (std::string const & name, uint64_t size) {
293- size_t prevOffset = bufferOffsets_.back ();
294- size_t prevSize = diskFileSizes_.back ();
295- numFiles_++;
296- fileNames_.push_back (name);
297- fileOrder_.push_back (fileOrder_.size ());
298- diskFileSizes_.push_back (size);
299- fileSizes_.push_back (0 );
300- bufferOffsets_.push_back (prevOffset + prevSize);
301- }
302-
303- bool waitForChunk (unsigned int chunkid) {
304- // some atomics to make sure everything is cache synchronized for the main thread
305- return chunks_[chunkid] != nullptr && chunks_[chunkid]->readComplete_ ;
306- }
307- bool advance (std::mutex& m, std::condition_variable& cv, unsigned char *& dataPosition, const size_t size);
308- bool advanceSimple (unsigned char *& dataPosition, const size_t size) {
309- size_t currentLeft = chunks_[currentChunk_]->size_ - chunkPosition_;
310- if (currentLeft < size)
311- return true ;
312- dataPosition = chunks_[currentChunk_]->buf_ + chunkPosition_;
313- chunkPosition_ += size;
314- bufferPosition_ += size;
315- return false ;
316- }
317- void resetPos () {
318- chunkPosition_ = 0 ;
319- bufferPosition_ = 0 ;
320- }
321- void moveToPreviousChunk (const size_t size, const size_t offset);
322- void rewindChunk (const size_t size);
323- void unsetDeleteFile () { deleteFile_ = false ; }
324- void randomizeOrder (std::default_random_engine& rng) {
325- std::shuffle (std::begin (fileOrder_), std::end (fileOrder_), rng);
326- }
327- uint64_t currentChunkSize () const { return chunks_[currentChunk_]->size_ ; }
328- int64_t fileSizeLeft () const { return (int64_t )fileSize_ - (int64_t )bufferPosition_; }
329- };
330-
331189#endif // EventFilter_Utilities_FedRawDataInputSource_h
332190
333191// / emacs configuration
0 commit comments