Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:38

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 std::string& fileExt,
0028                     const size_t framesPerBX,
0029                     const size_t tmux,
0030                     const size_t maxFramesPerFile,
0031                     const ChannelMap_t&);
0032 
0033     BoardDataWriter(FileFormat,
0034                     const std::string& filePath,
0035                     const std::string& fileExt,
0036                     const size_t framesPerBX,
0037                     const size_t tmux,
0038                     const size_t maxFramesPerFile,
0039                     const std::map<LinkId, std::vector<size_t>>&,
0040                     const std::map<std::string, ChannelSpec>&);
0041 
0042     // Set ID string that's written at start of board data files
0043     void setBoardDataFileID(const std::string&);
0044 
0045     void addEvent(const EventData& data);
0046 
0047     // If there are events that have not been written to file, forces creation of a board data file containing them
0048     void flush();
0049 
0050   private:
0051     static ChannelMap_t mergeMaps(const std::map<LinkId, std::vector<size_t>>&,
0052                                   const std::map<std::string, ChannelSpec>&);
0053 
0054     void resetBoardData();
0055 
0056     FileFormat fileFormat_;
0057 
0058     // ID string that's written at start of board data files
0059     std::string boardDataFileID_;
0060 
0061     std::function<std::string(const size_t)> filePathGen_;
0062 
0063     std::vector<std::string> fileNames_;
0064 
0065     size_t framesPerBX_;
0066 
0067     size_t boardTMUX_;
0068 
0069     size_t maxFramesPerFile_;
0070 
0071     size_t maxEventsPerFile_;
0072 
0073     size_t eventIndex_;
0074 
0075     // Number of events stored in boardData_
0076     size_t pendingEvents_;
0077 
0078     BoardData boardData_;
0079 
0080     // map of logical channel ID -> [TMUX period, interpacket-gap & offset; channel indices]
0081     ChannelMap_t channelMap_;
0082   };
0083 
0084 }  // namespace l1t::demo
0085 
0086 #endif