CMS 3D CMS Logo

TrackletProjectionsMemory.cc
Go to the documentation of this file.
4 #include <iomanip>
5 #include <filesystem>
6 
7 using namespace std;
8 using namespace trklet;
9 
10 TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const& settings)
11  : MemoryBase(name, settings) {
12  size_t pos = find_nth(name, 0, "_", 1);
13  assert(pos != string::npos);
15  hasProj_ = false;
16 }
17 
19  if (layer_ != 0 && disk_ == 0)
20  assert(tracklet->validProj(layer_ - 1));
21  if (layer_ == 0 && disk_ != 0)
22  assert(tracklet->validProj(N_LAYER + abs(disk_) - 1));
23  if (layer_ != 0 && disk_ != 0)
24  assert(tracklet->validProj(layer_ - 1) || tracklet->validProj(N_LAYER + abs(disk_) - 1));
25 
26  for (auto& itracklet : tracklets_) {
27  if (itracklet == tracklet) {
28  edm::LogPrint("Tracklet") << "Adding same tracklet " << tracklet << " twice in " << getName();
29  }
30  assert(itracklet != tracklet);
31  }
32 
33  hasProj_ = true;
34  tracklets_.push_back(tracklet);
35 }
36 
38 
39 void TrackletProjectionsMemory::writeTPROJ(bool first, unsigned int iSector) {
40  iSector_ = iSector;
41  const string dirTP = settings_.memPath() + "TrackletProjections/";
42 
43  std::ostringstream oss;
44  oss << dirTP << "TrackletProjections_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1)
45  << ".dat";
46  auto const& fname = oss.str();
47 
48  openfile(out_, first, dirTP, fname, __FILE__, __LINE__);
49 
50  out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;
51 
52  for (unsigned int j = 0; j < tracklets_.size(); j++) {
53  string proj = (layer_ > 0 && tracklets_[j]->validProj(layer_ - 1)) ? tracklets_[j]->trackletprojstrlayer(layer_)
54  : tracklets_[j]->trackletprojstrdisk(disk_);
55  out_ << hexstr(j) << " " << proj << " " << trklet::hexFormat(proj) << endl;
56  }
57  out_.close();
58 
59  bx_++;
60  event_++;
61  if (bx_ > 7)
62  bx_ = 0;
63 }
static size_t find_nth(const std::string &haystack, size_t pos, const std::string &needle, size_t nth)
Definition: MemoryBase.cc:104
unsigned int iSector_
Definition: MemoryBase.h:47
void writeTPROJ(bool first, unsigned int iSector)
assert(be >=bs)
std::string hexFormat(const std::string &binary)
Definition: Util.h:19
std::string memPath() const
Definition: Settings.h:202
Settings const & settings_
Definition: MemoryBase.h:53
std::ofstream out_
Definition: MemoryBase.h:49
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string const & getName() const
Definition: MemoryBase.h:19
Log< level::Warning, true > LogPrint
static std::string hexstr(unsigned int index)
Definition: MemoryBase.cc:111
string fname
main script
bool validProj(int layerdisk) const
Definition: Tracklet.h:82
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: MemoryBase.cc:20
std::ofstream openfile(const std::string &dir, const std::string &fname, const char *file, int line)
Definition: Util.h:154
constexpr int N_LAYER
Definition: Settings.h:25