Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:47

0001 /* 
0002  * File:   MP7FileReader.h
0003  * Author: ale
0004  *
0005  * Created on August 22, 2014, 10:30 AM
0006  */
0007 
0008 #ifndef EventFilter_L1TRawToDigi_MP7FileReader_h
0009 #define EventFilter_L1TRawToDigi_MP7FileReader_h
0010 
0011 // C++ Headers
0012 #include <string>
0013 #include <fstream>
0014 #include <map>
0015 #include <cstdint>
0016 #include <vector>
0017 
0018 // Boost Headers
0019 #include <boost/regex.hpp>
0020 
0021 class FileData {
0022 public:
0023   typedef std::map<uint32_t, std::vector<uint64_t> > LinkMap;
0024   typedef LinkMap::value_type value_type;
0025   typedef LinkMap::const_iterator const_iterator;
0026 
0027   const std::string& name() const { return name_; }
0028 
0029   const std::vector<uint64_t>& link(uint32_t i) const;
0030 
0031   size_t size() const { return links_.size(); }
0032 
0033   LinkMap::const_iterator begin() const { return links_.begin(); }
0034   LinkMap::const_iterator end() const { return links_.end(); }
0035 
0036 private:
0037   std::string name_;
0038   LinkMap links_;
0039 
0040   friend class MP7FileReader;
0041 };
0042 
0043 class MP7FileReader {
0044 public:
0045   /// expose vector's const iterator
0046   typedef std::vector<FileData>::const_iterator const_iterator;
0047 
0048   MP7FileReader(const std::string& path);
0049 
0050   virtual ~MP7FileReader();
0051 
0052   /// reader status. valid() == 1 indicates that data was successfully read from file
0053   bool valid() const { return valid_; }
0054 
0055   /// source file path
0056   const std::string& path() const { return path_; }
0057 
0058   /// data getter via index
0059   const FileData& get(size_t k) const;
0060 
0061   /// raw data name collector
0062   std::vector<std::string> names() const;
0063 
0064   /// vector's begin iterator
0065   const_iterator begin() { return buffers_.begin(); }
0066 
0067   /// vector's end iterator
0068   const_iterator end() { return buffers_.end(); }
0069 
0070   /// number of rawdata objects stored
0071   size_t size() const { return buffers_.size(); }
0072 
0073 private:
0074   std::string searchBoard();
0075 
0076   std::vector<uint32_t> searchLinks();
0077 
0078   std::vector<std::vector<uint64_t> > readRows();
0079 
0080   static uint64_t validStrToUint64(const std::string& token);
0081 
0082   void load();
0083 
0084   bool valid_;
0085   std::string path_;
0086   std::ifstream file_;
0087 
0088 public:
0089   std::vector<FileData> buffers_;
0090 
0091 private:
0092   static boost::regex reBoard_;
0093   static boost::regex reLink_;
0094   static boost::regex reQuadChan_;
0095   static boost::regex reFrame_;
0096   static boost::regex reValid_;
0097 };
0098 
0099 #endif /* READER_H */