00001 /* 00002 // $Id: //open/dev/fennel/lucidera/bitmap/LbmNormalizerExecStream.cpp#4 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2005-2009 LucidEra, Inc. 00005 // Copyright (C) 2005-2009 The Eigenbase Project 00006 // 00007 // This program is free software; you can redistribute it and/or modify it 00008 // under the terms of the GNU General Public License as published by the Free 00009 // Software Foundation; either version 2 of the License, or (at your option) 00010 // any later version approved by The Eigenbase Project. 00011 // 00012 // This program is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the Free Software 00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #include "fennel/common/CommonPreamble.h" 00023 #include "fennel/exec/ExecStreamBufAccessor.h" 00024 #include "fennel/lucidera/bitmap/LbmNormalizerExecStream.h" 00025 00026 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/lucidera/bitmap/LbmNormalizerExecStream.cpp#4 $"); 00027 00028 void LbmNormalizerExecStream::prepare( 00029 LbmNormalizerExecStreamParams const ¶ms) 00030 { 00031 ConduitExecStream::prepare(params); 00032 00033 keyBitmapDesc = pInAccessor->getTupleDesc(); 00034 keyBitmapAccessor.compute(keyBitmapDesc); 00035 keyBitmapData.compute(keyBitmapDesc); 00036 00037 // temporarily fake a key projection 00038 keyProj = params.keyProj; 00039 keyDesc.projectFrom(keyBitmapDesc, keyProj); 00040 keyData.compute(keyDesc); 00041 } 00042 00043 void LbmNormalizerExecStream::open(bool restart) 00044 { 00045 ConduitExecStream::open(restart); 00046 segmentReader.init(pInAccessor, keyBitmapData); 00047 producePending = false; 00048 } 00049 00050 ExecStreamResult LbmNormalizerExecStream::execute( 00051 ExecStreamQuantum const &quantum) 00052 { 00053 ExecStreamResult rc; 00054 00055 for (uint i = 0; i < quantum.nTuplesMax; i++) { 00056 while (! producePending) { 00057 rc = readSegment(); 00058 if (rc == EXECRC_EOS) { 00059 pOutAccessor->markEOS(); 00060 return rc; 00061 } else if (rc != EXECRC_YIELD) { 00062 return rc; 00063 } 00064 assert (producePending); 00065 } 00066 if (! produceTuple()) { 00067 return EXECRC_BUF_OVERFLOW; 00068 } 00069 } 00070 return EXECRC_QUANTUM_EXPIRED; 00071 } 00072 00073 ExecStreamResult LbmNormalizerExecStream::readSegment() 00074 { 00075 assert (! producePending); 00076 00077 ExecStreamResult rc = segmentReader.readSegmentAndAdvance( 00078 segment.byteNum, segment.byteSeg, segment.len); 00079 if (rc == EXECRC_YIELD) { 00080 producePending = true; 00081 nTuplesPending = segment.countBits(); 00082 assert (nTuplesPending > 0); 00083 } 00084 return rc; 00085 } 00086 00087 bool LbmNormalizerExecStream::produceTuple() 00088 { 00089 assert(producePending); 00090 00091 // manually project output keys from the current tuple 00092 if (segmentReader.getTupleChange()) { 00093 for (uint i = 0; i < keyProj.size(); i++) { 00094 keyData[i] = keyBitmapData[keyProj[i]]; 00095 } 00096 segmentReader.resetChangeListener(); 00097 } 00098 00099 if (pOutAccessor->produceTuple(keyData)) { 00100 nTuplesPending--; 00101 if (nTuplesPending == 0) { 00102 producePending = false; 00103 } 00104 return true; 00105 } 00106 return false; 00107 } 00108 00109 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/lucidera/bitmap/LbmNormalizerExecStream.cpp#4 $"); 00110 00111 // End LbmNormalizerExecStream.cpp