CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 35 of file MP7FileReader.cc.

References file_, load(), and valid_.

35  : valid_(false), path_(path), file_(path) {
36  if (!file_.is_open()) {
37  //cout << "File " << path << " not found" << endl;
38  valid_ = false;
39  return;
40  }
41 
42  load();
43 }
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
MP7FileReader::~MP7FileReader ( )
virtual

Definition at line 46 of file MP7FileReader.cc.

46  {
47 }

Member Function Documentation

const_iterator MP7FileReader::begin ( void  )
inline

vector's begin iterator

Definition at line 68 of file MP7FileReader.h.

References buffers_.

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.

References buffers_.

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 67 of file MP7FileReader.cc.

References buffers_, data, file_, i, j, electronStore::links, FileData::links_, FileData::name_, readRows(), alignCSCRings::s, searchBoard(), searchLinks(), AlCaHLTBitMon_QueryRunRegistry::string, and valid_.

Referenced by MP7FileReader().

67  {
68  using namespace boost;
69 
70 
71  // Data, to be stored in a BufferSnapshot object
72  while (file_.good()) {
73  std::string id = searchBoard();
74  //cout << "Id: " << id << endl;
75  std::vector<uint32_t> links = searchLinks();
76 
77  //cout << "Links (" << links.size() << ") : ";
78 
79  //BOOST_FOREACH(uint32_t l, links) {
80  //cout << l << ",";
81  //}
82  //cout << endl;
83 
84  std::vector< std::vector<uint64_t> > data = readRows();
85  //cout << "Data loaded (" << data.size() << ")" << endl;
86 
87  // Id, Link # and Data Loaded
88 
89  FileData s;
90  s.name_ = id;
91 
92  std::vector< std::vector<uint64_t> > chans( links.size(), std::vector<uint64_t>(data.size()) );
93 
94  // Transpose
95  for ( size_t i(0); i<links.size(); ++i) {
96  for ( size_t j(0); j<data.size(); ++j) {
97  chans[i][j] = data[j][i];
98  }
99  }
100 
101  // pack
102  for ( size_t i(0); i<links.size(); ++i) {
103  s.links_.insert( std::make_pair(links[i],chans[i]) );
104  }
105 
106  buffers_.push_back(s);
107  }
108 
109  // File successfully read
110  valid_ = true;
111 
112 }
int i
Definition: DBlmapReader.cc:9
std::ifstream file_
Definition: MP7FileReader.h:90
LinkMap links_
Definition: MP7FileReader.h:40
std::vector< std::vector< uint64_t > > readRows()
int j
Definition: DBlmapReader.cc:9
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 57 of file MP7FileReader.cc.

References buffers_, FileData::name(), and alignCSCRings::r.

57  {
58  std::vector<std::string> names(buffers_.size());
59 
60  BOOST_FOREACH( const FileData& r, buffers_ ) {
61  names.push_back(r.name());
62  }
63  return names;
64 }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
const std::string & name() const
Definition: MP7FileReader.h:28
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 path_.

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

Definition at line 190 of file MP7FileReader.cc.

References data, file_, geometryCSVtoXML::line, n, reBoard_, reFrame_, split, contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, tmp, create_public_lumi_plots::transform, and validStrToUint64().

Referenced by load().

190  {
192  boost::smatch what;
193  std::vector< std::vector<uint64_t> > data;
194  int place = file_.tellg();
195  while (getline(file_, line)) {
196 
197  if (boost::regex_match(line, what, reBoard_)) {
198  // Upos, next board found. Go back by one line
199  file_.seekg(place);
200  return data;
201  }
202 
203  if (boost::regex_match(line, what, reFrame_)) {
204  // check frame number
205  uint32_t n = boost::lexical_cast<uint32_t>(what[1].str());
206 
207  if (n != data.size()) {
208  std::stringstream ss;
209  ss << "Frame misalignment! (expected " << data.size() << " found " << n;
210  throw std::logic_error(ss.str());
211  }
212  std::vector<std::string> tokens;
213  std::string tmp = what[2].str();
214  boost::trim(tmp);
215  boost::split(tokens, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
216 
217  std::vector<uint64_t> row;
218  std::transform(tokens.begin(), tokens.end(), std::back_inserter(row), validStrToUint64);
219 
220  data.push_back(row);
221  }
222 
223  place = file_.tellg();
224  }
225 
226  return data;
227 
228 }
static boost::regex reBoard_
Definition: MP7FileReader.h:97
static boost::regex reFrame_
std::ifstream file_
Definition: MP7FileReader.h:90
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 116 of file MP7FileReader.cc.

References file_, geometryCSVtoXML::line, reBoard_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by load().

116  {
118  std::string id;
119  boost::smatch what;
120 
121  while (getline(file_, line)) {
122 
123  // Trim and skip empties and comments
124  boost::trim(line);
125  if (line.empty()) continue;
126  if (line[0] == '#') continue;
127 
128  if (boost::regex_match(line, what, reBoard_)) {
129  // Create a new buffer snapshot
130  id = what[1];
131  return id;
132  } else {
133  //cout << "Here '" << line << "'" << endl;
134  throw std::logic_error("Unexpected line found!");
135  }
136  }
137  throw std::logic_error("No board found");
138 }
static boost::regex reBoard_
Definition: MP7FileReader.h:97
std::ifstream file_
Definition: MP7FileReader.h:90
std::vector< uint32_t > MP7FileReader::searchLinks ( )
private

Definition at line 142 of file MP7FileReader.cc.

References file_, geometryCSVtoXML::line, electronStore::links, reLink_, reQuadChan_, split, AlCaHLTBitMon_QueryRunRegistry::string, tmp, and create_public_lumi_plots::transform.

Referenced by load().

142  {
144  boost::smatch what;
145 
146  while (getline(file_, line)) {
147 
148  boost::trim(line);
149  if (line.empty()) continue;
150  if (line[0] == '#') continue;
151 
152  if (boost::regex_match(line, what, reQuadChan_)) {
153  // Not used
154  continue;
155  }
156 
157  if (boost::regex_match(line, what, reLink_)) {
158 
159  std::vector<std::string> tokens;
160  std::string tmp = what[1].str();
161  // Trim the line
162  boost::trim(tmp);
163  // Split line into tokens
164  boost::split(tokens, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
165  // Convert it into uint32 s
166  std::vector<uint32_t> links;
167  std::transform(tokens.begin(), tokens.end(), std::back_inserter(links), boost::lexical_cast<uint32_t, const std::string&>);
168  return links;
169  } else {
170  throw std::logic_error("Unexpected line found!");
171  }
172  }
173  throw std::logic_error("No list of links found");
174 }
std::ifstream file_
Definition: MP7FileReader.h:90
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 buffers_.

Referenced by MP7PacketReader::load().

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 valid_.

Referenced by MP7PacketReader::MP7PacketReader(), and MP7PacketReader::valid().

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

Definition at line 176 of file MP7FileReader.cc.

References reValid_, and relativeConstraints::value.

Referenced by readRows().

176  {
177 
178  boost::smatch what;
179  if (!boost::regex_match(token, what, reValid_)) {
180  throw std::logic_error("Token '" + token + "' doesn't match the valid format");
181  }
182 
183  uint64_t value = (uint64_t) (what[1] == "1") << 32;
184  value += std::stoul(what[2].str(), 0x0, 16);
185  return value;
186 }
unsigned long long uint64_t
Definition: Time.h:15
static boost::regex reValid_

Member Data Documentation

std::vector<FileData> MP7FileReader::buffers_

Definition at line 94 of file MP7FileReader.h.

Referenced by begin(), end(), get(), load(), names(), and size().

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(), MP7FileReader(), and valid().