forked from sPHENIX-Collaboration/coresoftware
/
PHG4InttDeadMapLoader.cc
177 lines (143 loc) · 5.43 KB
/
PHG4InttDeadMapLoader.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// $Id: $
/*!
* \file PHG4InttDeadMapLoader.cc
* \brief
* \author Jin Huang <jhuang@bnl.gov>
* \version $Revision: $
* \date $Date: $
*/
#include "PHG4InttDeadMapLoader.h"
#include "InttDeadMap.h" // for InttDeadMap
#include "InttDeadMapv1.h"
#include <phparameter/PHParameters.h>
#include <fun4all/Fun4AllReturnCodes.h>
#include <fun4all/SubsysReco.h> // for SubsysReco
#include <phool/PHCompositeNode.h>
#include <phool/PHIODataNode.h>
#include <phool/PHNode.h> // for PHNode
#include <phool/PHNodeIterator.h>
#include <phool/PHObject.h> // for PHObject
#include <phool/getClass.h>
// boost headers
#include <boost/tokenizer.hpp>
// this is an ugly hack, the gcc optimizer has a bug which
// triggers the uninitialized variable warning which
// stops compilation because of our -Werror
#include <boost/version.hpp> // to get BOOST_VERSION
#if (__GNUC__ == 4 && __GNUC_MINOR__ == 4 && BOOST_VERSION == 105700)
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma message "ignoring bogus gcc warning in boost header lexical_cast.hpp"
#include <boost/lexical_cast.hpp>
#pragma GCC diagnostic warning "-Wuninitialized"
#else
#include <boost/lexical_cast.hpp>
#endif
#include <cassert>
#include <iostream>
#include <map>
#include <stdexcept>
#include <string>
#include <utility> // for pair
using namespace std;
PHG4InttDeadMapLoader::PHG4InttDeadMapLoader(const std::string &detector)
: SubsysReco("PHG4InttDeadMapLoader_" + detector)
, m_detector(detector)
{
}
PHG4InttDeadMapLoader::~PHG4InttDeadMapLoader()
{
}
int PHG4InttDeadMapLoader::InitRun(PHCompositeNode *topNode)
{
PHNodeIterator topiter(topNode);
PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(topiter.findFirst("PHCompositeNode", "RUN"));
if (!runNode)
{
std::cerr << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__
<< "Run Node missing, doing nothing." << std::endl;
throw std::runtime_error("Failed to find Run node in RawTowerCalibration::CreateNodes");
}
// Create the tower nodes on the tree
PHNodeIterator dstiter(runNode);
PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", m_detector));
if (!DetNode)
{
DetNode = new PHCompositeNode(m_detector);
runNode->addNode(DetNode);
}
// Be careful as a previous calibrator may have been registered for this detector
string deadMapName = "DEADMAP_" + m_detector;
InttDeadMap *deadmap = findNode::getClass<InttDeadMapv1>(DetNode, deadMapName);
if (!deadmap)
{
deadmap = new InttDeadMapv1();
PHIODataNode<PHObject> *towerNode = new PHIODataNode<PHObject>(deadmap, deadMapName, "PHObject");
DetNode->addNode(towerNode);
}
assert(deadmap);
for (const auto& pathiter : m_deadMapPathMap)
{
const unsigned int ilayer = pathiter.first;
const string &deadMapPath = pathiter.second;
int counter = 0;
PHParameters deadMapParam(m_detector);
deadMapParam.ReadFromFile(m_detector, "xml", 0, 0, deadMapPath);
const auto in_par_ranges = deadMapParam.get_all_int_params();
for (auto iter = in_par_ranges.first; iter != in_par_ranges.second; ++iter)
{
const string &deadChanName = iter->first;
if (Verbosity())
{
cout << "HG4InttDeadMapLoader::InitRun - deadMapParam[" << deadChanName << "] = " << iter->second << ": ";
}
boost::char_separator<char> sep("_");
boost::tokenizer<boost::char_separator<char> > tok(deadChanName, sep);
boost::tokenizer<boost::char_separator<char> >::const_iterator tokeniter;
for (tokeniter = tok.begin(); tokeniter != tok.end(); ++tokeniter)
{
if (*tokeniter == "INTT")
{
// Form("INTT_%d_%d_%d_%d", ladder_phi, ladder_z, strip_z, strip_phi)
++tokeniter;
assert(tokeniter != tok.end());
int ladder_phi = boost::lexical_cast<int>(*tokeniter);
++tokeniter;
assert(tokeniter != tok.end());
int ladder_z = boost::lexical_cast<int>(*tokeniter);
++tokeniter;
assert(tokeniter != tok.end());
int strip_z = boost::lexical_cast<int>(*tokeniter);
++tokeniter;
assert(tokeniter != tok.end());
int strip_phi = boost::lexical_cast<int>(*tokeniter);
deadmap->addDeadChannelIntt(ilayer, ladder_phi, ladder_z, strip_z, strip_phi);
++counter;
if (Verbosity())
{
cout << "add Intt dead channel ladder_phi" << ladder_phi << " ladder_z" << ladder_z
<< " strip_z" << strip_z << " strip_phi" << strip_phi;
}
} // if (*tokeniter == "INTT")
else
{
if (Verbosity())
{
cout << "skip " << deadChanName;
}
}
} // for (tokeniter = tok.begin(); tokeniter != tok.end(); ++tokeniter)
if (Verbosity())
{
cout << endl;
}
} // for (const auto iter = in_par_ranges.first; iter != in_par_ranges.second; ++iter)
cout << "PHG4InttDeadMapLoader::" << m_detector << "::InitRun - loading " << counter << " dead channel for layer "
<< ilayer << " from " << deadMapPath << ". Total dead chan = " << deadmap->size() << endl;
}
if (Verbosity())
{
cout << "PHG4InttDeadMapLoader::" << m_detector << "::InitRun - loading dead map completed : ";
deadmap->identify();
}
return Fun4AllReturnCodes::EVENT_OK;
}