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