MDetector.cc
Go to the documentation of this file.
1 #include <mdet/MDetector.h>
2 
3 #include <utl/ErrorLogger.h>
4 
5 #include <algorithm>
6 
7 #include <boost/lambda/lambda.hpp>
8 #include <boost/lambda/bind.hpp>
9 
10 namespace mdet {
11 
12  void
13  MDetector::Update(bool invalidateData, bool invalidateComponents)
14  {
16  // Being the root of the hierarchy leave it empty.
17  // From there the actual loading gets triggered down
18  // the hierarchy.
19  fCounters.Update(m, invalidateData, invalidateComponents);
20  }
21 
22  int
24  const
25  {
26  // Assume non-null: user must call previously 'Exists' method.
27  return *LookUpAssociatedCounter(tankId);
28  }
29 
30  bool
32  const
33  {
34  return LookUpAssociatedCounter(tankId);
35  }
36 
37  const int *
39  const
40  {
41  AssociationMap::const_iterator cacheIt = fAssociatedCountersIds.find(tankId);
42  if (cacheIt != fAssociatedCountersIds.end()) {
43  // Access to the raw pointer.
44  // Note: Get it's an specific method from the wrapping class,
45  // other similar classes with the same wrapping purpose may
46  // have the same method, or maybe in lowercase get.
47  return cacheIt->second.Get();
48  }
49  // First time query for this tank: update the cache.
50  // Linear search among _all_ for the counter associated with the given tank.
53  CounterConstIterator i = std::find_if(beg, end,
54  boost::lambda::bind(&Counter::GetAssociatedTankId, boost::lambda::_1)
55  == tankId);
56  // Retrieve the id if it exists or use a null pointer instead.
57  int* const res = i != end ? new int(i->GetId()) : 0;
58  /*
59  * Wrap the raw pointer constructing an object
60  * of the actual mapped type, then update the
61  * cache.
62  */
63  AssociationMap::mapped_type p(res);
64  fAssociatedCountersIds[ tankId ] = p;
65  return res;
66  }
67 
68 }
CounterGroup fCounters
The child components.
Definition: MDetector.h:149
AssociationMap fAssociatedCountersIds
Cache of ids.
Definition: MDetector.h:178
const int * LookUpAssociatedCounter(int tankId) const
Resolve a pointer to the counter id.
Definition: MDetector.cc:38
int GetAssociatedTankId() const
Retrieve the id of the associated surface tank.
CounterConstIterator AllCountersBegin() const
Begin iterator over all the counters.
Definition: MDetector.h:80
bool ExistsAssociatedCounter(int tankId) const
Tells whether there&#39;s an associated counter for a sdet::Station.
Definition: MDetector.cc:31
CounterGroup::ConstIterator CounterConstIterator
Defines a more meaningful (and shorter) type for iterators.
Definition: MDetector.h:44
CounterConstIterator AllCountersEnd() const
End iterator over all the counters.
Definition: MDetector.h:86
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
int GetAssociatedCounterId(int tankId) const
Resolve the associated counter given an id for a sdet::Station.
Definition: MDetector.cc:23
constexpr double m
Definition: AugerUnits.h:121
void Update(bool invalidateData=true, bool invalidateComponents=true)
Perform detector update.
Definition: MDetector.cc:13

, generated on Tue Sep 26 2023.