1 #ifndef _det_ComponentGroup_h
2 #define _det_ComponentGroup_h
4 #include <det/VManager.h>
5 #include <det/DetectorComponent.h>
6 #include <utl/ErrorLogger.h>
16 #include <boost/ptr_container/ptr_map.hpp>
17 #include <boost/iterator/transform_iterator.hpp>
47 template<
class Parent,
class Child>
49 {
return new Child(
id); }
64 template<
class Parent,
class Child>
66 {
return new Child(
id, parent.GetIdsMap(), parent); }
88 template<
class A1,
class A2,
class A3,
class A4>
friend class ComponentGroup;
91 template<
class Component>
93 { c.Update(invData, invComp); }
126 template<
class P,
class C,
class Creator,
class ManagerProv
ider>
189 typedef boost::transform_iterator<
196 typedef boost::transform_iterator<
212 const C&
Get(
int i)
const;
302 template<
class P,
class C,
class Creator,
class ManagerProv
ider>
308 if (fComponentsIds.empty() || invalidateComponents) {
310 fComponentsIds.clear();
311 fComponentsById.clear();
312 fComponentsIdsSet.clear();
319 const VManager& mgr = ManagerProvider::GetInstance();
323 std::ostringstream e;
324 e <<
"Couldn't find the list of " << C::kComponentName <<
':';
325 for (VManager::IndexMap::const_iterator i = m.begin(); i != m.end(); ++i) {
326 e <<
' ' << i->first <<
'=' << i->second;
331 fNumberOfIds = fComponentsIds.size();
344 template<
class P,
class C,
class Creator,
class ManagerProv
ider>
351 if (ic != fComponentsById.end())
354 const IdIterator ii = std::find(fComponentsIds.begin(), fComponentsIds.end(), id);
355 if (ii != fComponentsIds.end()) {
358 C*
c = Creator::template CreateObject<P, C>(id, fParent);
359 fComponentsById.insert(
id, c);
362 std::ostringstream e;
363 e <<
"No " << C::kComponentName <<
" with Id= " <<
id <<
" was found.";
370 template<
class P,
class C,
class Creator,
class ManagerProv
ider>
411 template<
class P,
class C,
class Creator,
class ManagerProv
ider>
417 if (fComponentsIdsSet.empty()) {
419 fComponentsIdsSet.insert(fComponentsIds.begin(), fComponentsIds.end());
421 return fComponentsIdsSet.find(i) != fComponentsIdsSet.end();
C & operator()(const IdList::value_type &id) const
Converts the integral id to the object. Resolve the id through the container: Id it's an integer at t...
const C & operator()(const IdList::value_type &id) const
ComponentGroup(const P &p)
Construct with parent.
ComponentMap::const_iterator ComponentMapConstIterator
IdList::size_type SizeType
Type for number of components.
const ComponentGroup< P, C, Creator, ManagerProvider > & fContainer
The child doesn't actually receive the information from its parent upon construction.
Functor to convert id to Counter.
C ComponentType
The type of the contained component.
SizeType fNumberOfIds
The number of Ids. We keep the number of IDs separately because in a std::list the query for number i...
IdList::const_iterator IdIterator
Base class for exceptions trying to access non-existing components.
boost::transform_iterator< InternalConstFunctor, IdIterator, const C & > ConstIterator
Convenience alias for constant iterators over components.
Interface for detector managers.
InternalConstFunctor(const ComponentGroup< P, C, Creator, ManagerProvider > &p)
Const functor to convert id to Counter.
IdList fComponentsIds
List of contained ids.
Iterator End()
End iterator over components.
SizeType GetNumberOfComponents() const
Returns the number of components.
IdSet fComponentsIdsSet
Set of contained ids.
const C & Get(int i) const
Retrieve component by id.
ComponentMap fComponentsById
Id to object conversion map.
virtual Status GetData(double &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const =0
Iterator Begin()
Begin iterator over components.
void Update(const VManager::IndexMap &m, const bool invalidateData=true, const bool invalidateComponents=true)
Updates the components.
boost::ptr_map< int, C > ComponentMap
const P & fParent
The parent of the components.
bool Exists(int i) const
Check for existence by id.
ComponentMap::iterator ComponentMapIterator
ComponentGroup< P, C, Creator, ManagerProvider > & fContainer
Base class for group of detector components.
boost::transform_iterator< InternalFunctor, IdIterator, C & > Iterator
Convenience alias for iterators over components.
static void UpdateComponent(Component &c, bool invData, bool invComp)
Perform the update call.
std::map< std::string, std::string > IndexMap
static Child * CreateObject(int id, const Parent &)
InternalFunctor(ComponentGroup< P, C, Creator, ManagerProvider > &p)
Initialize with a reference to the containing object so as to have a reference to which invoke the Ge...
#define ERROR(message)
Macro for logging error messages.
static Child * CreateObject(int id, const Parent &parent)
Simple struct to defer update call.
Status
Specifies success or (eventually) various possible failure modes.
The child the information from the parent upon construction.