FdChannelMappingManager.cc
Go to the documentation of this file.
1 
9 #include <sstream>
10 #include <string>
11 #include <set>
12 #include <map>
13 #include <utility>
14 #include <algorithm>
15 
16 #include <boost/lexical_cast.hpp>
17 
18 #include <utl/Reader.h>
19 #include <utl/TimeStamp.h>
20 #include <utl/ErrorLogger.h>
21 #include <utl/AugerException.h>
22 
23 #include <fwk/CentralConfig.h>
24 
25 #include <det/Detector.h>
26 #include <det/ValidityStamp.h>
27 
28 #include <fdet/FDetector.h>
29 #include <fdet/FdChannelMappingManager.h>
30 
31 #include <TFile.h>
32 #include <TTree.h>
33 #include <TDirectory.h>
34 
35 using namespace fwk;
36 using namespace det;
37 using namespace fdet;
38 using namespace utl;
39 using namespace std;
40 
41 
42 REGISTER_F_MANAGER("FdChannelMappingManager", FdChannelMappingManager);
43 
44 
45 FdChannelMappingManager::FdChannelMappingManager()
46 { }
47 
48 
49 FdChannelMappingManager::~FdChannelMappingManager()
50 { }
51 
52 
53 void
54 FdChannelMappingManager::Init(const std::string& configLink)
55 {
56  VManager::Init(configLink);
57 
58  // parse XML
59  if (!FillMaps()) {
60  ERROR_TERSE("error during init!");
61  throw(NoDataForModelException("FdChannelMappingManager"));
62  }
63 
64  // list of properties
65  fPropertiesList.insert("channel_mapping");
66  fPropertiesList.insert("pixel_mapping");
67 }
68 
69 
71 FdChannelMappingManager::GetMapping(int& returnData,
72  const string& componentProperty,
73  const string& componentName,
74  const IndexMap& componentIndex)
75  const
76 {
77  // check component availability
78  if (componentName != "electronics")
79  return eNotFound;
80 
81  // check property availability
82  if (fPropertiesList.find(componentProperty) == fPropertiesList.end())
83  return eNotFound;
84 
85  // check size of index map
86  if (componentIndex.size() != 3)
87  return eNotFound;
88 
89  // retrive the component indices
90  const IndexMap::const_iterator iEyeId =
91  componentIndex.find("eyeId");
92  const IndexMap::const_iterator iTelId =
93  componentIndex.find("telescopeId");
94  if (iEyeId == componentIndex.end() || iTelId == componentIndex.end()) {
95  INFO("Called FdChannelMappingManager with wrong number of arguments!");
96  return eNotFound;
97  }
98 
99  const int eyeId = boost::lexical_cast<int>(iEyeId->second);
100  const int telId = boost::lexical_cast<int>(iTelId->second);
101  const int indexEyeTel = eyeId*6*440 + telId*440;
102 
103  IndexMap::const_iterator iId;
104  if (componentProperty == "channel_mapping")
105  iId = componentIndex.find("channelId");
106  else if (componentProperty == "pixel_mapping")
107  iId = componentIndex.find("pixelId");
108  else {
109  INFO("Called FdChannelMappingManager with missing pixelId/channelId!");
110  return eNotFound;
111  }
112  const int id = boost::lexical_cast<int>(iId->second);
113  const int dataId = indexEyeTel + id;
114 
115  returnData = id; // default return is pixelid=chanelId
116 
117  for (ConstPeriodIterator iPeriod = fPeriods.begin();
118  iPeriod != fPeriods.end(); ++iPeriod) {
119 
120  if (!iPeriod->validity.IsValid())
121  continue;
122 
123  if (componentProperty == "channel_mapping") {
124  const Mapping& channelMapping = iPeriod->channels;
125  const map<int, int>::const_iterator iMapping =
126  channelMapping.find(dataId);
127  if (iMapping != channelMapping.end()) {
128  returnData = iMapping->second; // REMAP
129  break;
130  }
131  }
132 
133  if (componentProperty == "pixel_mapping") {
134  const Mapping& pixelMapping = iPeriod->pixels;
135  const map<int, int>::const_iterator iMapping =
136  pixelMapping.find(dataId);
137  if (iMapping != pixelMapping.end()) {
138  returnData = iMapping->second;
139  break;
140  }
141  }
142 
143  }
144 
145  return eFound;
146 }
147 
148 
149 
150 bool
151 FdChannelMappingManager::FillMaps()
152 {
153  fPeriods.clear();
154 
155  Branch topB =
156  fwk::CentralConfig::GetInstance()->GetTopBranch("FdChannelMappingManager");
157 
158  for (Branch cB = topB.GetFirstChild(); cB; cB = cB.GetNextSibling()) {
159 
160  int eyeId;
161  cB.GetChild("eye").GetData(eyeId);
162  int telId;
163  cB.GetChild("telescope").GetData(telId);
164  const int indexEyeTel = eyeId*6*440 + telId*440;
165  utl::TimeStamp begin;
166  cB.GetChild("begin").GetData(begin);
167  utl::TimeStamp end;
168  cB.GetChild("end").GetData(end);
169  det::ValidityStamp validity(begin, end);
170 
171  Mapping pixelMapping;
172  Mapping channelMapping;
173 
174  for (Branch b = cB.GetChild("mapping").GetFirstChild();
175  b; b = b.GetNextSibling()) {
176 
177  const AttributeMap atts = b.GetAttributes();
178  const int pixelId = boost::lexical_cast<int>(atts.find("id")->second);
179 
180  int channelId;
181  b.GetChild("channel").GetData(channelId);
182 
183  // check for double existence of pixels/channels
184  if (pixelMapping.count(indexEyeTel + pixelId) ||
185  channelMapping.count(indexEyeTel + channelId)) {
186  ERROR_TERSE("double existance of pixels/channels");
187  return false;
188  }
189 
190  pixelMapping[indexEyeTel + pixelId] = channelId;
191  channelMapping[indexEyeTel + channelId] = pixelId;
192 
193  }
194 
195  // consitency check
196  for (ConstMappingIterator iPixel = pixelMapping.begin();
197  iPixel != pixelMapping.end(); ++iPixel) {
198 
199  // check if each pixel has a channel (nothing is lost)
200  const int pixelId = iPixel->first;
201  ConstMappingIterator iChannel = channelMapping.find(pixelId);
202  if (iChannel == channelMapping.end()) {
203  ERROR_TERSE("Wrong pixel mapping!");
204  return false;
205  }
206  }
207 
208  Period mappingPeriod;
209  mappingPeriod.validity = validity;
210  mappingPeriod.pixels = pixelMapping;
211  mappingPeriod.channels = channelMapping;
212  fPeriods.push_back(mappingPeriod);
213 
214  }
215 
216  return true;
217 }
218 
219 
220 // Configure (x)emacs for this file ...
221 // Local Variables:
222 // mode: c++
223 // compile-command: "make -C .. -k"
224 // End:
std::map< std::string, std::string > AttributeMap
Definition: Branch.h:24
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
Class to manage Fd camera channel-pixel mapping.
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
Exception to use in a atmosphere model cannot find data it needs.
Mapping::const_iterator ConstMappingIterator
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
Class representing a document branch.
Definition: Branch.h:107
#define ERROR_TERSE(message)
Macro for logging error messages.
Definition: ErrorLogger.h:179
PeriodContainer::const_iterator ConstPeriodIterator
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
#define REGISTER_F_MANAGER(_name_, _Type_)
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
Object to keep track of whether data are valid, or have expired.
Definition: ValidityStamp.h:29
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.