00001 #ifndef HISTORIANCUSTOMRULES_H
00002 #define HISTORIANCUSTOMRULES_H
00003
00007
00008 #include "RuleParser/RuleFactory.h"
00009 #include "RuleParser/Rules.h"
00010 #include <DetDesc/IDetectorElement.h>
00011 #include <DetDesc/IGeometryInfo.h>
00012 #include <iostream>
00013
00014 template<class Q>
00015 struct DetElemContainsRuleFactory : public RuleParser::RuleFactory
00016 {
00017 DetElemContainsRuleFactory(Q* caller) : mCaller(caller) {};
00018 RuleParser::Rule* createRule(
00019 const RuleParser::ParameterDescription& paramter,
00020 int operation,
00021 const std::string& value,
00022 bool param_on_left
00023 );
00024 Q* mCaller;
00025 };
00026
00027 template<class Q>
00028 class DetElemContainsRule : public RuleParser::Rule
00029 {
00030 public:
00031 DetElemContainsRule(std::string n, const IDetectorElement* value)
00032 : Rule(n)
00033 , mValue(value) {};
00034 virtual ~DetElemContainsRule() {};
00035 virtual bool select(const RuleParser::Queriable* thing);
00036 private:
00037 const IDetectorElement* mValue;
00038 };
00039
00040
00041
00042 template<class Q>
00043 bool DetElemContainsRule<Q>::select(const RuleParser::Queriable* thing)
00044 {
00045 const Q* q = dynamic_cast<const Q*>(thing);
00046 assert(q && "Was given the wrong kind of Queriable!");
00047 const IDetectorElement* curElement = q->getDetectorElement();
00048 if(!curElement) return false;
00049 if(!mValue) return false;
00050
00051
00052
00053
00054
00055
00056
00058 const IGeometryInfo* curGeo = curElement->geometry();
00059 const IGeometryInfo* valGeo = mValue->geometry();
00060 ILVolume::ReplicaPath dummy;
00061 while(true){
00062 if(!curGeo) break;
00063 if(curGeo == valGeo) return true;
00064 IGeometryInfo* nextGeo = 0;
00065 curGeo->location(nextGeo, dummy);
00066 curGeo = nextGeo;
00067 }
00068 return false;
00069 }
00070
00071
00072
00073
00074 template<class Q>
00075 RuleParser::Rule* DetElemContainsRuleFactory<Q>::createRule(
00076 const RuleParser::ParameterDescription& parameter,
00077 int operation,
00078 const std::string& value,
00079 bool
00080 )
00081 {
00086
00087
00088 DataObject* d;
00089 mCaller->detSvc()->retrieveObject(value,d);
00090 const IDetectorElement* valueDetElem
00091 = dynamic_cast<const IDetectorElement*>(d);
00092
00093 if(!valueDetElem){
00094 mCaller->err() << "DetElemContainsRuleFactory: Can't build DetElemContainsRule because given value ("
00095 << value << ") doesn't correspond to a known IDetectorElement object." << endreq;
00096 assert(0);
00097 }
00098
00099 std::string name = parameter.name() + " " + parameter.operators()[operation] + " " + valueDetElem->name();
00100 return new DetElemContainsRule<Q>(name,valueDetElem);
00101 }
00102
00103
00104
00105 #endif