EventFlags.cpp

Go to the documentation of this file.
00001 
00002 #include "cafe/EventFlags.hpp"
00003 
00004 #include <algorithm>
00005 #include "cafe/Config.hpp"
00006 #include "cafe/Event.hpp"
00007 #include "tmb_tree/TMBEventFlags.hpp"
00008 
00009 
00010 namespace cafe {
00011 
00012     EventFlags::EventFlags(const char *name)
00013         : Processor(name),
00014           _any(true),_veto(false)
00015     {
00016         using namespace std;
00017 
00018         Config config(name);
00019         _flagNames = config.getVString("Any", " ,");
00020         if(_flagNames.size() == 0) {
00021             _flagNames = config.getVString("All", " ,");
00022             _any = false;
00023         }
00024         _vetoflagNames = config.getVString("Veto", " ,");
00025         if(_vetoflagNames.size() != 0)
00026             _veto = true;        
00027 
00028         out() << "EventFlags[" << name << "] Flags = "
00029               << (_any ? " Any of :" : "All of :" );
00030         for(vector<string>::iterator it = _flagNames.begin();
00031             it != _flagNames.end(); ++it) {
00032             out() << *it << ' ';
00033         }
00034         out() << endl;
00035 
00036         if(_veto){
00037           out() << "EventFlags[" << name << "] Flags = "
00038                 << " Veto of :";
00039           for(vector<string>::iterator it = _vetoflagNames.begin();
00040               it != _vetoflagNames.end(); ++it) {
00041               out() << *it << ' ';
00042           }
00043           out() << endl;
00044         }   
00045 
00046         TMBEventFlags f;
00047         for(vector<string>::iterator it = _flagNames.begin();
00048             it != _flagNames.end(); ++it) {
00049             TMBEventFlags::Flag flag = f.GetFlagValue((*it).c_str());
00050             if (flag == (TMBEventFlags::Flag )128) {
00051                 out() << name << " : Unknown flag name: " << *it << endl;
00052             } else {
00053                 _flagValues.push_back(flag);
00054             }
00055         }
00056        // Do the same with a list of Veto-ed flags
00057        for(vector<string>::iterator it = _vetoflagNames.begin();
00058             it != _vetoflagNames.end(); ++it) {
00059             TMBEventFlags::Flag flag = f.GetFlagValue((*it).c_str());
00060             if (flag == (TMBEventFlags::Flag )128) {
00061                 out() << name << " : Unknown flag name: " << *it << endl;
00062             } else {
00063                 _vetoflagValues.push_back(flag);
00064             }
00065         }
00066     }
00067         
00068     bool EventFlags::processEvent(Event& event) 
00069     {
00070         using namespace std;
00071 
00072         if(const TMBEventFlags *flags = event.getEventFlags()) {
00073            if(_veto)
00074                  for(vector<TMBEventFlags::Flag>::iterator it = _vetoflagValues.begin();
00075                      it != _vetoflagValues.end();
00076                      ++it)
00077                      if(flags->HasFlag(*it)) return false;
00078 
00079             if(_any) {
00080                 for(vector<TMBEventFlags::Flag>::iterator it = _flagValues.begin();
00081                     it != _flagValues.end();
00082                     ++it) {
00083                     if(flags->HasFlag(*it)) {
00084                         return true;
00085                     }
00086                 }
00087                 return false;
00088             } else {
00089                 for(vector<TMBEventFlags::Flag>::iterator it = _flagValues.begin();
00090                     it != _flagValues.end();
00091                     ++it) {
00092                     if(!flags->HasFlag(*it)) {
00093                         return false;
00094                     }
00095                 }
00096                 return true;
00097             }
00098         }
00099 
00100         return false;
00101 
00102     }
00103 
00104 }
00105 
00106 ClassImp(cafe::EventFlags)
00107 

Generated on Thu Apr 3 04:14:23 2008 for CAF by doxygen 1.3.4