CQParallel Class Reference

#include <CQParallel.h>

Inheritance diagram for CQParallel:

CQuery CMagic

List of all members.

Public Member Functions

 ~CQParallel ()
 CQParallel (CAccessorAdminCollection &inAccessorAdminCollection, CAlgorithm &inAlgorithm)
virtual CXMLElementquery (const CXMLElement &inQuery, int inNumberOfInterestingImages, double inDifferenceToBest)
virtual CIDRelevanceLevelPairListfastQuery (const CXMLElement &inQuery, int inNumberOfInterestingImages, double inDifferenceToBest)
virtual CXMLElementgetRandomImages (int inNumberOfInterestingImages) const
virtual list< TID > * getAllIDs () const
virtual list< string > * getAllURLs () const
virtual list< pair< TID,
string > > * 
getAllIDURLPairs () const
virtual bool setAlgorithm (CAlgorithm &inAlgorithm)
void finishInit ()

Protected Member Functions

virtual void init ()

Private Attributes

CAccessorAdminCollectionmAccessorAdminCollection
lCLocalAccessorMap mAccessors

Classes

class  lCLocalAccessor
class  lCLocalAccessorMap


Detailed Description

FIXME: The name WRONGLY suggests that this actually does parallel processing. It should be relatively quick to add, it is intendend, but it is not yet done.

This is going to be one of our main building blocks. It is a structure which contains a couple of CQuery structures, hands a query through to them, and then unifies the result. In fact this is the center of all this query tree business.

Probably we will put another layer into the class tree: The CQTreeNode, but let's first start.

Important: The basic assumption here is, that all children operate on the same collections. If this is not the case we have to be more careful, and most of all: we have to operate using URLs.

: Wolfgang Müller

Definition at line 94 of file CQParallel.h.


Constructor & Destructor Documentation

CQParallel::~CQParallel (  ) 

we need to unregister the accessors used

destructor: at present empty

Definition at line 77 of file CQParallel.cc.

00077                        {
00078 
00079   cout << "destroying this "
00080        << __FILE__
00081        << __LINE__
00082        << flush
00083        << endl;
00084 
00085   //i thought i will need this, but at present I do not have this impression
00086   //it does not hurt, so we leave it in
00087 };

CQParallel::CQParallel ( CAccessorAdminCollection inAccessorAdminCollection,
CAlgorithm inAlgorithm 
)

In fact, what we are doing here is to get ourselves an accessor ACURL2FTS to do a proper fastQuery

constructor see CQuery

Definition at line 61 of file CQParallel.cc.

00062                                             :
00063   mAccessorAdminCollection(inAccessorAdminCollection)
00064 {
00065   
00066 
00067   // nothing we could do here at present...
00068  
00069 
00070 };
    


Member Function Documentation

void CQParallel::init (  )  [protected, virtual]

Initializer, used by both construcors

FIXME: The name WRONGLY suggests that this actually does parallel processing. It should be relatively quick to add, it is intendend, but it is not yet done.

This is going to be one of our main building blocks. It is a structure which contains a couple of CQuery structures, hands a query through to them, and then unifies the result. In fact this is the center of all this query tree business.

Probably we will put another layer into the class tree: The CQTreeNode, but let's first start.

Important: The basic assumption here is, that all children operate on the same collections. If this is not the case we have to be more careful, and most of all: we have to operate using URLs.

Initializer, used by both construcors

Implements CQuery.

Definition at line 52 of file CQParallel.cc.

00052                      {
00053   //we assume that all the children have been initialised.
00054   //so there is nothing to do here
00055 };

CXMLElement * CQParallel::query ( const CXMLElement inQuery,
int  inNumberOfInterestingImages,
double  inDifferenceToBest 
) [virtual]

calls fastQuery for every child, merges the results and translates them back into URLs difficulty: take into account that each child might operate on a different collection.

calls fastQuery for every child, merges the results and translates them back into URLs

Definition at line 94 of file CQParallel.cc.

References mAccessors.

00096                                          {
00097 
00098   //
00099   double lWeightNormaliser=0;
00100 
00101   //
00102   cout << endl
00103        << "I made it till here " 
00104        << endl
00105        << flush;
00106 
00107   CXMLElement* lReturnValue=new CXMLElement();
00108 
00109   //
00110   assert(lReturnValue);
00111 
00112   //this will be the receptacle of the final result
00113   map<string,double> lURLToRelevanceLevel;
00114   
00115 
00116   //for all collections
00117   for(lCLocalAccessorMap::iterator i=mAccessors.begin();
00118       i!=mAccessors.end();
00119       i++){
00120     lWeightNormaliser+=i->second.mWeightedSum;
00121     i->second.mUnifiedResults=new map<TID,double>();
00122 
00123 
00124     //for all query structures using each collection
00125     for(list<lCChildren::iterator>::iterator j=i->second.mUsedBy.begin();
00126   j!=i->second.mUsedBy.end();
00127   j++){
00128 
00129 
00130       CIDRelevanceLevelPairList* ltempResultList=
00131   (*j)->mQuery->fastQuery(inQuery,
00132         inNumberOfInterestingImages,
00133         inDifferenceToBest);
00134 
00135 
00136       //
00137       CSelfDestroyPointer<CIDRelevanceLevelPairList> lResultList=
00138   ltempResultList;
00139       
00140       
00141       cout << endl
00142      << "Subquery: current result size "
00143      << lResultList->size()
00144      << endl;
00145 
00146       if(lResultList){
00147   for(CIDRelevanceLevelPairList::iterator k=lResultList->begin();
00148       k!=lResultList->end();
00149       k++){
00150     map<TID,double>::iterator lFound=
00151       (i->second.mUnifiedResults)->find(k->getID());
00152 
00153     if(lFound==i->second.mUnifiedResults->end()){
00154       i->second.mUnifiedResults
00155         ->insert(make_pair(k->getID(),
00156          k->getRelevanceLevel()));
00157     }else{
00158       i->second.mUnifiedResults
00159         ->insert(make_pair(k->getID(),
00160          k->getRelevanceLevel()
00161          +lFound->second * (*j)->mWeight));
00162 
00163     }
00164   }
00165       }
00166     }
00167 
00168     //now we have unified lists of IDs which belong
00169     //to one collection
00170     //Now turn them into URLs and sum them all up
00171     //note that it is not guaranteed that 
00172     //the maps we unite are sorted the same way, so
00173     //we do it again with maps.
00174     for(map<TID,double>::const_iterator j=i->second.mUnifiedResults->begin();
00175   j!=i->second.mUnifiedResults->end();
00176   j++){
00177       assert((i->second).mAccessor);
00178       for(map<TID,double>::const_iterator 
00179       k=(i->second).mUnifiedResults->begin();
00180     k!=(i->second).mUnifiedResults->end();
00181     k++){
00182   string lURL=i->second.mAccessor->IDToURL(k->first);
00183 
00184   map<string,double>::iterator lFound=
00185     lURLToRelevanceLevel.find(lURL);
00186   if(lFound!=lURLToRelevanceLevel.end()){
00187     lURLToRelevanceLevel[lURL]+=k->second;
00188   }else{
00189     lURLToRelevanceLevel[lURL] =k->second;
00190   }
00191       }
00192     }
00193     i->second.mUnifiedResults=0;
00194   }
00195   //
00196   //
00197   //
00198   for(map<string,double>::iterator i=lURLToRelevanceLevel.begin();
00199       i!=lURLToRelevanceLevel.end();
00200       i++){
00201     lReturnValue->push_back(CRelevanceLevel(i->first,
00202               i->second/lWeightNormaliser));
00203     
00204   }
00205   //this is quite ugly
00206   //should be one sort with the right op
00207   lReturnValue->sort();
00208   lReturnValue->reverse();
00209   return lReturnValue;
00210 };

CIDRelevanceLevelPairList * CQParallel::fastQuery ( const CXMLElement inQuery,
int  inNumberOfInterestingImages,
double  inDifferenceToBest 
) [virtual]

FIXME: useless in current scenario.

Generally using IDs instead of URLs (for keeping communication overhead low, when doing things like CORBA).

in this case we simply hand things through. this might be some kind of "take it and translate it" thing. however, at present we save the work.

using IDs instead of CQParallel::URLs (for keeping communication overhead low, when doing things like CORBA).

Implements CQuery.

Definition at line 218 of file CQParallel.cc.

00220                                        {
00221   assert(0);
00222 };

CXMLElement * CQParallel::getRandomImages ( int  inNumberOfInterestingImages  )  const [virtual]

get some random images

Reimplemented from CQuery.

Definition at line 229 of file CQParallel.cc.

00229 {};

virtual list<TID>* CQParallel::getAllIDs (  )  const [virtual]

get the IDs of all images (handed through to accessor)

Reimplemented from CQuery.

virtual list<string>* CQParallel::getAllURLs (  )  const [virtual]

get the IDs of all images (handed through to accessor)

virtual list<pair<TID,string> >* CQParallel::getAllIDURLPairs (  )  const [virtual]

get the IDs of all images (handed through to accessor)

bool CQParallel::setAlgorithm ( CAlgorithm inAlgorithm  )  [virtual]

set the Algorithm. same scheme as in setCollection

Reimplemented from CQuery.

Definition at line 236 of file CQParallel.cc.

00236 {};

void CQParallel::finishInit (  )  [virtual]

it might be necessary to wait until all the children are added before ending the initialisation phase.

This function is called by CAlgorithm.

What we are doing here is to find out the necessary accessor information for each child, and construct an accessor for it.

it might be necessary to wait until all the children are added before ending the initialisation phase.

This function is called by CAlgorithm.

Reimplemented from CQuery.

Definition at line 245 of file CQParallel.cc.

References CAccessorAdminCollection::getProxy(), mAccessorAdminCollection, mAccessors, and CQuery::mChildren.

00245                            {
00246   cout << endl
00247        << "Finish init in CQParallel, size of mChildren"
00248        << mChildren.size()
00249        << endl;
00250   
00251   for(lCChildren::iterator i=mChildren.begin();
00252       i!=mChildren.end();
00253       i++){
00254     string lCollection=i->mQuery->getAlgorithm().getCollectionID();
00255 
00256     //FIXME fails if not all the parents say which collections 
00257     //unfixable. need to catch this case somewhere
00258     //
00259     //they contain included in this instruction is:
00260     //make a new item if there is already one
00261     lCLocalAccessorMap::iterator lFound=mAccessors.find(lCollection);
00262 
00263     if(lFound==mAccessors.end()){
00264       mAccessors.insert(make_pair(lCollection,
00265           lCLocalAccessor()));
00266       //do i need this: look up in specs
00267       lFound=mAccessors.find(lCollection);
00268     }
00269     //
00270     lFound->second.mUsedBy.push_back(i);
00271     //FIXME: actually make the accessor.
00272     //relies on mAccessor initially being 0
00273     if(!lFound->second.mAccessor){
00274       //
00275       CAccessorAdmin* lProxy=&(mAccessorAdminCollection
00276              .getProxy(i->mQuery->getAlgorithm()
00277            .getCollectionID()));
00278       
00279       lFound->second.mAccessor=lProxy->openURL2FTS();
00280       lFound->second.mAccessorAdmin=lProxy;
00281       
00282     }
00283 
00284     //this enables you to put relative weight on algorithms
00285     lFound->second.mWeightedSum+=i->mWeight;
00286   }
00287   cout << "finishInitFinished inCQParallel"
00288        << endl
00289        << endl;
00290 };


Member Data Documentation

We need this because we cannot use this just when constructing, but we have to use it in finishInit

Reimplemented from CQuery.

Definition at line 99 of file CQParallel.h.

Referenced by finishInit().

do not confuse with mAccessor. This is the accessor list we talked about before

Definition at line 143 of file CQParallel.h.

Referenced by finishInit(), and query().


The documentation for this class was generated from the following files:

Generated on Wed Jan 7 00:31:13 2009 for Gift by  doxygen 1.5.6