CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AsciiNeutronReader.cc
Go to the documentation of this file.
5 #include <sstream>
6 #include<iostream>
7 
8 using namespace std;
9 
11  theFileNameBase(fileNameBase),
12  //theStreamPos(nChamberTypes+1, 0) //TODO WON"T WORK! replace with a map
13  theStreamPos(11,0)
14 {
15 }
16 
17 
19  stringstream fileName;
20  fileName << theFileNameBase << chamberType;
21  ifstream fin(fileName.str().c_str(), ios::in);
22  if(!fin.is_open()) {
23  throw cms::Exception("NeutronReader")
24  << "Muon neutron noise file missing " << fileName.str();
25  }
26 
27  int nhits = read_nhits(fin, chamberType);
28  for(int ihit = 0; ihit < nhits; ++ihit) {
29  float entryX, entryY, entryZ, exitX, exitY, exitZ;
30  float p, tof, eloss, theta, phi;
31  int type, layer, track;
32 
33  fin >> entryX >> entryY >> entryZ
34  >> exitX >> exitY >> exitZ
35  >> p >> tof >> eloss >> type >> layer >> track >> theta >> phi;
36  LocalPoint entry(entryX, entryY, entryZ);
37  LocalPoint exit (exitX, exitY, exitZ);
38  PSimHit phit(entry, exit, p, tof, eloss, type, layer, track, theta, phi);
39  result.push_back(phit);
40  }
41  theStreamPos[chamberType] = fin.tellg();
42 }
43 
44 
45 int AsciiNeutronReader::read_nhits(ifstream & fin, int chamberType) {
46  int nhits = 0;
47  // go to the last saved place
48  fin.seekg(theStreamPos[chamberType]);
49  if(fin.eof()) {
50  resetStreampos(fin, chamberType);
51  }
52  LogDebug("NeutronReader") << "starting from pos " << theStreamPos[chamberType]
53  << " EOF " << fin.eof();
54  fin >> nhits;
55  if(fin.eof()) {
56  resetStreampos(fin, chamberType);
57  fin >> nhits;
58  }
59  LogDebug("NeutronReader") << "returning nhits " << nhits;
60  return nhits;
61 }
62 
63 
64 void AsciiNeutronReader::resetStreampos(ifstream & fin, int chamberType) {
65  LogDebug("NeutronReader") << "reached EOF, resetting streampos ";
66  theStreamPos[chamberType] = 0;
67  fin.clear();
68  fin.seekg(0, ios::beg);
69 }
70 
#define LogDebug(id)
type
Definition: HCALResponse.h:21
Geom::Theta< T > theta() const
virtual void readNextEvent(int chamberType, edm::PSimHitContainer &result)
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
tuple result
Definition: query.py:137
std::string theFileNameBase
std::vector< std::streampos > theStreamPos
AsciiNeutronReader(std::string fileNameBase)
std::vector< PSimHit > PSimHitContainer
int read_nhits(std::ifstream &fin, int chamberType)
void resetStreampos(std::ifstream &fin, int chamberType)
Definition: DDAxes.h:10