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 #include <DataUtil/GetTempTags.h>
00008 #include <Util/UtilString.h>
00009
00010 #include <MessageService/MsgService.h>
00011 CVSID("$Id: GetVldContext.cxx,v 1.4 2010/01/15 22:04:33 rhatcher Exp $");
00012
00013 #include <TIterator.h>
00014
00015 #include <string>
00016 #include <map>
00017 using namespace std;
00018
00019
00020 vector<VldContext> DataUtil::GetVldContext(const MomNavigator* mom,
00021 const char* filter)
00022 {
00023 static const char* last_filter = 0;
00024 static bool include = true;
00025 static map<string,int> filt;
00026
00027 if (filter && filter[0] && filter != last_filter) {
00028 last_filter = filter;
00029 filt.clear();
00030
00031 if (filter[0] == '!') {
00032 include = false;
00033 ++filter;
00034 }
00035
00036 std::vector<string> toklist;
00037 UtilString::StringTok(toklist,filter,",:;");
00038 for ( size_t i = 0; i < toklist.size(); ++i ) {
00039 std::string& item = toklist[i];
00040 filt[item] = 1;
00041 MSG("GetVldContext",Msg::kDebug)
00042 << "filter by "
00043 << (include ? "including " : "excluding ")
00044 << item << endl;
00045 }
00046 }
00047
00048 vector<VldContext> ret;
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 classname = fragment->ClassName();
00058 TNamed* named = dynamic_cast<TNamed*>(fragment);
00059 string username = (named) ? named->GetName() : "<no-name>";
00060 string streamname = DataUtil::GetTempTagString(fragment,"stream");
00061 int found = filt[classname] || filt[username] || filt[streamname];
00062 if (found && !include) {
00063 MSG("GetVldContext",Msg::kDebug)
00064 << "excluding " << classname << "," << username
00065 << "," << streamname << endl;
00066 continue;
00067 }
00068 if (!found && include) {
00069 MSG("GetVldContext",Msg::kDebug)
00070 << "excluding " << classname << "," << username
00071 << "," << streamname << endl;
00072 continue;
00073 }
00074 }
00075
00076 if (RecMinos* rec = dynamic_cast<RecMinos*>(fragment)) {
00077 ret.push_back(rec->GetHeader()->GetVldContext());
00078 }
00079 else if (RecRecord* rec = dynamic_cast<RecRecord*>(fragment)) {
00080 ret.push_back(rec->GetHeader().GetVldContext());
00081 }
00082 }
00083 return ret;
00084 }