#ifndef _mdet_Counter_h #define _mdet_Counter_h #include #include // #include #include #include // #include #include namespace sdet { class Station; }; namespace mdet { class MDetector; /** * \class Counter Counter.h "mdet/Counter.h" * \brief Root detector of the muon detector hierarchy. * * The Counters are logical constructions (in opposition * to an actual device) that are associated to surface tanks * (sdet::Station) and group together several muon detection * modules (mdet::Module). * * \author Rodolfo Federico Gamarra * \date 09 Jan 2009 * \ingroup mdet */ class Counter : public MDetectorComponent::Type, public det::MPositionable { private: /** * \brief Type for the set of associated Modules. */ typedef MComponentGroup::Type ModuleGroup; public: /** * \brief Convenience typedef for const iterator over * the contained Module instances. */ typedef ModuleGroup::ConstIterator ModuleConstIterator; /* * Name of the component, as of the needs of MDetectorComponent * template class. */ static const char* const kComponentName; static const char* const kComponentId; /** * \brief Begin iterator for the Modules contained * in the Counter. */ ModuleConstIterator ModulesBegin() const { return GetModules().Begin(); } /** * \brief Begin iterator for the Modules contained * in the Counter. */ ModuleConstIterator ModulesEnd() const { return GetModules().End(); } /** * \brief Retrieve by id a constant module. */ const Module& GetModule(const int mId) const { return GetModules().Get(mId); } /** * \brief Check existence. */ bool ExistsModule(const int mId) const { return GetModules().Exists(mId); } /** * \brief Retrieve the id of the associated surface tank. * */ int GetAssociatedTankId() const; /** * \brief Retrieve the associated tank. * */ const sdet::Station& GetAssociatedTank() const; //Segmentation getter unsigned int GetSegmentation() const { return fSegmentation; } //check if station is a dense station bool IsDense() const {return fDense;}; // Get the counter area in square metres double GetArea() const; private: /** * \brief Perform update in this component and forward to * subcomponents. */ void Update(bool invalidateData, bool invalidateComponents); /** * \brief The reference is the local coordinate system of the associated * sdet::Station. * * \sa mdet::Counter::GetLocalCoordinateSystem */ utl::CoordinateSystemPtr GetReferenceCoordinateSystem() const; /** * \brief Contructs a Counter with the given id. * * This method is kept private creation of these objects is not * meant to be performed by client code. See the related friendship * declaration. * * \param cId This counter's id. */ Counter(int cId); /** * */ ~Counter() { } /** * \brief Accesor for delayed update. */ const ModuleGroup& GetModules() const { if (! fModulesUpdated) { if (fUseInvalidateFlags) fModules.Update(GetIdsMap(), fInvalidateData, fInvalidateComponents); else fModules.Update(GetIdsMap()); fModulesUpdated = true; // Modifies data. } return fModules; } /** * \brief Frienship for GetData callback. */ friend class det::MPositionable; /** * \brief Friendship to allow creation. */ friend struct det::IdOnlyCreator; /** * \brief Friendship for destruction. * * Depends on det::ComponentGroup innards. */ template friend void boost::checked_delete(T*); /** * \brief Friendship for the update call. */ friend struct det::ComponentUpdater; mutable utl::Validated fAssociatedTankId; /** * \brief Lazy update flag. * * Mutable in order to be modifiable * on first access to modules. * * This flag comes from the desire of delay the loading * of the modules (and so on) of a counter until the time * they are required. */ mutable bool fModulesUpdated; // Auxiliary flags to use in delayed updating (reflect the parameters of Update). bool fInvalidateData; bool fInvalidateComponents; // To indicate whether the "invalidate" flags are usable or need to be ignored. bool fUseInvalidateFlags; /** * \brief Modules. * * Mutable in order to be modifiable on first * access to modules. */ mutable ModuleGroup fModules; unsigned int fSegmentation; //Calculate segmentation of a given Counter void Segmentation() { fSegmentation = 0; typedef ModuleConstIterator mIt; typedef mdet::Module::ScintillatorConstIterator sIt; for ( mIt mod = ModulesBegin(), mend = ModulesEnd(); mod!=mend; ++mod ) for (sIt sci = mod->ScintillatorsBegin(), send = mod->ScintillatorsEnd(); sci != send; ++sci) ++fSegmentation; } bool fDense; }; } #endif // _mdet_Counter_h