Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-01 23:54:03

0001 
0002 #ifndef L1Trigger_DemonstratorTools_BoardDataWriter_h
0003 #define L1Trigger_DemonstratorTools_BoardDataWriter_h
0004 
0005 #include <functional>
0006 
0007 #include "L1Trigger/DemonstratorTools/interface/BoardData.h"
0008 #include "L1Trigger/DemonstratorTools/interface/EventData.h"
0009 #include "L1Trigger/DemonstratorTools/interface/ChannelSpec.h"
0010 #include "L1Trigger/DemonstratorTools/interface/FileFormat.h"
0011 
0012 namespace l1t::demo {
0013 
0014   // Writes I/O buffer files created from hardware/firmware tests, ensuring that
0015   // the data conforms to the declared packet structure (by inserting invalid
0016   // frames automatically), concatenating data from each event (accounting for
0017   // different TM periods of specific links, and of the data-processor itself),
0018   // and transparently switching to new output files when the data would overrun
0019   // the length of the board's I/O buffers
0020   class BoardDataWriter {
0021   public:
0022     // map of logical channel ID -> [TMUX period, interpacket-gap & offset; channel indices]
0023     typedef std::map<LinkId, std::pair<ChannelSpec, std::vector<size_t>>> ChannelMap_t;
0024 
0025     BoardDataWriter(FileFormat,
0026                     const std::string& filePath,
0027                     const size_t framesPerBX,
0028                     const size_t tmux,
0029                     const size_t maxFramesPerFile,
0030                     const ChannelMap_t&);
0031 
0032     BoardDataWriter(FileFormat,
0033                     const std::string& filePath,
0034                     const size_t framesPerBX,
0035                     const size_t tmux,
0036                     const size_t maxFramesPerFile,
0037                     const std::map<LinkId, std::vector<size_t>>&,
0038                     const std::map<std::string, ChannelSpec>&);
0039 
0040     void addEvent(const EventData& data);
0041 
0042     // If there are events that have not been written to file, forces creation of a board data file containing them
0043     void flush();
0044 
0045   private:
0046     static ChannelMap_t mergeMaps(const std::map<LinkId, std::vector<size_t>>&,
0047                                   const std::map<std::string, ChannelSpec>&);
0048 
0049     void resetBoardData();
0050 
0051     FileFormat fileFormat_;
0052 
0053     std::function<std::string(const size_t)> filePathGen_;
0054 
0055     std::vector<std::string> fileNames_;
0056 
0057     size_t framesPerBX_;
0058 
0059     size_t boardTMUX_;
0060 
0061     size_t maxFramesPerFile_;
0062 
0063     size_t maxEventsPerFile_;
0064 
0065     size_t eventIndex_;
0066 
0067     // Number of events stored in boardData_
0068     size_t pendingEvents_;
0069 
0070     BoardData boardData_;
0071 
0072     // map of logical channel ID -> [TMUX period, interpacket-gap & offset; channel indices]
0073     ChannelMap_t channelMap_;
0074   };
0075 
0076 }  // namespace l1t::demo
0077 
0078 #endif