// Change History
// 11/20/03 AV Development: BC6 conversion. Const/none const
// 11/20/03 AV Development: BC6 conversion. changes in DRS_Sort_RecList constructor

//DRS_Report.cpp

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// DRS_Report
//////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <commctrl.h>
#include <time.h>

#include "drs/drs_rpt.h"
#include "drs/drs_vect.h"
#include "drs/drs_tree.h"
#include "drs/drs_sort.h"
// #include "drs/drs_progress.h"
#include "drs/drs_srch.h"

//#include "frmProgress.h"

extern DRS_Application *pCurAppl;

////////////////////////////////////////////////////////////////////////////////////////////////////////
//DRS_ReportTree
////////////////////////////////////////////////////////////////////////////////////////////////////////

DRS_ReportTree::DRS_ReportTree( DRS_Application const &rAppl, DRS_Descriptor const &rDescriptor)

                              : oAppl( rAppl),
                                descr(rDescriptor)

{

  //Create root node and root dim
  AttachNode( new DRS_ReportNode());
  AttachDim( new DRS_ReportDim());

  //Report tree maintains address selectors for all vectors.
  addrSelectors = new ( auto_ptr<uint32> [oAppl.VectorCount()] );
  for( uint i = 0; i < oAppl.VectorCount(); i++)
    addrSelectors[i].reset( new uint32[oAppl.Vector(i).Depth()]);
}


void DRS_ReportTree::AddVector( uint iVectorID, uint32 *pVectorSelector)
{

  //Copy vector selector
  //ReportTree maintains const vector selector for all nodes.
  memcpy( addrSelectors[iVectorID].get(), pVectorSelector, oAppl.Vector(iVectorID).Depth() * sizeof(uint32));

  //Create report vector and add to root node.
  Root().AttachVectorTree( new DRS_ReportVectorTree( oAppl.Vector(iVectorID), addrSelectors[iVectorID].get() ) );

}

void DRS_ReportTree::AddSubreport( uint iSearchFieldID)
{
  //A subreport can only be added for SearchFields that
  //  have one and only one index
  //  have one and only one data field
  if( oAppl.SearchField(iSearchFieldID).DataFieldCount() > 1)
    throw AT_Bounds_Err( *this, (AT_String)"DataCount for search field", iSearchFieldID);


       vSearchFieldIDs.push_back( iSearchFieldID);

       //Create & Attach DRS_ReportDim for search fields data field. Assume only one.
       AttachDim( new DRS_ReportDim( oAppl.SearchField(iSearchFieldID).DataField(0)));
}

void DRS_ReportTree::Report( AT_Record_List const *pRecordList, bool *pIsCancel)
{
  /*
  try {
  */
       //Copy record list
       AT_Record_List copy = *pRecordList;

       DRS_Sort_RecList ReportRecList = DRS_Sort_RecList( &copy);

       //Sort record list
       //Create sort contexts
       if( vSearchFieldIDs.size())
         {
         auto_array<AT_Record_List::Sort_Context> Contexts(new AT_Record_List::Sort_Context[vSearchFieldIDs.size()]);

         DRS_Index ** Indexes = new DRS_Index * [vSearchFieldIDs.size()];

         for( uint i = 0; i < vSearchFieldIDs.size(); i++)
           {
           Indexes[i] = oAppl.SearchField( vSearchFieldIDs[i]).IndexList().IndexOpen( 0);
           Contexts[i] = AT_Record_List::Sort_Context(Indexes[i],
                                             true /*isAscending*/,
  									                  AT_Record_List::Sort_Context::unindexedToBottom /*caseKeepUnindexed*/,
                                             true  /*isDuplicate*/);
           }
         ReportRecList.Sort( Contexts.get(), vSearchFieldIDs.size(), 0, pIsCancel);

         for( uint i = 0; i < vSearchFieldIDs.size(); i++) delete Indexes[i];
         delete [] Indexes;
         }
       if( *pIsCancel) return;

       //Assert only root node available before Report reclist.
       AT_Assert( !GetRootNode()->ChildCount(), *this, "Cannot overwrite report");

       //Create DRS_ReportNode for data loading as copy of root.
       DRS_ReportNode CurReportNode( Root());
       //Create DRS_ReportNode for report result as copy of root.
       DRS_ReportNode ResultReportNode( Root());

       //Cycle record list
       // DRS_ProgressLong Progress( (byte *)"DART Report Builder", (byte *)"Analysing data...");

       //TFormProgress * frmProgress = new TFormProgress( NULL);
       //frmProgress->Show();

       for( AT_Record_List::Iter RecIter = ReportRecList.getBase()->begin();
            RecIter != ReportRecList.getBase()->end(); RecIter ++)
         {
         //if( Progress.IsCancel())
         //  {
         //  *pIsCancel = true;
         //  break;
         //  }

         // Progress.progress( RecIter - ReportRecList.getBase()->begin(), ReportRecList.getBase()->count());

         DRS_RecordSet oRecord( &oAppl, *RecIter);

         CurReportNode  << oRecord;

         //Load ReportDims for record
         RootDim() << oRecord;

         //Add ReportNode to root node
         ResultReportNode.PlusEquals( CurReportNode, GetRootDim());
         }

       Root().SetResult(ResultReportNode, GetRootDim());
      //delete frmProgress;
/*

  }
  catch( ...)
    {
    //delete frmProgress;

    throw;
    }
*/    
}

void DRS_ReportVectorTree::SelectorGet( uint32 * addrDest)
  const
{

  memcpy( addrDest, addrSelector, rVector.Depth() * sizeof(uint32));

}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//DRS_ReportNode
////////////////////////////////////////////////////////////////////////////////////////////////////////
//Copy contructor
DRS_ReportNode::DRS_ReportNode( DRS_ReportNode const &rCopyNode)
      : DRS_TreeNode<DRS_ReportNode>()
{

    if( rCopyNode.FieldData())
      pFieldData.reset( new DRS_FieldData( * rCopyNode.FieldData()));

    //Copy report vectors
    for( std::vector<DRS_ReportVectorTree*>::const_iterator iter = rCopyNode.vReportVectors.begin();
         iter != rCopyNode.vReportVectors.end(); iter ++)
      vReportVectors.push_back( new DRS_ReportVectorTree(**iter));
}

//Copy constructor with new data field contents.
DRS_ReportNode::DRS_ReportNode( DRS_ReportNode const &rCopyNode, DRS_FieldData const * pFieldData)
      : DRS_TreeNode<DRS_ReportNode>(), pFieldData( new DRS_FieldData( *pFieldData))
{
    //Copy report vectors
    for( std::vector<DRS_ReportVectorTree *>::const_iterator iter = rCopyNode.vReportVectors.begin();
         iter != rCopyNode.vReportVectors.end(); iter ++)
      vReportVectors.push_back( new DRS_ReportVectorTree(**iter));
}

DRS_ReportNode::~DRS_ReportNode()
{
  for( uint i = vReportVectors.size(); i > 0; --i) delete vReportVectors[i-1];
}

#if 0
void DRS_ReportNode::AddVectorAddress( uint iVectorID, uint32 *pVectorAddress)
{
       throw AT_Function_Err( *this, "AddVectorAddress");

       //If ReportVector for this vector exists, Add vectoraddress to reportvector
       for( std::vector<DRS_ReportVectorTree *>::const_iterator iter = vReportVectors.begin();
            iter != vReportVectors.end(); iter++)
         {
         if( (*iter)->Vector().VectorID() == iVectorID)
           {
           (*iter)->AddVectorAddress( pVectorAddress);
           return;
           }
         }
       //else create and attach new report vector
       {


       DRS_ReportVectorTree *pNewVector = new DRS_ReportVectorTree( oAppl.Vector(iVectorID));
       pNewVector->AddVectorAddress( pVectorAddress);
       vReportVectors.push_back( pNewVector);
       }
}
#endif

//Load record
void DRS_ReportNode::operator<< ( DRS_RecordSet &rRecord)
{

       //Load record in each reportvector
       for( std::vector<DRS_ReportVectorTree *>::const_iterator iter = vReportVectors.begin();
            iter != vReportVectors.end(); iter++)
          **iter << rRecord;
}


//Add report nodes
//Tree creates report node for each record and adds to root report node.
//Each report node adds to cuurent child (if applicable), else creates new child
void DRS_ReportNode::PlusEquals( DRS_ReportNode const &rNode, DRS_ReportDim const *pDim)
{
       //Add each report vector
       for( std::vector<DRS_ReportVectorTree *>::iterator iter = vReportVectors.begin();
            iter != vReportVectors.end(); iter++)
          **iter += *rNode.vReportVectors[iter - vReportVectors.begin()];

       //If not end of Tree, add to existing or create new child
       if( pDim->GetChild())
         {
         //If children and if child dim has same FieldData as last child,
         //then add to last child,

         if( vChildren.size() && ( pDim->GetChild()->FieldData() == * vChildren[vChildren.size()-1]->FieldData()))
           vChildren[vChildren.size()-1]->PlusEquals( rNode, pDim->GetChild());

         //else copy node and add as child, add new node to new child.
         else
           InheretChild( new DRS_ReportNode( rNode, & pDim->GetChild()->FieldData()))
             ->PlusEquals( rNode, pDim->GetChild());
         }
}

//Add report nodes
//Remove nodes that do not have any data
void DRS_ReportNode::SetResult( DRS_ReportNode const &rNode, DRS_ReportDim const *pDim)
{
  //Add each report vector
  for( std::vector<DRS_ReportVectorTree *>::iterator iter = vReportVectors.begin();
      iter != vReportVectors.end(); iter++)
    (*iter)->addTree(*rNode.vReportVectors[iter - vReportVectors.begin()]);

  //If not end of Tree, add to existing or create new child
  if( pDim->GetChild())
   {
   // copy all children nodes
   for (uint i = 0; i < rNode.ChildCount(); ++i)
     InheretChild( new DRS_ReportNode( *rNode.GetChild(i), rNode.GetChild(i)->FieldData()))
       ->SetResult( *rNode.GetChild(i), pDim->GetChild());
   }
}

//DRS_ReportDim

//Load record: i.e. store recs comparison field contents
void DRS_ReportDim::operator<< ( DRS_RecordSet &rec) const
{
  if( DRS_ReportDim const * child = GetChild()) *child << rec;
  if( pFieldData.get())
    *(pFieldData.get()) << rec;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//DRS_ReportVectorTree
////////////////////////////////////////////////////////////////////////////////////////////////////////

DRS_ReportVectorTree::DRS_ReportVectorTree( DRS_Vector const &rRefVector, uint32 const *pSelector)
    : rVector( rRefVector),
      addrSelector( pSelector)
{
    //Create root
    AttachNode( new DRS_ReportVectorTreeNode());
}

  //A report node creates a new  ReportNode and attaches as child when
  //new Dim data val detected. ReportNode contructor copies ReportVectorTrees.
  //NOTE: ReportVectorTrees & nodes use the dims of the vector to which they refer.
  //NOTE: Cannot use DRS_Tree copy contructor. Root node may be leaf.
  //      Tree copier would create root as node.
DRS_ReportVectorTree::DRS_ReportVectorTree( DRS_ReportVectorTree const &rCopy)
  : rVector( rCopy.rVector),
    addrSelector( rCopy.addrSelector)
{
  //Blank tree on copy. Get by occurrence.
  AttachNode( new DRS_ReportVectorTreeNode());

  //AttachNode( new DRS_ReportVectorTreeNode( *rReportVector.GetRootNode(), rReportVector.rVector), 0);
}

/*
//Clear all data contents.
inline void DRS_ReportVectorTree::Clear()
{ GetRootNode()->Clear();};
*/

//Load record
void DRS_ReportVectorTree::operator<< ( DRS_RecordSet &rRecord)
{
  Clear();  //Delete tree (only root remains).


  //Get occurrences (ordinal vector numbers in record) and cycle occurrences, adding nodes.

  /*
  'TODO
  'Cannot pass vectors between dlls that allocate on the vectror!!!!!
  'MUST be changed before reporting becomes a separate dll from atappl.
  */
  std::vector<uint> vOccurrences;

  rVector.VectorOccurrences( rRecord, &vOccurrences, (const VectorAddress*) addrSelector);

  for( std::vector<uint>::iterator iter = vOccurrences.begin(); iter != vOccurrences.end(); iter ++)
    {
    //Get address of occurrence and add to root.
    auto_array<uint32> addrVector( new uint32[rVector.Depth()]);
    rVector.GetVectorAddress( rRecord, *iter, addrVector.get());

    DRS_VectorData oData( rRecord, rVector, *iter);

    //DRS_ReportVectorTreeNode const * pRootNode = GetRootNode();
    //  if( DRS_ReportVectorTreeSumNode const * pSumNode = dynamic_cast<DRS_ReportVectorTreeSumNode const *> (pRootNode))
    //    pSumNode->LoadRecord( rRecord, addrVector.get(), rVector, rVector.GetRootDim());
    //  else
        Root().LoadData( addrVector.get(), rVector.GetRootDim(), oData, true);

    }
}

void DRS_ReportVectorTree::addTree (DRS_ReportVectorTree const &rhs)
{
  Root().addTreeNode(rhs.Root());
};

void DRS_ReportVectorTree::operator+= (const DRS_ReportVectorTree &rhs)
{
  const_cast<DRS_ReportVectorTreeNode&>(Root()) += rhs.Root();
};

//DRS_ReportVectorTreeNode
//Copy constructor
DRS_ReportVectorTreeNode::DRS_ReportVectorTreeNode( DRS_ReportVectorTreeNode const &rNode, DRS_Vector const &rVector)
    : DRS_TreeNodeMapped<DRS_ReportVectorTreeNode>( rNode), last_address(rNode.last_address),
    has_data(rNode.has_data)
{
  //Copy children
    uint iChildren = rNode.ChildCount();
    for( uint i = 0; i < iChildren; i++)
      {
      DRS_ReportVectorTreeNode const *pChild = rNode.GetChildAbs(i);

      if( DRS_ReportVectorTreeSumNode const * pSumChild = dynamic_cast<DRS_ReportVectorTreeSumNode const *>(pChild) )
        InheretChild( new DRS_ReportVectorTreeSumNode( *pSumChild));
      else
        InheretChild( new DRS_ReportVectorTreeNode( *pChild, rVector));
      }

}

/* Obsolete  */
#if 0
void DRS_ReportVectorTreeNode::AddVectorAddress( uint32 *pVectorIDs, DRS_VectorDim const *pDim, DRS_Vector const &rVector)
{
  AT_Assert( pDim, *this, "Expected dim.")
  if( !pDim->GetChild()) return; //root can be only node for 0 depth vectors such as calls. throw AT_Unexpected_Err;

       /*********************************************************************************
       Vector Dims are either:
         disparate
         collective
             mapped to child
             summed as sumnode
       All dims may be constant.

       When a node adds a child:
         If the child dim is collective
           if sum mapped to child, assure sum child included
           else add sum node.
         Otherwise its disparate
           Add just this child.

       /*********************************************************************************/


           if( pDim->GetChild()->IsCollective() ) //If child level is collective, collect sum
             {

             if( pDim->IsMappedToChild()) //If mapped to child, included mapped child
               {
               if( ! GetChildNoRaise(pDim->MappedToChild()))
                 {
                   InheretChild( new DRS_ReportVectorTreeNode( pDim->MappedToChild(), rVector))
                             ->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);
                 }
               else //Add vector address to exisiting mapped child
                 GetChild(pDim->MappedToChild())
                             ->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);
               }

             else //Else add SumNode as child
               {
               //Add SumChild IFF not already avail
               if( ! ChildCount() || ! GetChildNoRaise( REPORTVECTORSUMNODE_ID))
                 {
                 InheretChild( new DRS_ReportVectorTreeSumNode())->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);
                 }
               else // Add vector address to existing SumChild
                 GetChild( REPORTVECTORSUMNODE_ID)
                             ->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);
               }
             } //collective children

           //Add requested child
           //If child is -1, add all children
           if( pVectorIDs[pDim->Dim()] == MAXUINT)
             {

             }
           else
             {
             //If child node avail, add to child, else create new child
             if( DRS_ReportVectorTreeNode * pChild = GetChildNoRaise( pVectorIDs[pDim->Dim()]))
               pChild->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);
             else
               {
                 InheretChild( new DRS_ReportVectorTreeNode(pVectorIDs[pDim->Dim()]))
                  ->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);
               }
             }

}
#endif

/*
//Clear contents
void DRS_ReportVectorTreeNode::Clear()
{
    //Clear each child
    for( uint i = 0; i < ChildCount(); i++) GetChildAbs(i)->Clear();

    if( apVectorData.get() )
      apVectorData->Clear();

}
*/

//Load record.
//Create nodes for address.
void DRS_ReportVectorTreeNode::LoadData( uint32 *addrVector, DRS_VectorDim const *pDim, DRS_VectorData const &rData, bool hasData)
{
  const DRS_Vector& rVector = *rData.GetVector();
  has_data = hasData;
   
  //If leaf, get data
  if( pDim->Dim() == rVector.Depth())
    {
    //Leaf
    AT_Assert( !pDim->GetChild(), *this, "Expected leaf.");

    if( ! apVectorData.get())
      //Create data vector
      apVectorData.reset( new DRS_VectorData(rData));
    else
      *apVectorData.get() = rData;
    return;
    }

  AT_Assert( pDim->GetChild(), *this, "Expected node.");

  //Create nodes for address.
  //If child node avail, add to child, else create new child
  if( DRS_ReportVectorTreeNode * pChild = GetChildNoRaise( addrVector[pDim->Dim()]))
    pChild->LoadData( addrVector, pDim->GetChild(), rData, hasData);
  else
    {
// AV I do not know what this code is for but it causing the problem!!!
//    if( (pDim->Dim() == 2) && (addrVector[pDim->Dim()-1] > 17))
//      {
//      addrVector[pDim->Dim()-1] = 18;
//      }

    // inheret all children in between to get the same tree structure as
    // application vector
    DRS_VectorData null_data(rVector);
    for (uint i = last_address; i < addrVector[pDim->Dim()]; ++i)
    {
      pChild = GetChildNoRaise( i);
      if (!pChild)
        InheretChild( new DRS_ReportVectorTreeNode( i))
            ->LoadData( addrVector, pDim->GetChild(), null_data, false);
    }
    InheretChild( new DRS_ReportVectorTreeNode(addrVector[pDim->Dim()]))
         ->LoadData( addrVector, pDim->GetChild(), rData, hasData);
    last_address = max((uint32)last_address, addrVector[pDim->Dim()]);
    }
}

//Add tree node
void DRS_ReportVectorTreeNode::operator+= (DRS_ReportVectorTreeNode const &src)
{
  for( uint i = 0; i < src.ChildCount(); i++)
    {
    //If I have the child, add to that child,
    DRS_ReportVectorTreeNode * srcChild = src.GetChildAbs( i);
    has_data |= srcChild->hasData();

    if( DRS_ReportVectorTreeNode * myChild = GetChildNoRaise( srcChild->ID()))
      {
      *myChild += *srcChild;
      }
    //Else create new child and add
    else
      {
      *InheretChild( new DRS_ReportVectorTreeNode( srcChild->ID())) += *srcChild;
      }
      
    }// for each child

  if( src.VectorData())
    {
    has_data |= src.hasData();
    //Add datavectors.
    if( !apVectorData.get() )
      apVectorData.reset( new DRS_VectorData( *(src.VectorData())));
    else
      *apVectorData += *(src.VectorData());
    }
}

//Add tree node
void DRS_ReportVectorTreeNode::addTreeNode (DRS_ReportVectorTreeNode const &src)
{
  for( uint i = 0; i < src.ChildCount(); i++)
    {
    //If I have the child, add to that child,
    DRS_ReportVectorTreeNode * srcChild = src.GetChildAbs( i);
    has_data |= srcChild->hasData();
    
    if (srcChild->hasData())
      {
      if( DRS_ReportVectorTreeNode * myChild = GetChildNoRaise( srcChild->ID()))
        {
        myChild->addTreeNode(*srcChild);
        }
      //Else create new child and add
      else
        {
        InheretChild( new DRS_ReportVectorTreeNode( srcChild->ID()))->addTreeNode(*srcChild);
        }

      }// for each child
    }// if has data

  if( src.VectorData())
    {
    has_data |= src.hasData();
    
    //Add datavectors.
    if( !apVectorData.get() )
      apVectorData.reset( new DRS_VectorData( *(src.VectorData())));
    else
      *apVectorData += *(src.VectorData());
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
//DRS_ReportVewctorTreeSumNode
////////////////////////////////////////////////////////////////////////////////////////////////////////

void DRS_ReportVectorTreeSumNode::LoadRecord( DRS_RecordSet &rRecord, uint32 *addrVector, DRS_Vector const & rVector, DRS_VectorDim const *pDim)
{
  throw AT_Function_Err( *this, "LoadRecord()");

//Temporarily disabled for ims
#if 0

  if( ChildCount())
    {
    //Node
    AT_Assert( !pDim->GetChild(), *this, "Expected node.");

    if( pDim->Dim()) addrVector[pDim->Dim() - 1] = ID();

    //Clear children
    uint iChildren = ChildCount();
    for( uint j = 0; j < iChildren; j++)
      GetChildAbs(j)->Clear();

    //For each child, load record
    for( uint i = 0; i < iChildren; i++)
      {
      DRS_ReportVectorTreeNode const * pChildNode = GetChildAbs(i);
      if( DRS_ReportVectorTreeSumNode const * pSumNode = dynamic_cast<DRS_ReportVectorTreeSumNode const *> (pChildNode))
        pSumNode->LoadRecord( rRecord, addrVector, rVector, pDim->GetChild());
      else
        pChildNode->LoadRecord( rRecord, addrVector, rVector, pDim->GetChild());
      }
    }
  else //Leaf
    {
    //Add data from every sibling
    DRS_VectorData CurVector( rVector);

    for( uint i = rVector.Node( pDim->Dim() - 1, addrVector).ChildCount(); i > 0; i--)
     {
     //addrVector[pDim->Dim()-1] = i-1;
     addrVector[pDim->Dim()-1] = i-1;
     CurVector.LoadRecord( rRecord, addrVector, rVector);
     *apVectorData += CurVector;
     }
  }
#endif
}

#if 0
void DRS_ReportVectorTreeSumNode::AddVectorAddress( uint32 *pVectorIDs, DRS_VectorDim const *pDim, DRS_Vector const &rVector)
{
  //If not at end of tree, add sum node.
  //1 for each if disparet.
  //1 for all if collective.

  //Leaf does nothing
  if( ! pDim->GetChild() ) return;

  //Node

           //ReportVectorNodes maintain a SumChildNode|Leaf IFF children are collective/not_mapped.
           //Add SumNode/Leaf iff child dim is collective and sum is NOT ammped to child
           if( pDim->GetChild()->IsCollective() )
             {
             //Add one sum node for collective child
                   InheretChild( new DRS_ReportVectorTreeSumNode()
                                         )->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);



             /*
             //If mapped to child, assure mapped child included
             if( pDim->IsMappedToChild())
               {
               if( ! GetChildNoRaise(pDim->MappedToChild()))
                 {
                 //Add mapped child (could be leaf), Add vector address to new child
                 InheretChild( pDim->GetChild()->GetChild() ?
                                new DRS_ReportVectorTreeNode( pDim->MappedToChild()) :
                                new DRS_ReportVectorTreeLeaf( pDim->MappedToChild(), rVector)
                             )->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);
                 }
               }
             //Else add SumChildNode
             else
               {
               //Add SumChild IFF not already avail
               if( ! ChildCount() || ! GetChildNoRaise( REPORTVECTORSUMNODE_ID))
                 {
                 //Attach DRS_ReportVectorTreeSumNode/Leaf
                 if( pDim->GetChild()->GetChild())
                   InheretChild( new DRS_ReportVectorTreeSumNode()
                             )->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);
                 else
                   InheretChild(new DRS_ReportVectorTreeSumLeaf( rVector)
                             )->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);
                 }
               }
             */
             }
           else //Children are disparate. Add one sum node for each child in Vector.
             {
             for( uint i = 0; i < rVector.Node(pDim->Dim(), pVectorIDs).ChildCount() - 1; i++)
               {
               InheretChild( new DRS_ReportVectorTreeSumNode( i ))
                  ->AddVectorAddress( pVectorIDs, pDim->GetChild(), rVector);

               }

             }

} //AddVectorAddress
#endif


