ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawTowerDeadMapLoader.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawTowerDeadMapLoader.cc
1 // $Id: $
2 
11 #include "RawTowerDeadMapLoader.h"
12 
13 #include <calobase/RawTowerDeadMap.h>
14 #include <calobase/RawTowerDeadMapv1.h>
15 #include <calobase/RawTowerDefs.h>
16 
17 #include <phparameter/PHParameters.h>
18 
20 #include <fun4all/SubsysReco.h>
21 
22 #include <phool/PHCompositeNode.h>
23 #include <phool/PHIODataNode.h>
24 #include <phool/PHNode.h>
25 #include <phool/PHNodeIterator.h>
26 #include <phool/PHObject.h>
27 #include <phool/getClass.h>
28 
29 // boost headers
30 #include <boost/token_iterator.hpp> // for token_iterator
31 #include <boost/tokenizer.hpp>
32 // this is an ugly hack, the gcc optimizer has a bug which
33 // triggers the uninitialized variable warning which
34 // stops compilation because of our -Werror
35 #include <boost/version.hpp> // to get BOOST_VERSION
36 #if (__GNUC__ == 4 && __GNUC_MINOR__ == 4 && BOOST_VERSION == 105700)
37 #pragma GCC diagnostic ignored "-Wuninitialized"
38 #pragma message "ignoring bogus gcc warning in boost header lexical_cast.hpp"
39 #include <boost/lexical_cast.hpp>
40 #pragma GCC diagnostic warning "-Wuninitialized"
41 #else
42 #include <boost/lexical_cast.hpp>
43 #endif
44 
45 #include <cassert>
46 #include <iostream>
47 #include <map>
48 #include <stdexcept>
49 #include <string>
50 #include <utility>
51 
52 using namespace std;
53 
55  : SubsysReco("RawTowerDeadMapLoader_" + detector)
56  , m_detector(detector)
57 {
58 }
59 
61 {
62  PHNodeIterator iter(topNode);
63  PHCompositeNode *runNode = static_cast<PHCompositeNode *>(iter.findFirst(
64  "PHCompositeNode", "RUN"));
65  if (!runNode)
66  {
67  std::cerr << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__
68  << "Run Node missing, doing nothing." << std::endl;
69  throw std::runtime_error(
70  "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(
76  "PHCompositeNode", m_detector));
77  if (!DetNode)
78  {
79  DetNode = new PHCompositeNode(m_detector);
80  runNode->addNode(DetNode);
81  }
82 
83  // Be careful as a previous calibrator may have been registered for this detector
84  string deadMapName = "DEADMAP_" + m_detector;
85  RawTowerDeadMap *m_deadmap = findNode::getClass<RawTowerDeadMapv1>(DetNode, deadMapName);
86  if (!m_deadmap)
87  {
89 
90  m_deadmap = new RawTowerDeadMapv1(caloid);
92  m_deadmap, deadMapName, "PHObject");
93  DetNode->addNode(towerNode);
94  }
95 
96  assert(m_deadmap);
97 
98  cout << "RawTowerDeadMapLoader::" << m_detector << "::InitRun - loading dead map from " << m_deadMapPath << endl;
99 
100  PHParameters deadMapParam(m_detector);
101  deadMapParam.ReadFromFile(m_detector, "xml", 0, 0, m_deadMapPath);
102 
103  const auto in_par_ranges = deadMapParam.get_all_int_params();
104 
105  for (auto iter = in_par_ranges.first; iter != in_par_ranges.second; ++iter)
106  {
107  const string &deadChanName = iter->first;
108 
109  if (Verbosity())
110  {
111  cout << "deadMapParam[" << deadChanName << "] = " << iter->second << ": ";
112  }
113 
114  boost::char_separator<char> sep("_");
115  boost::tokenizer<boost::char_separator<char> > tok(deadChanName, sep);
116  boost::tokenizer<boost::char_separator<char> >::const_iterator tokeniter;
117 
118  for (tokeniter = tok.begin(); tokeniter != tok.end(); ++tokeniter)
119  {
120  if (*tokeniter == "deadtower")
121  {
122  // Form("deadtower_eta_%d_phi_%d", eta, phi)
123 
124  ++tokeniter;
125  assert(tokeniter != tok.end());
126 
127  if (*tokeniter == "eta")
128  {
129  ++tokeniter;
130  assert(tokeniter != tok.end());
131  const int eta = boost::lexical_cast<int>(*tokeniter);
132 
133  ++tokeniter;
134  assert(tokeniter != tok.end());
135  assert(*tokeniter == "phi");
136 
137  ++tokeniter;
138  assert(tokeniter != tok.end());
139  const int phi = boost::lexical_cast<int>(*tokeniter);
140 
141  m_deadmap->addDeadTower(eta, phi);
142 
143  if (Verbosity())
144  {
145  cout << "add dead channel eta" << eta << " phi" << phi;
146  }
147  } // if (*tokeniter == "eta")
148  else
149  {
150  if (Verbosity())
151  {
152  cout << "skip " << deadChanName;
153  }
154  }
155 
156  } // if (*tokeniter == "deadtower")
157  else
158  {
159  if (Verbosity())
160  {
161  cout << "skip " << deadChanName;
162  }
163  }
164 
165  } // for (tokeniter = tok.begin(); tokeniter != tok.end(); ++tokeniter)
166 
167  if (Verbosity())
168  {
169  cout << endl;
170  }
171 
172  } // for (const auto iter = in_par_ranges.first; iter != in_par_ranges.second; ++iter)
173 
174  if (Verbosity())
175  {
176  cout << "RawTowerDeadMapLoader::" << m_detector << "::InitRun - loading dead map completed : ";
177  m_deadmap->identify();
178  }
180 }