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

In This Package:

Filter.h

Go to the documentation of this file.
00001 #ifndef OnXSvc_Filter_h
00002 #define OnXSvc_Filter_h
00003 
00004 #include <Slash/Data/IHandlersIterator.h>
00005 #include <Slash/Data/IProcessor.h>
00006 #include <Slash/Data/IIterator.h>
00007 #include <Slash/Data/IHandlersIterator.h>
00008 #include <Slash/Data/IHandler.h>
00009 
00010 #include <OnXSvc/IUserInterfaceSvc.h>
00011 #include <GaudiKernel/MsgStream.h>
00012 #include <GaudiKernel/KeyedContainer.h>
00013 
00014 template <class Object> 
00015 class Filter {
00016 public:
00017   typedef KeyedContainer<Object, Containers::HashMap> container;
00018   Filter(IUserInterfaceSvc& aUISvc,MsgStream& aLog)
00019   :fUISvc(aUISvc),fLog(aLog)
00020   ,fTypeManager(0),fType(0),fIterator(0)
00021   {
00022     fTypeManager = fUISvc.typeManager();
00023   }
00024   container* collect(container& aVector
00025                      ,const std::string& aWhat
00026                      ,const std::string& aCuts) {
00027     int number = aVector.size();
00028     if(number<=0) return 0;
00029     if(!setup(aWhat,aVector)) return 0;
00030     std::vector<std::string> args;
00031     args.push_back(aWhat);
00032     args.push_back(aCuts);
00033     fTypeManager->execute("collect",args);
00034     container* v = new container;
00035     if(v) {
00036       Slash::Data::IHandlersIterator* hit = fTypeManager->handlersIterator();
00037       for(;const Slash::Data::IHandler* h = hit->handler();hit->next()) {
00038         v->add((Object*)h->object());
00039       }
00040       delete hit;
00041     }
00042     fTypeManager->eraseHandlers();
00043     // fIterator deleted by the collect.
00044     fType->setIterator(0);
00045     return v;
00046   }
00047   void dump(container& aVector,const std::string& aWhat) {
00048     int number = aVector.size();
00049     if(number<=0) return;
00050     if(!setup(aWhat,aVector)) return;
00051     std::vector<std::string> args;
00052     args.push_back(aWhat);
00053     args.push_back("");
00054     fTypeManager->execute("collect",args);
00055     args.clear();
00056     args.push_back("table");
00057     //args.push_back("raw");
00058     fTypeManager->execute("dump",args);
00059     fTypeManager->eraseHandlers();
00060     // fIterator deleted by the collect.
00061     fType->setIterator(0);
00062   }
00063 private:
00064   bool setup(const std::string& aWhat,container& aVector) {
00065     fType = 0;
00066     fIterator = 0;
00067     if(!fTypeManager) return false;
00068     Slash::Data::IAccessor* type = fTypeManager->findAccessor(aWhat);
00069     if(!type) { 
00070       // Not found in OnX dictionary. Try the Gaudi dico.
00071       type = fUISvc.metaType();
00072       if(type && type->setName(aWhat)) { 
00073         // Found in Gaudi dictionary.
00074       } else {
00075         fLog << MSG::INFO << " type \"" << aWhat << "\" not found." << endreq;
00076         return false;
00077       }
00078     }
00079 
00080     class Iterator : public Slash::Data::IIterator {
00081     public: //Slash::Data::IIterator
00082       virtual void* object() {
00083         if(fIterator==fVector.end()) return 0;
00084         return *fIterator;
00085       }
00086       virtual void next() { ++fIterator;}
00087       virtual void* tag() {return 0;}
00088     public:
00089       Iterator(container& aVector):fIndex(0),fVector(aVector) {
00090         fIterator = fVector.begin();
00091       }
00092     private:
00093       unsigned int fIndex;
00094       container& fVector;
00095       typename container::iterator fIterator;
00096     };
00097 
00098     fType = type;
00099     fIterator = new Iterator(aVector);
00100     fType->setIterator(fIterator);
00101     return true;
00102   }
00103 private:
00104   IUserInterfaceSvc& fUISvc;
00105   MsgStream& fLog;
00106   Slash::Data::IProcessor* fTypeManager;
00107   Slash::Data::IAccessor* fType;
00108   Slash::Data::IIterator* fIterator;
00109 };
00110 
00111 #endif
00112 
00113 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:02:00 2011 for OnXSvc by doxygen 1.4.7