| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

HistorianCustomRules.h

Go to the documentation of this file.
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 // Template code follows.
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    // The problem with this method is that parentIDetectorElement() seems to crash.
00051    // bool done = false;
00052    // while(!done) {
00053    //   if(curElement == mValue) return true;
00054    //   if(curElement == 0) return false;
00055    //   curElement = curElement->parentIDetectorElement();
00056    // }
00058    const IGeometryInfo* curGeo = curElement->geometry();
00059    const IGeometryInfo* valGeo = mValue->geometry();
00060    ILVolume::ReplicaPath dummy;
00061    while(true){
00062      if(!curGeo) break;  // We got to the top of the tree and never hit the Value
00063      if(curGeo == valGeo) return true; // The value matches a parent of the current position.. it's contained
00064      IGeometryInfo* nextGeo = 0;
00065      curGeo->location(nextGeo, dummy); 
00066      curGeo = nextGeo;  // Ok, move up a level and check again.
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 /*param_on_left*/          
00080                 )
00081 {
00086   
00087   // Go find the data object we want to compare to.
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 /* CUSTOMRULES_H */
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:54:53 2011 for Historian by doxygen 1.4.7