26{
27 std::map<uint64_t, uint64_t> cellId_vs_cellHashId_map;
28
29 std::unique_ptr<std::istream> hashStream{};
30 std::unique_ptr<std::streambuf> hashStreamBuf{};
31#ifdef ENABLE_XROOTD_SUPPORT
32 if (hashFileName.find("root://") != std::string::npos) {
33 hashStreamBuf = std::make_unique<XrdStreamBuf>(hashFileName);
34 hashStream = std::make_unique<std::istream>(hashStreamBuf.get());
35 } else {
36#endif
37 std::unique_ptr<std::ifstream> hashStreamDirect = std::make_unique<std::ifstream>(hashFileName);
38 if (!hashStreamDirect->is_open()) {
39 std::cout << "Error: Could not open " << hashFileName << std::endl;
40 throw std::runtime_error("Could not open file");
41 }
42 hashStream = std::move(hashStreamDirect);
43#ifdef ENABLE_XROOTD_SUPPORT
44 }
45#endif
46
47 std::cout << "Loading cellId_vs_cellHashId_map" << std::endl;
48
51 while (!hashStream->eof()) {
53
54 *hashStream >> id >> hash_id;
55 cellId_vs_cellHashId_map[
id] = hash_id;
56 if (i % 10000 == 0)
57 std::cout <<
"Line: " <<
i <<
" id " << std::hex <<
id <<
" hash_id "
58 << std::dec << hash_id << std::endl;
59 }
60
61 std::cout << "Done." << std::endl;
62
63 auto f = std::unique_ptr<TFile>(TFile::Open(
fileName.c_str()));
64 if (!f) {
65 std::cerr <<
"Error: Could not open file '" <<
fileName <<
"'" << std::endl;
66 return false;
67 }
70 return false;
71
73
74 CaloDetDescrElement
cell;
75
76
77 TBranch *b_identifier;
78 TBranch *b_calosample;
79 TBranch *b_eta;
80 TBranch *b_phi;
81 TBranch *b_r;
82 TBranch *b_eta_raw;
83 TBranch *b_phi_raw;
84 TBranch *b_r_raw;
85 TBranch *b_x;
86 TBranch *b_y;
87 TBranch *b_z;
88 TBranch *b_x_raw;
89 TBranch *b_y_raw;
90 TBranch *b_z_raw;
91 TBranch *b_deta;
92 TBranch *b_dphi;
93 TBranch *b_dr;
94 TBranch *b_dx;
95 TBranch *b_dy;
96 TBranch *b_dz;
97
98 fChain->SetMakeClass(1);
99 fChain->SetBranchAddress(
"identifier", &
cell.m_identify, &b_identifier);
100 fChain->SetBranchAddress(
"calosample", &
cell.m_calosample, &b_calosample);
101 fChain->SetBranchAddress(
"eta", &
cell.m_eta, &b_eta);
102 fChain->SetBranchAddress(
"phi", &
cell.m_phi, &b_phi);
103 fChain->SetBranchAddress(
"r", &
cell.m_r, &b_r);
104 fChain->SetBranchAddress(
"eta_raw", &
cell.m_eta_raw, &b_eta_raw);
105 fChain->SetBranchAddress(
"phi_raw", &
cell.m_phi_raw, &b_phi_raw);
106 fChain->SetBranchAddress(
"r_raw", &
cell.m_r_raw, &b_r_raw);
107 fChain->SetBranchAddress(
"x", &
cell.m_x, &b_x);
108 fChain->SetBranchAddress(
"y", &
cell.m_y, &b_y);
109 fChain->SetBranchAddress(
"z", &
cell.m_z, &b_z);
110 fChain->SetBranchAddress(
"x_raw", &
cell.m_x_raw, &b_x_raw);
111 fChain->SetBranchAddress(
"y_raw", &
cell.m_y_raw, &b_y_raw);
112 fChain->SetBranchAddress(
"z_raw", &
cell.m_z_raw, &b_z_raw);
113 fChain->SetBranchAddress(
"deta", &
cell.m_deta, &b_deta);
114 fChain->SetBranchAddress(
"dphi", &
cell.m_dphi, &b_dphi);
115 fChain->SetBranchAddress(
"dr", &
cell.m_dr, &b_dr);
116 fChain->SetBranchAddress(
"dx", &
cell.m_dx, &b_dx);
117 fChain->SetBranchAddress(
"dy", &
cell.m_dy, &b_dy);
118 fChain->SetBranchAddress(
"dz", &
cell.m_dz, &b_dz);
119
120 Long64_t
nentries = fChain->GetEntriesFast();
121 for (Long64_t jentry = 0; jentry <
nentries; jentry++) {
122 Long64_t ientry = fChain->LoadTree(jentry);
123 if (ientry < 0)
124 break;
125 fChain->GetEntry(jentry);
126
127 if (cellId_vs_cellHashId_map.find(
cell.m_identify)
128 != cellId_vs_cellHashId_map.end()) {
129 cell.m_hash_id = cellId_vs_cellHashId_map[
cell.m_identify];
130 if (
cell.m_hash_id != jentry)
131 std::cout << jentry <<
" : ERROR hash=" <<
cell.m_hash_id << std::endl;
132 } else
133 std::cout << std::endl
134 << "ERROR: Cell id not found in the cellId_vs_cellHashId_map!!!"
135 << std::endl
136 << std::endl;
137
138 const CaloDetDescrElement *pcell = new CaloDetDescrElement(cell);
140
141 if (jentry % 25000 == 0) {
142 std::cout << "Checking loading cells from file" << std::endl
145
146 }
147 }
148
151
152 std::cout << "Result of PostProcessGeometry(): " << ok << std::endl;
153
154 const CaloDetDescrElement *
mcell = 0;
155 unsigned long long cellid64(3179554531063103488);
156 Identifier cellid(cellid64);
158
159 std::cout << "\n \n";
160 std::cout << "Testing whether CaloGeoGeometry is loaded properly"
161 << std::endl;
162 if (!mcell) {
163 std::cout << "Cell is not found" << std::endl;
164 }
165 else {
166 std::cout <<
"Identifier " <<
mcell->identify() <<
" sampling "
167 <<
mcell->getSampling() <<
" eta: " <<
mcell->eta()
168 <<
" phi: " <<
mcell->phi() <<
" CaloDetDescrElement=" <<
mcell
169 << std::endl
170 << std::endl;
171
172 const CaloDetDescrElement *mcell2
174 std::cout <<
"Identifier " << mcell2->
identify() <<
" sampling "
176 <<
" phi: " << mcell2->
phi() <<
" CaloDetDescrElement=" << mcell2
177 << std::endl
178 << std::endl;
179 }
180
181 return ok;
182}
Identifier identify() const override final
cell identifier
virtual bool PostProcessGeometry()
virtual void addcell(const CaloDetDescrElement *cell)