CMS 3D CMS Logo

SimHitPrinter.cc
Go to the documentation of this file.
2 
3 #include <iomanip>
4 #include <iostream>
5 #include <memory>
6 #include <mutex>
7 
8 std::atomic<std::ofstream*> SimHitPrinter::theFile(nullptr);
9 
10 namespace {
11  std::mutex fileMutex;
12 }
13 
15  if (theFile)
16  return;
17  const char* theName = filename.c_str();
18  auto f = std::make_unique<std::ofstream>(theName, std::ios::out);
19 
20  std::ofstream* previous = nullptr;
21  if (theFile.compare_exchange_strong(previous, f.get())) {
22  //this thread was the first one to try to set the value
23  f.release();
24  }
25 }
26 
28  // theFile->close();
29 }
30 
32  std::cout.width(10);
33  std::cout.setf(std::ios::right, std::ios::adjustfield);
34  std::cout.setf(std::ios::scientific, std::ios::floatfield);
35  std::cout.precision(6);
36  std::cout << "SimHit in " << s << std::endl;
37 
38  std::lock_guard<std::mutex> guard{fileMutex};
39  (*theFile).width(10);
40  (*theFile).setf(std::ios::right, std::ios::adjustfield);
41  (*theFile).setf(std::ios::scientific | std::ios::uppercase | std::ios::showpos, std::ios::floatfield);
42  (*theFile).precision(5);
43  (*theFile) << "SimHit in " << s;
44 }
45 
47  std::lock_guard<std::mutex> guard{fileMutex};
48  (*theFile) << "Event " << num << std::endl;
49 }
50 
51 void SimHitPrinter::printId(int id) const {
52  std::cout << " Id: " << id << std::endl;
53  std::lock_guard<std::mutex> guard{fileMutex};
54  (*theFile) << " id ";
55  (*theFile).width(10);
56  (*theFile).setf(std::ios::right, std::ios::adjustfield);
57  (*theFile) << id;
58 }
59 
60 void SimHitPrinter::printTrack(int id) const {
61  std::cout << " Track: " << id << std::endl;
62  std::lock_guard<std::mutex> guard{fileMutex};
63  (*theFile) << " trk ";
64  (*theFile).width(10);
65  (*theFile).setf(std::ios::right, std::ios::adjustfield);
66  (*theFile) << id;
67 }
68 
69 void SimHitPrinter::printPabs(float pabs) const {
70  std::cout << " Pabs: " << pabs << std::endl;
71  std::lock_guard<std::mutex> guard{fileMutex};
72  (*theFile) << " p " << pabs;
73 }
74 
75 void SimHitPrinter::printEloss(float eloss) const {
76  std::cout << " Eloss: " << eloss << std::endl;
77  std::lock_guard<std::mutex> guard{fileMutex};
78  (*theFile) << " e " << eloss;
79 }
80 
81 void SimHitPrinter::printLocal(LocalPoint localen, LocalPoint localex) const {
82  std::cout << " Local(en/ex): " << localen.x() << " " << localen.y() << " " << localen.z() << " / " << localex.x()
83  << " " << localex.y() << " " << localex.z() << std::endl;
84  std::lock_guard<std::mutex> guard{fileMutex};
85  (*theFile).width(10);
86  (*theFile).setf(std::ios::right, std::ios::adjustfield);
87  (*theFile).setf(std::ios::floatfield);
88  (*theFile).precision(6);
89  (*theFile) << " en/ex " << localen.x() << " " << localen.y() << " " << localen.z() << " / " << localex.x() << " "
90  << localex.y() << " " << localex.z();
91 }
92 
94  std::cout << " Global(en): " << global.x() << " " << global.y() << " " << global.z() << std::endl;
95  std::lock_guard<std::mutex> guard{fileMutex};
96  (*theFile).width(10);
97  (*theFile).setf(std::ios::right, std::ios::adjustfield);
98  (*theFile).setf(std::ios::floatfield);
99  (*theFile).precision(6);
100  (*theFile) << " gl " << global.x() << " " << global.y() << " " << global.z() << std::endl;
101 }
void printPabs(float) const
void printTrack(int) const
T z() const
Definition: PV3DBase.h:61
static std::mutex mutex
Definition: Proxy.cc:8
void printEloss(float) const
void printLocal(LocalPoint, LocalPoint) const
void printId(int) const
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
void startNewEvent(int)
double f[11][100]
static std::atomic< std::ofstream * > theFile
Definition: SimHitPrinter.h:39
SimHitPrinter(std::string)
void printGlobal(GlobalPoint) const
void startNewSimHit(std::string)