| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Alg1 Namespace Reference


Functions

 Alg1 (const std::string &name, ISvcLocator *ploc)
StatusCode initialize ()
StatusCode execute ()
 Goal of execute(): Consumer&Producer: Push an element into StageData.
StatusCode finalize ()
StatusCode beginRun ()
StatusCode endRun ()

Function Documentation

Alg1::Alg1 ( const std::string &  name,
ISvcLocator ploc 
)

Definition at line 16 of file Alg1.cpp.

00017            : Algorithm(name, ploc) {
00018 //------------------------------------------------------------------------------
00019   m_initialized = false;
00020   
00021   declareProperty("ThisStageName",m_ThisStageName, "Name of this stage");
00022   declareProperty("LowerStageName",m_LowerStageName, "Name of the lower stage");
00023 
00024 }

StatusCode Alg1::initialize (  ) 

Definition at line 27 of file Alg1.cpp.

00027                             {
00028 //------------------------------------------------------------------------------
00029   // avoid calling initialize more than once
00030   if( m_initialized ) return StatusCode::SUCCESS;
00031 
00032   MsgStream log(msgSvc(), name());
00033   log << MSG::DEBUG << "initializing...." << endreq;
00034   log << MSG::DEBUG << "Current Stage " <<m_ThisStageName <<endreq;
00035   log << MSG::DEBUG << "Lower Stage " <<m_LowerStageName <<endreq;
00036 
00037   StatusCode sc;
00038 
00039   // =========
00040   sc= toolSvc()->retrieveTool("Stage",m_ThisStageName,m_ThisStage);
00041   if( sc.isFailure() ) {
00042     log << MSG::ERROR << "Error retrieving the public tool" << endreq;
00043   }
00044   // =========
00045   int diff;
00046   diff = m_LowerStageName.compare("null");
00047   if(diff!=0) {
00048     sc= toolSvc()->retrieveTool("Stage",m_LowerStageName,m_LowerStage);
00049     if( sc.isFailure() ) {
00050       log << MSG::ERROR << "Error retrieving the public tool" << endreq;
00051     }
00052   } else {
00053     m_LowerStage=0;
00054   }
00055 
00056   // Although initialized to 0, however, no special meaning
00057   m_CurrentTime=0;
00058 
00059   m_FakeDataList.clear();
00060 
00061   m_initialized = true;
00062 
00063   m_Start=true;
00064 
00065   return StatusCode::SUCCESS;
00066 }

StatusCode Alg1::execute (  ) 

Goal of execute(): Consumer&Producer: Push an element into StageData.

It might consume many elements from lower stage. It might store many elements. Producer: Get one element into StageData.

=====))))) Consumer&Producer:

Principle: make sure the data provided is really the earliest (with smallest time)

the core part begins ///////// determine localtime, it is not m_CurrentTime

localtime must go beyond lower stage to make sure output is safe

pulling event from lower stage

fake code begins //////////////////

destroy the data pulled out generate some new data This process is like to take some input after use then produce new data

find out the min time

get the data with smallest time push it into current stage and delete it.

=====))))) Producer: generate data by myself

fake code begins ////////////////// The following should be replace by real stuff.

update my current time

push it into StageData

Definition at line 78 of file Alg1.cpp.

00078                          {
00079 //------------------------------------------------------------------------------
00080   MsgStream  log( msgSvc(), name() );
00081   log << MSG::DEBUG << "begin of execute()" << endreq;
00082 
00083   FakeDataList::iterator pfakedatalist;
00084 
00085   FFTimeStamp localtime(0,0);
00086 
00087   // Random number (to generate random integer 0,1,2,3)
00088   Rndm::Numbers flat(randSvc(),Rndm::Flat(0,3.1));
00089 
00091   if(m_LowerStage!=0) {
00094     log << MSG::DEBUG << "Consumer&Producer" << endreq;
00095     if(m_Start||m_CurrentTime<=m_ThisStage->currentTime()) {
00096       
00099       if(m_Start) {
00100         // nothing to do
00101       } else {
00102         pfakedatalist=m_FakeDataList.begin();
00103         localtime=pfakedatalist->first;
00104       }
00105 
00107       while(m_Start||localtime>=m_LowerStage->currentTime()) {
00108         m_Start=false;
00110         log << MSG::DEBUG << "In while loop, pulling data from lower Stage ......" << endreq;   
00111         
00112         IStageData* pIStageData=0;
00113         StatusCode sc = m_LowerStage->nextElement(pIStageData);  // pulling out
00114         if (sc.isFailure()) {
00115             log << MSG::ERROR
00116                 << "Failed to get next element from lower stage" << endreq;
00117             return StatusCode::FAILURE;
00118         }
00119         
00120         FakeData* pFakeData=dynamic_cast<FakeData*>(pIStageData);
00121         if (!pFakeData) {
00122             log << MSG::ERROR
00123                 << "Recieved unknown type of data from lower stage"
00124                 << endreq;
00125             return StatusCode::FAILURE;
00126         }
00127 
00128         //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
00136         // destroy the used one
00137         FFTimeStamp dt=flat();
00138 
00139         FFTimeStamp tm=pFakeData->time();
00140         log << MSG::DEBUG << "data pulled out from lower stage has time: "<<tm<<endreq;
00141         delete pFakeData;
00142         log << MSG::DEBUG << "data from lower stage is consumed"<<endreq;
00143         // generate new one
00144         FakeData* pFD=new FakeData(tm+dt);
00145         log << MSG::DEBUG << "new data generated at time: "<< pFD->time()<< endreq;
00147         //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
00148 
00149         // push back into a local store
00150         m_FakeDataList.insert(FakeDataList::value_type(pFD->time(),pFD));
00151 
00153         pfakedatalist=m_FakeDataList.begin();
00154         localtime=pfakedatalist->first;
00155       }
00156 
00157       m_CurrentTime=localtime;
00158       log << MSG::DEBUG << "m_CurrentTime= "<< m_CurrentTime << endreq;
00159 
00160       if (m_FakeDataList.size()) {
00163           pfakedatalist=m_FakeDataList.begin();
00164           log << MSG::DEBUG << "new data pushed out at time " << pfakedatalist->first << endreq;
00165           
00166           m_ThisStage->pushElement(pfakedatalist->second);
00167           m_FakeDataList.erase(pfakedatalist);
00168       }
00169       else {
00170           log << MSG::WARNING 
00171               << "I have no more data to give" << endreq;
00172       }
00173 
00175     }
00176   }
00177 
00178   
00180   if(m_LowerStage==0) {
00181     log << MSG::DEBUG << "Producer" << endreq;
00182     if(m_Start||m_CurrentTime<=m_ThisStage->currentTime()) {
00183       
00184       m_Start=false;
00187       FFTimeStamp dt=flat();
00188       FakeData* pFD=new FakeData(m_CurrentTime+dt);
00190       
00192       m_CurrentTime=pFD->time();
00194       m_ThisStage->pushElement(pFD);
00195       log << MSG::DEBUG << "a data is generated: time = "<< pFD->time() <<endreq; 
00196     }
00197   }
00198 
00199   log << MSG::DEBUG << "execute() end "<<endreq;
00200   return StatusCode::SUCCESS;
00201 }

StatusCode Alg1::finalize (  ) 

Definition at line 205 of file Alg1.cpp.

00205                           {
00206 //------------------------------------------------------------------------------
00207   MsgStream log(msgSvc(), name());
00208   log << MSG::INFO << "finalizing...." << endreq;
00209 
00210   m_initialized = false;
00211   return StatusCode::SUCCESS;
00212 }

StatusCode Alg1::beginRun (  ) 

Definition at line 214 of file Alg1.cpp.

00214                           {
00215 //------------------------------------------------------------------------------
00216   MsgStream log(msgSvc(), name());
00217   log << MSG::INFO << "beginning new run...." << endreq;
00218   
00219   m_initialized = true;
00220   return StatusCode::SUCCESS;
00221 }

StatusCode Alg1::endRun (  ) 

Definition at line 225 of file Alg1.cpp.

00225                         {
00226 //------------------------------------------------------------------------------
00227   MsgStream log(msgSvc(), name());
00228   log << MSG::INFO << "ending new run...." << endreq;
00229   
00230   m_initialized = true;
00231   return StatusCode::SUCCESS;
00232 }

| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:37:09 2011 for Alg1 by doxygen 1.4.7