CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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) return;
16  const char* theName = filename.c_str();
17  auto f = std::make_unique<std::ofstream>(theName, std::ios::out);
18 
19  std::ofstream* previous = nullptr;
20  if(theFile.compare_exchange_strong(previous,f.get()) ) {
21  //this thread was the first one to try to set the value
22  f.release();
23  }
24 }
25 
27  // theFile->close();
28 }
29 
31  std::cout.width(10);
32  std::cout.setf(std::ios::right,std::ios::adjustfield);
33  std::cout.setf(std::ios::scientific,std::ios::floatfield);
34  std::cout.precision(6);
35  std::cout << "SimHit in "<<s<<std::endl;
36 
37  std::lock_guard<std::mutex> guard{fileMutex};
38  (*theFile).width(10);
39  (*theFile).setf(std::ios::right,std::ios::adjustfield);
40  (*theFile).setf(std::ios::scientific|std::ios::uppercase|std::ios::showpos,std::ios::floatfield);
41  (*theFile).precision(5);
42  (*theFile) << "SimHit in "<<s;
43 }
44 
46  std::lock_guard<std::mutex> guard{fileMutex};
47  (*theFile) << "Event "<<num<<std::endl;
48 }
49 
50 void SimHitPrinter::printId(int id) const{
51  std::cout << " Id: "<<id<<std::endl;
52  std::lock_guard<std::mutex> guard{fileMutex};
53  (*theFile) << " id ";
54  (*theFile).width(10);
55  (*theFile).setf(std::ios::right,std::ios::adjustfield);
56  (*theFile) <<id;
57 }
58 
59 void SimHitPrinter::printTrack(int id) const{
60  std::cout << " Track: "<<id<<std::endl;
61  std::lock_guard<std::mutex> guard{fileMutex};
62  (*theFile) << " trk ";
63  (*theFile).width(10);
64  (*theFile).setf(std::ios::right,std::ios::adjustfield);
65  (*theFile) << id;
66 }
67 
68 void SimHitPrinter::printPabs(float pabs) const{
69  std::cout << " Pabs: "<<pabs<<std::endl;
70  std::lock_guard<std::mutex> guard{fileMutex};
71  (*theFile) << " p "<<pabs;
72 }
73 
74 void SimHitPrinter::printEloss(float eloss) const{
75  std::cout << " Eloss: "<<eloss<<std::endl;
76  std::lock_guard<std::mutex> guard{fileMutex};
77  (*theFile) << " e "<<eloss;
78 }
79 
80 void SimHitPrinter::printLocal(LocalPoint localen,LocalPoint localex) const{
81  std::cout << " Local(en/ex): "<<localen.x()<<" "<< localen.y()<<" "
82  <<localen.z()<<" / "<<localex.x()<<" "<< localex.y()<<" "
83  <<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()<<" "
90  <<localen.z()<<" / "<<localex.x()<<" "<< localex.y()<<" "
91  <<localex.z();
92 }
93 
95  std::cout << " Global(en): "<<global.x()<<" "<< global.y()<<" "
96  <<global.z()<<std::endl;
97  std::lock_guard<std::mutex> guard{fileMutex};
98  (*theFile).width(10);
99  (*theFile).setf(std::ios::right,std::ios::adjustfield);
100  (*theFile).setf(std::ios::floatfield);
101  (*theFile).precision(6);
102  (*theFile) << " gl "<<global.x()<<" "<< global.y()<<" "
103  <<global.z()<<std::endl;
104 }
void printTrack(int) const
static boost::mutex mutex
Definition: LHEProxy.cc:11
void printLocal(LocalPoint, LocalPoint) const
T y() const
Definition: PV3DBase.h:63
void startNewEvent(int)
T z() const
Definition: PV3DBase.h:64
void printPabs(float) const
double f[11][100]
static std::atomic< std::ofstream * > theFile
Definition: SimHitPrinter.h:38
SimHitPrinter(std::string)
void printGlobal(GlobalPoint) const
tuple out
Definition: dbtoconf.py:99
void startNewSimHit(std::string)
void printEloss(float) const
void printId(int) const
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
T x() const
Definition: PV3DBase.h:62