File indexing completed on 2025-08-05 08:18:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "PHG4InttDeadMapLoader.h"
0012
0013 #include "InttDeadMap.h" // for InttDeadMap
0014 #include "InttDeadMapv1.h"
0015
0016 #include <phparameter/PHParameters.h>
0017
0018 #include <fun4all/Fun4AllReturnCodes.h>
0019 #include <fun4all/SubsysReco.h> // for SubsysReco
0020
0021 #include <phool/PHCompositeNode.h>
0022 #include <phool/PHIODataNode.h>
0023 #include <phool/PHNode.h> // for PHNode
0024 #include <phool/PHNodeIterator.h>
0025 #include <phool/PHObject.h> // for PHObject
0026 #include <phool/getClass.h>
0027
0028
0029 #include <boost/tokenizer.hpp>
0030
0031
0032
0033 #include <boost/version.hpp> // to get BOOST_VERSION
0034 #if (__GNUC__ == 4 && __GNUC_MINOR__ == 4 && BOOST_VERSION == 105700)
0035 #pragma GCC diagnostic ignored "-Wuninitialized"
0036 #pragma message "ignoring bogus gcc warning in boost header lexical_cast.hpp"
0037 #include <boost/lexical_cast.hpp>
0038 #pragma GCC diagnostic warning "-Wuninitialized"
0039 #else
0040 #include <boost/lexical_cast.hpp>
0041 #endif
0042
0043 #include <cassert>
0044 #include <iostream>
0045 #include <map>
0046 #include <stdexcept>
0047 #include <string>
0048 #include <utility> // for pair
0049
0050 PHG4InttDeadMapLoader::PHG4InttDeadMapLoader(const std::string &detector)
0051 : SubsysReco("PHG4InttDeadMapLoader_" + detector)
0052 , m_detector(detector)
0053 {
0054 }
0055
0056 int PHG4InttDeadMapLoader::InitRun(PHCompositeNode *topNode)
0057 {
0058 PHNodeIterator topiter(topNode);
0059 PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(topiter.findFirst("PHCompositeNode", "RUN"));
0060 if (!runNode)
0061 {
0062 std::cout << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__
0063 << "Run Node missing, doing nothing." << std::endl;
0064 throw std::runtime_error("Failed to find Run node in RawTowerCalibration::CreateNodes");
0065 }
0066
0067
0068 PHNodeIterator dstiter(runNode);
0069 PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", m_detector));
0070 if (!DetNode)
0071 {
0072 DetNode = new PHCompositeNode(m_detector);
0073 runNode->addNode(DetNode);
0074 }
0075
0076
0077 std::string deadMapName = "DEADMAP_" + m_detector;
0078 InttDeadMap *deadmap = findNode::getClass<InttDeadMapv1>(DetNode, deadMapName);
0079 if (!deadmap)
0080 {
0081 deadmap = new InttDeadMapv1();
0082 PHIODataNode<PHObject> *towerNode = new PHIODataNode<PHObject>(deadmap, deadMapName, "PHObject");
0083 DetNode->addNode(towerNode);
0084 }
0085
0086 assert(deadmap);
0087
0088 for (const auto &pathiter : m_deadMapPathMap)
0089 {
0090 const unsigned int ilayer = pathiter.first;
0091 const std::string &deadMapPath = pathiter.second;
0092
0093 int counter = 0;
0094
0095 PHParameters deadMapParam(m_detector);
0096 deadMapParam.ReadFromFile(m_detector, "xml", 0, 0, deadMapPath);
0097
0098 const auto in_par_ranges = deadMapParam.get_all_int_params();
0099
0100 for (auto iter = in_par_ranges.first; iter != in_par_ranges.second; ++iter)
0101 {
0102 const std::string &deadChanName = iter->first;
0103
0104 if (Verbosity())
0105 {
0106 std::cout << "HG4InttDeadMapLoader::InitRun - deadMapParam[" << deadChanName << "] = " << iter->second << ": ";
0107 }
0108
0109 boost::char_separator<char> sep("_");
0110 boost::tokenizer<boost::char_separator<char> > tok(deadChanName, sep);
0111 boost::tokenizer<boost::char_separator<char> >::const_iterator tokeniter;
0112
0113 for (tokeniter = tok.begin(); tokeniter != tok.end(); ++tokeniter)
0114 {
0115 if (*tokeniter == "INTT")
0116 {
0117
0118
0119 ++tokeniter;
0120 assert(tokeniter != tok.end());
0121 int ladder_phi = boost::lexical_cast<int>(*tokeniter);
0122
0123 ++tokeniter;
0124 assert(tokeniter != tok.end());
0125 int ladder_z = boost::lexical_cast<int>(*tokeniter);
0126
0127 ++tokeniter;
0128 assert(tokeniter != tok.end());
0129 int strip_z = boost::lexical_cast<int>(*tokeniter);
0130
0131 ++tokeniter;
0132 assert(tokeniter != tok.end());
0133 int strip_phi = boost::lexical_cast<int>(*tokeniter);
0134
0135 deadmap->addDeadChannelIntt(ilayer, ladder_phi, ladder_z, strip_z, strip_phi);
0136 ++counter;
0137
0138 if (Verbosity())
0139 {
0140 std::cout << "add Intt dead channel ladder_phi" << ladder_phi << " ladder_z" << ladder_z
0141 << " strip_z" << strip_z << " strip_phi" << strip_phi;
0142 }
0143 }
0144 else
0145 {
0146 if (Verbosity())
0147 {
0148 std::cout << "skip " << deadChanName;
0149 }
0150 }
0151
0152 }
0153
0154 if (Verbosity())
0155 {
0156 std::cout << std::endl;
0157 }
0158
0159 }
0160
0161 std::cout << "PHG4InttDeadMapLoader::" << m_detector << "::InitRun - loading " << counter << " dead channel for layer "
0162 << ilayer << " from " << deadMapPath << ". Total dead chan = " << deadmap->size() << std::endl;
0163 }
0164
0165 if (Verbosity())
0166 {
0167 std::cout << "PHG4InttDeadMapLoader::" << m_detector << "::InitRun - loading dead map completed : ";
0168 deadmap->identify();
0169 }
0170 return Fun4AllReturnCodes::EVENT_OK;
0171 }