00001 #include "GetVldContext.h"
00002 #include <MinosObjectMap/MomNavigator.h>
00003 #include <Record/RecMinos.h>
00004 #include <Record/RecMinosHdr.h>
00005 #include <Record/RecRecord.h>
00006 #include <Record/RecHeader.h>
00007
00008 #include <MessageService/MsgService.h>
00009 CVSID("$Id: GetVldContext.cxx,v 1.3 2005/08/01 22:48:44 bv Exp $");
00010
00011 #include <TIterator.h>
00012
00013 #include <string>
00014 #include <map>
00015 using namespace std;
00016
00017
00018 vector<VldContext> DataUtil::GetVldContext(const MomNavigator* mom,
00019 const char* filter)
00020 {
00021 static const char* last_filter = 0;
00022 static bool include = true;
00023 static map<string,int> filt;
00024 if (filter && filter[0] && filter != last_filter) {
00025 last_filter = filter;
00026 filt.clear();
00027
00028 if (filter[0] == '!') {
00029 include = false;
00030 ++filter;
00031 }
00032
00033 string sfilter(filter);
00034 string::size_type a=0,b=0;
00035 while (true) {
00036 b = sfilter.find(',',a);
00037 string n = sfilter.substr(a,b-a);
00038 filt[n] = 1;
00039 if (b == string::npos) break;
00040 MSG("GetVldContext",Msg::kDebug)
00041 << (include ? "including " : "excluding ")
00042 << n << endl;
00043 }
00044 }
00045
00046
00047 vector<VldContext> ret;
00048
00049 if (!mom) return ret;
00050
00051 TIter fiter(mom->GetFragmentArray());
00052 TObject* fragment = 0;
00053 while ((fragment = fiter())) {
00054 if (!fragment) continue;
00055
00056 if (filter) {
00057 string n = fragment->ClassName();
00058 int found = filt[n];
00059 if (found && !include) {
00060 MSG("GetVldContext",Msg::kDebug) << "excluding "
00061 << n << endl;
00062 continue;
00063 }
00064 if (!found && include) {
00065 MSG("GetVldContext",Msg::kDebug) << "not including "
00066 << n << endl;
00067 continue;
00068 }
00069 }
00070
00071 if (RecMinos* rec = dynamic_cast<RecMinos*>(fragment)) {
00072 ret.push_back(rec->GetHeader()->GetVldContext());
00073 }
00074 else if (RecRecord* rec = dynamic_cast<RecRecord*>(fragment)) {
00075 ret.push_back(rec->GetHeader().GetVldContext());
00076 }
00077 }
00078 return ret;
00079 }