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 }
SimHitPrinter::printTrack
void printTrack(int) const
Definition: SimHitPrinter.cc:60
SimHitPrinter::startNewSimHit
void startNewSimHit(std::string)
Definition: SimHitPrinter.cc:31
SimHitPrinter::startNewEvent
void startNewEvent(int)
Definition: SimHitPrinter.cc:46
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
SimHitPrinter::theFile
static std::atomic< std::ofstream * > theFile
Definition: SimHitPrinter.h:39
SimHitPrinter::printEloss
void printEloss(float) const
Definition: SimHitPrinter.cc:75
gather_cfg.cout
cout
Definition: gather_cfg.py:144
SimHitPrinter::printId
void printId(int) const
Definition: SimHitPrinter.cc:51
callgraph.previous
previous
Definition: callgraph.py:62
SimHitPrinter::SimHitPrinter
SimHitPrinter(std::string)
Definition: SimHitPrinter.cc:14
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
alignCSCRings.s
s
Definition: alignCSCRings.py:92
SimHitPrinter::printGlobal
void printGlobal(GlobalPoint) const
Definition: SimHitPrinter.cc:93
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
Point3DBase< float, LocalTag >
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SimHitPrinter::printLocal
void printLocal(LocalPoint, LocalPoint) const
Definition: SimHitPrinter.cc:81
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
mutex
static std::mutex mutex
Definition: Proxy.cc:8
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
SimHitPrinter.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
SimHitPrinter::printPabs
void printPabs(float) const
Definition: SimHitPrinter.cc:69
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
SimHitPrinter::~SimHitPrinter
~SimHitPrinter()
Definition: SimHitPrinter.cc:27