ECCE @ EIC 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 
50 using namespace std;
51 
53  : SubsysReco("PHG4InttDeadMapLoader_" + detector)
54  , m_detector(detector)
55 {
56 }
57 
59 {
60 }
61 
63 {
64  PHNodeIterator topiter(topNode);
65  PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(topiter.findFirst("PHCompositeNode", "RUN"));
66  if (!runNode)
67  {
68  std::cerr << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__
69  << "Run Node missing, doing nothing." << std::endl;
70  throw std::runtime_error("Failed to find Run node in RawTowerCalibration::CreateNodes");
71  }
72 
73  // Create the tower nodes on the tree
74  PHNodeIterator dstiter(runNode);
75  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", m_detector));
76  if (!DetNode)
77  {
78  DetNode = new PHCompositeNode(m_detector);
79  runNode->addNode(DetNode);
80  }
81 
82  // Be careful as a previous calibrator may have been registered for this detector
83  string deadMapName = "DEADMAP_" + m_detector;
84  InttDeadMap *deadmap = findNode::getClass<InttDeadMapv1>(DetNode, deadMapName);
85  if (!deadmap)
86  {
87  deadmap = new InttDeadMapv1();
88  PHIODataNode<PHObject> *towerNode = new PHIODataNode<PHObject>(deadmap, deadMapName, "PHObject");
89  DetNode->addNode(towerNode);
90  }
91 
92  assert(deadmap);
93 
94  for (const auto& pathiter : m_deadMapPathMap)
95  {
96  const unsigned int ilayer = pathiter.first;
97  const string &deadMapPath = pathiter.second;
98 
99  int counter = 0;
100 
101  PHParameters deadMapParam(m_detector);
102  deadMapParam.ReadFromFile(m_detector, "xml", 0, 0, deadMapPath);
103 
104  const auto in_par_ranges = deadMapParam.get_all_int_params();
105 
106  for (auto iter = in_par_ranges.first; iter != in_par_ranges.second; ++iter)
107  {
108  const string &deadChanName = iter->first;
109 
110  if (Verbosity())
111  {
112  cout << "HG4InttDeadMapLoader::InitRun - deadMapParam[" << deadChanName << "] = " << iter->second << ": ";
113  }
114 
115  boost::char_separator<char> sep("_");
116  boost::tokenizer<boost::char_separator<char> > tok(deadChanName, sep);
117  boost::tokenizer<boost::char_separator<char> >::const_iterator tokeniter;
118 
119  for (tokeniter = tok.begin(); tokeniter != tok.end(); ++tokeniter)
120  {
121  if (*tokeniter == "INTT")
122  {
123  // Form("INTT_%d_%d_%d_%d", ladder_phi, ladder_z, strip_z, strip_phi)
124 
125  ++tokeniter;
126  assert(tokeniter != tok.end());
127  int ladder_phi = boost::lexical_cast<int>(*tokeniter);
128 
129  ++tokeniter;
130  assert(tokeniter != tok.end());
131  int ladder_z = boost::lexical_cast<int>(*tokeniter);
132 
133  ++tokeniter;
134  assert(tokeniter != tok.end());
135  int strip_z = boost::lexical_cast<int>(*tokeniter);
136 
137  ++tokeniter;
138  assert(tokeniter != tok.end());
139  int strip_phi = boost::lexical_cast<int>(*tokeniter);
140 
141  deadmap->addDeadChannelIntt(ilayer, ladder_phi, ladder_z, strip_z, strip_phi);
142  ++counter;
143 
144  if (Verbosity())
145  {
146  cout << "add Intt dead channel ladder_phi" << ladder_phi << " ladder_z" << ladder_z
147  << " strip_z" << strip_z << " strip_phi" << strip_phi;
148  }
149  } // if (*tokeniter == "INTT")
150  else
151  {
152  if (Verbosity())
153  {
154  cout << "skip " << deadChanName;
155  }
156  }
157 
158  } // for (tokeniter = tok.begin(); tokeniter != tok.end(); ++tokeniter)
159 
160  if (Verbosity())
161  {
162  cout << endl;
163  }
164 
165  } // for (const auto iter = in_par_ranges.first; iter != in_par_ranges.second; ++iter)
166 
167  cout << "PHG4InttDeadMapLoader::" << m_detector << "::InitRun - loading " << counter << " dead channel for layer "
168  << ilayer << " from " << deadMapPath << ". Total dead chan = " << deadmap->size() << endl;
169  }
170 
171  if (Verbosity())
172  {
173  cout << "PHG4InttDeadMapLoader::" << m_detector << "::InitRun - loading dead map completed : ";
174  deadmap->identify();
175  }
177 }