CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
MP7FileReader Class Reference

#include <MP7FileReader.h>

Public Types

typedef std::vector< FileData >::const_iterator const_iterator
 expose vector's const iterator More...
 

Public Member Functions

const_iterator begin ()
 vector's begin iterator More...
 
const_iterator end ()
 vector's end iterator More...
 
const FileDataget (size_t k) const
 data getter via index More...
 
 MP7FileReader (const std::string &path)
 
std::vector< std::string > names () const
 raw data name collector More...
 
const std::string & path () const
 source file path More...
 
size_t size () const
 number of rawdata objects stored More...
 
bool valid () const
 reader status. valid() == 1 indicates that data was successfully read from file More...
 
virtual ~MP7FileReader ()
 

Public Attributes

std::vector< FileDatabuffers_
 

Private Member Functions

void load ()
 
std::vector< std::vector< uint64_t > > readRows ()
 
std::string searchBoard ()
 
std::vector< uint32_t > searchLinks ()
 

Static Private Member Functions

static uint64_t validStrToUint64 (const std::string &token)
 

Private Attributes

std::ifstream file_
 
std::string path_
 
bool valid_
 

Static Private Attributes

static boost::regex reBoard_
 
static boost::regex reFrame_
 
static boost::regex reLink_
 
static boost::regex reQuadChan_
 
static boost::regex reValid_
 

Detailed Description

Definition at line 45 of file MP7FileReader.h.

Member Typedef Documentation

expose vector's const iterator

Definition at line 49 of file MP7FileReader.h.

Constructor & Destructor Documentation

MP7FileReader::MP7FileReader ( const std::string &  path)

Definition at line 36 of file MP7FileReader.cc.

References buffers_, file_, load(), LogDebug, path(), and valid_.

36  : valid_(false), path_(path), file_(path) {
37  if (!file_.is_open()) {
38  edm::LogError("L1T") << "File " << path << " not found";
39  valid_ = false;
40  return;
41  }
42  else {
43  LogDebug("L1T") << "Reading file " << path;
44  }
45 
46  load();
47 
48  LogDebug("L1T") << "# buffers " << buffers_.size();
49 
50  if (!buffers_.empty()) {
51  LogDebug("L1T") << "# links " << buffers_.at(0).size();
52  if (buffers_.at(0).size()>0) {
53  LogDebug("L1T") << "# frames " << buffers_.at(0).link(0).size();
54  }
55  }
56 
57 }
#define LogDebug(id)
std::ifstream file_
Definition: MP7FileReader.h:90
const std::string & path() const
source file path
Definition: MP7FileReader.h:59
std::string path_
Definition: MP7FileReader.h:89
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
MP7FileReader::~MP7FileReader ( )
virtual

Definition at line 60 of file MP7FileReader.cc.

60  {
61 }

Member Function Documentation

const_iterator MP7FileReader::begin ( void  )
inline

vector's begin iterator

Definition at line 68 of file MP7FileReader.h.

Referenced by MP7PacketReader::load().

68 { return buffers_.begin(); }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
const_iterator MP7FileReader::end ( void  )
inline

vector's end iterator

Definition at line 71 of file MP7FileReader.h.

Referenced by Types.LuminosityBlockRange::cppID(), Types.EventRange::cppID(), and MP7PacketReader::load().

71 { return buffers_.end(); }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
const FileData & MP7FileReader::get ( size_t  k) const
void MP7FileReader::load ( )
private

Definition at line 81 of file MP7FileReader.cc.

References buffers_, data, file_, mps_fire::i, triggerObjects_cff::id, FileData::links_, FileData::name_, readRows(), alignCSCRings::s, searchBoard(), searchLinks(), AlCaHLTBitMon_QueryRunRegistry::string, and valid_.

Referenced by MP7FileReader().

81  {
82  using namespace boost;
83 
84 
85  // Data, to be stored in a BufferSnapshot object
86  while (file_.good()) {
87  std::string id = searchBoard();
88  //cout << "Id: " << id << endl;
89  std::vector<uint32_t> links = searchLinks();
90 
91  //cout << "Links (" << links.size() << ") : ";
92 
93  //for(uint32_t l : links) {
94  //cout << l << ",";
95  //}
96  //cout << endl;
97 
98  std::vector< std::vector<uint64_t> > data = readRows();
99  //cout << "Data loaded (" << data.size() << ")" << endl;
100 
101  // Id, Link # and Data Loaded
102 
103  FileData s;
104  s.name_ = id;
105 
106  std::vector< std::vector<uint64_t> > chans( links.size(), std::vector<uint64_t>(data.size()) );
107 
108  // Transpose
109  for ( size_t i(0); i<links.size(); ++i) {
110  for ( size_t j(0); j<data.size(); ++j) {
111  chans[i][j] = data[j][i];
112  }
113  }
114 
115  // pack
116  for ( size_t i(0); i<links.size(); ++i) {
117  s.links_.insert( std::make_pair(links[i],chans[i]) );
118  }
119 
120  buffers_.push_back(s);
121  }
122 
123  // File successfully read
124  valid_ = true;
125 
126 }
Definition: CLHEP.h:16
std::ifstream file_
Definition: MP7FileReader.h:90
LinkMap links_
Definition: MP7FileReader.h:40
std::vector< std::vector< uint64_t > > readRows()
std::string name_
Definition: MP7FileReader.h:39
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::vector< uint32_t > searchLinks()
std::string searchBoard()
std::vector< std::string > MP7FileReader::names ( void  ) const

raw data name collector

Definition at line 71 of file MP7FileReader.cc.

References buffers_, and alignCSCRings::r.

71  {
72  std::vector<std::string> names(buffers_.size());
73 
74  for(auto const& r : buffers_ ) {
75  names.push_back(r.name());
76  }
77  return names;
78 }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
std::vector< std::string > names() const
raw data name collector
const std::string& MP7FileReader::path ( ) const
inline

source file path

Definition at line 59 of file MP7FileReader.h.

References gen::k, names, and path_.

Referenced by MP7FileReader().

59 { return path_; }
std::string path_
Definition: MP7FileReader.h:89
std::vector< std::vector< uint64_t > > MP7FileReader::readRows ( )
private

Definition at line 205 of file MP7FileReader.cc.

References data, file_, mps_splice::line, gen::n, reBoard_, reFrame_, split, AlCaHLTBitMon_QueryRunRegistry::string, tmp, create_public_lumi_plots::transform, trim(), and validStrToUint64().

Referenced by load().

205  {
207  boost::smatch what;
208  std::vector< std::vector<uint64_t> > data;
209  int place = file_.tellg();
210  while (getline(file_, line)) {
211 
212  if (boost::regex_match(line, what, reBoard_)) {
213  // Upos, next board found. Go back by one line
214  file_.seekg(place);
215  return data;
216  }
217 
218  if (boost::regex_match(line, what, reFrame_)) {
219  // check frame number
220  uint32_t n = boost::lexical_cast<uint32_t>(what[1].str());
221 
222  if (n != data.size()) {
223  std::stringstream ss;
224  ss << "Frame misalignment! (expected " << data.size() << " found " << n;
225  throw std::logic_error(ss.str());
226  }
227  std::vector<std::string> tokens;
228  std::string tmp = what[2].str();
229  boost::trim(tmp);
230  boost::split(tokens, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
231 
232  std::vector<uint64_t> row;
233  std::transform(tokens.begin(), tokens.end(), std::back_inserter(row), validStrToUint64);
234 
235  data.push_back(row);
236  }
237 
238  place = file_.tellg();
239  }
240 
241  return data;
242 
243 }
static boost::regex reBoard_
Definition: MP7FileReader.h:97
static boost::regex reFrame_
std::ifstream file_
Definition: MP7FileReader.h:90
static void trim(std::string &s)
static uint64_t validStrToUint64(const std::string &token)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double split
Definition: MVATrainer.cc:139
std::string MP7FileReader::searchBoard ( )
private

Definition at line 130 of file MP7FileReader.cc.

References file_, triggerObjects_cff::id, mps_splice::line, reBoard_, AlCaHLTBitMon_QueryRunRegistry::string, and trim().

Referenced by load().

130  {
132  std::string id;
133  boost::smatch what;
134 
135  while (getline(file_, line)) {
136 
137  // Trim and skip empties and comments
138  boost::trim(line);
139  if (line.empty()) continue;
140  if (line[0] == '#') continue;
141 
142  if (boost::regex_match(line, what, reBoard_)) {
143  // Create a new buffer snapshot
144  id = what[1];
145  return id;
146  } else {
147  edm::LogError("L1T") << "Unexpected line found";
148  return std::string("");
149  }
150  }
151  edm::LogError("L1T") << "No board found";
152  return std::string("");
153 }
static boost::regex reBoard_
Definition: MP7FileReader.h:97
std::ifstream file_
Definition: MP7FileReader.h:90
static void trim(std::string &s)
std::vector< uint32_t > MP7FileReader::searchLinks ( )
private

Definition at line 157 of file MP7FileReader.cc.

References file_, mps_splice::line, reLink_, reQuadChan_, split, AlCaHLTBitMon_QueryRunRegistry::string, tmp, create_public_lumi_plots::transform, and trim().

Referenced by load().

157  {
159  boost::smatch what;
160 
161  while (getline(file_, line)) {
162 
163  boost::trim(line);
164  if (line.empty()) continue;
165  if (line[0] == '#') continue;
166 
167  if (boost::regex_match(line, what, reQuadChan_)) {
168  // Not used
169  continue;
170  }
171 
172  if (boost::regex_match(line, what, reLink_)) {
173 
174  std::vector<std::string> tokens;
175  std::string tmp = what[1].str();
176  // Trim the line
177  boost::trim(tmp);
178  // Split line into tokens
179  boost::split(tokens, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
180  // Convert it into uint32 s
181  std::vector<uint32_t> links;
182  std::transform(tokens.begin(), tokens.end(), std::back_inserter(links), boost::lexical_cast<uint32_t, const std::string&>);
183  return links;
184  } else {
185  throw std::logic_error("Unexpected line found!");
186  }
187  }
188  throw std::logic_error("No list of links found");
189 }
std::ifstream file_
Definition: MP7FileReader.h:90
static void trim(std::string &s)
static boost::regex reLink_
Definition: MP7FileReader.h:98
static boost::regex reQuadChan_
Definition: MP7FileReader.h:99
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double split
Definition: MVATrainer.cc:139
size_t MP7FileReader::size ( void  ) const
inline

number of rawdata objects stored

Definition at line 74 of file MP7FileReader.h.

References svgfig::load(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by ntupleDataFormat._Collection::__iter__(), ntupleDataFormat._Collection::__len__(), MP7PacketReader::load(), and l1t::MP7BufferDumpToRaw::MP7BufferDumpToRaw().

74 { return buffers_.size(); }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
bool MP7FileReader::valid ( ) const
inline

reader status. valid() == 1 indicates that data was successfully read from file

Definition at line 56 of file MP7FileReader.h.

References sistrip::valid_.

Referenced by MP7PacketReader::MP7PacketReader().

56 { return valid_; }
uint64_t MP7FileReader::validStrToUint64 ( const std::string &  token)
staticprivate

Definition at line 191 of file MP7FileReader.cc.

References reValid_, str, and relativeConstraints::value.

Referenced by readRows().

191  {
192 
193  boost::smatch what;
194  if (!boost::regex_match(token, what, reValid_)) {
195  throw std::logic_error("Token '" + token + "' doesn't match the valid format");
196  }
197 
198  uint64_t value = (uint64_t) (what[1] == "1") << 32;
199  value += std::stoul(what[2].str(), nullptr, 16);
200  return value;
201 }
Definition: value.py:1
unsigned long long uint64_t
Definition: Time.h:15
static boost::regex reValid_
#define str(s)

Member Data Documentation

std::vector<FileData> MP7FileReader::buffers_

Definition at line 94 of file MP7FileReader.h.

Referenced by get(), load(), MP7FileReader(), and names().

std::ifstream MP7FileReader::file_
private

Definition at line 90 of file MP7FileReader.h.

Referenced by load(), MP7FileReader(), readRows(), searchBoard(), and searchLinks().

std::string MP7FileReader::path_
private
boost::regex MP7FileReader::reBoard_
staticprivate

Definition at line 97 of file MP7FileReader.h.

Referenced by readRows(), and searchBoard().

boost::regex MP7FileReader::reFrame_
staticprivate

Definition at line 100 of file MP7FileReader.h.

Referenced by readRows().

boost::regex MP7FileReader::reLink_
staticprivate

Definition at line 98 of file MP7FileReader.h.

Referenced by searchLinks().

boost::regex MP7FileReader::reQuadChan_
staticprivate

Definition at line 99 of file MP7FileReader.h.

Referenced by searchLinks().

boost::regex MP7FileReader::reValid_
staticprivate

Definition at line 101 of file MP7FileReader.h.

Referenced by validStrToUint64().

bool MP7FileReader::valid_
private

Definition at line 88 of file MP7FileReader.h.

Referenced by load(), and MP7FileReader().