/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Public Attributes | Private Attributes
Alg1 Class Reference

prototype for a processor More...

#include <Alg1.h>

Collaboration diagram for Alg1:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Alg1 (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor of this form must be provided.
StatusCode initialize ()
 Three mandatory member functions of any algorithm.
StatusCode execute ()
 Goal of execute(): Consumer&Producer: Push an element into StageData.
StatusCode finalize ()
StatusCode beginRun ()
StatusCode endRun ()

Public Attributes

tuple g = gm.AppMgr()
tuple a1 = g.algorithm('Alg1')
tuple msv = g.service('MessageSvc')

Private Attributes

bool m_initialized
std::string m_ThisStageName
 These data members are used in the execution of this algorithm They are set in the initialisation phase by the job options service.
IStagem_ThisStage
std::string m_LowerStageName
IStagem_LowerStage
FFTimeStamp m_CurrentTime
 The earliest (smallest) time which this has provided.
FakeDataList m_FakeDataList
 This is for Consumer&Producer only.
bool m_Start

Detailed Description

prototype for a processor

Here all possible situations are considered. Other Algs are just copies of this while maybe with different configuration.

Wang, Mar 21, 2008

Definition at line 24 of file Alg1.h.


Constructor & Destructor Documentation

Alg1::Alg1 ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Constructor of this form must be provided.

Definition at line 16 of file Alg1.cpp.

           : Algorithm(name, ploc) {
//------------------------------------------------------------------------------
  m_initialized = false;
  
  declareProperty("ThisStageName",m_ThisStageName, "Name of this stage");
  declareProperty("LowerStageName",m_LowerStageName, "Name of the lower stage");

}

Member Function Documentation

StatusCode Alg1::initialize ( )

Three mandatory member functions of any algorithm.

Definition at line 27 of file Alg1.cpp.

                            {
//------------------------------------------------------------------------------
  // avoid calling initialize more than once
  if( m_initialized ) return StatusCode::SUCCESS;

  MsgStream log(msgSvc(), name());
  log << MSG::DEBUG << "initializing...." << endreq;
  log << MSG::DEBUG << "Current Stage " <<m_ThisStageName <<endreq;
  log << MSG::DEBUG << "Lower Stage " <<m_LowerStageName <<endreq;

  StatusCode sc;

  // =========
  sc= toolSvc()->retrieveTool("Stage",m_ThisStageName,m_ThisStage);
  if( sc.isFailure() ) {
    log << MSG::ERROR << "Error retrieving the public tool" << endreq;
  }
  // =========
  int diff;
  diff = m_LowerStageName.compare("null");
  if(diff!=0) {
    sc= toolSvc()->retrieveTool("Stage",m_LowerStageName,m_LowerStage);
    if( sc.isFailure() ) {
      log << MSG::ERROR << "Error retrieving the public tool" << endreq;
    }
  } else {
    m_LowerStage=0;
  }

  // Although initialized to 0, however, no special meaning
  m_CurrentTime=0;

  m_FakeDataList.clear();

  m_initialized = true;

  m_Start=true;

  return StatusCode::SUCCESS;
}
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.

                         {
//------------------------------------------------------------------------------
  MsgStream  log( msgSvc(), name() );
  log << MSG::DEBUG << "begin of execute()" << endreq;

  FakeDataList::iterator pfakedatalist;

  FFTimeStamp localtime(0,0);

  // Random number (to generate random integer 0,1,2,3)
  Rndm::Numbers flat(randSvc(),Rndm::Flat(0,3.1));

  if(m_LowerStage!=0) {
    log << MSG::DEBUG << "Consumer&Producer" << endreq;
    if(m_Start||m_CurrentTime<=m_ThisStage->currentTime()) {
      
      if(m_Start) {
        // nothing to do
      } else {
        pfakedatalist=m_FakeDataList.begin();
        localtime=pfakedatalist->first;
      }

      while(m_Start||localtime>=m_LowerStage->currentTime()) {
        m_Start=false;
        log << MSG::DEBUG << "In while loop, pulling data from lower Stage ......" << endreq;   
        
        IStageData* pIStageData=0;
        StatusCode sc = m_LowerStage->nextElement(pIStageData);  // pulling out
        if (sc.isFailure()) {
            log << MSG::ERROR
                << "Failed to get next element from lower stage" << endreq;
            return StatusCode::FAILURE;
        }
        
        FakeData* pFakeData=dynamic_cast<FakeData*>(pIStageData);
        if (!pFakeData) {
            log << MSG::ERROR
                << "Recieved unknown type of data from lower stage"
                << endreq;
            return StatusCode::FAILURE;
        }

        //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        // destroy the used one
        FFTimeStamp dt=flat();

        FFTimeStamp tm=pFakeData->time();
        log << MSG::DEBUG << "data pulled out from lower stage has time: "<<tm<<endreq;
        delete pFakeData;
        log << MSG::DEBUG << "data from lower stage is consumed"<<endreq;
        // generate new one
        FakeData* pFD=new FakeData(tm+dt);
        log << MSG::DEBUG << "new data generated at time: "<< pFD->time()<< endreq;
        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        // push back into a local store
        m_FakeDataList.insert(FakeDataList::value_type(pFD->time(),pFD));

        pfakedatalist=m_FakeDataList.begin();
        localtime=pfakedatalist->first;
      }

      m_CurrentTime=localtime;
      log << MSG::DEBUG << "m_CurrentTime= "<< m_CurrentTime << endreq;

      if (m_FakeDataList.size()) {
          pfakedatalist=m_FakeDataList.begin();
          log << MSG::DEBUG << "new data pushed out at time " << pfakedatalist->first << endreq;
          
          m_ThisStage->pushElement(pfakedatalist->second);
          m_FakeDataList.erase(pfakedatalist);
      }
      else {
          log << MSG::WARNING 
              << "I have no more data to give" << endreq;
      }

    }
  }

  
  if(m_LowerStage==0) {
    log << MSG::DEBUG << "Producer" << endreq;
    if(m_Start||m_CurrentTime<=m_ThisStage->currentTime()) {
      
      m_Start=false;
      FFTimeStamp dt=flat();
      FakeData* pFD=new FakeData(m_CurrentTime+dt);
      
      m_CurrentTime=pFD->time();
      m_ThisStage->pushElement(pFD);
      log << MSG::DEBUG << "a data is generated: time = "<< pFD->time() <<endreq; 
    }
  }

  log << MSG::DEBUG << "execute() end "<<endreq;
  return StatusCode::SUCCESS;
}
StatusCode Alg1::finalize ( )

Definition at line 205 of file Alg1.cpp.

                          {
//------------------------------------------------------------------------------
  MsgStream log(msgSvc(), name());
  log << MSG::INFO << "finalizing...." << endreq;

  m_initialized = false;
  return StatusCode::SUCCESS;
}
StatusCode Alg1::beginRun ( )

Definition at line 214 of file Alg1.cpp.

                          {
//------------------------------------------------------------------------------
  MsgStream log(msgSvc(), name());
  log << MSG::INFO << "beginning new run...." << endreq;
  
  m_initialized = true;
  return StatusCode::SUCCESS;
}
StatusCode Alg1::endRun ( )

Definition at line 225 of file Alg1.cpp.

                        {
//------------------------------------------------------------------------------
  MsgStream log(msgSvc(), name());
  log << MSG::INFO << "ending new run...." << endreq;
  
  m_initialized = true;
  return StatusCode::SUCCESS;
}

Member Data Documentation

bool Alg1::m_initialized [private]

Definition at line 36 of file Alg1.h.

std::string Alg1::m_ThisStageName [private]

These data members are used in the execution of this algorithm They are set in the initialisation phase by the job options service.

Definition at line 39 of file Alg1.h.

Definition at line 40 of file Alg1.h.

std::string Alg1::m_LowerStageName [private]

Definition at line 42 of file Alg1.h.

Definition at line 43 of file Alg1.h.

The earliest (smallest) time which this has provided.

Definition at line 46 of file Alg1.h.

This is for Consumer&Producer only.

For new generated data.

Definition at line 50 of file Alg1.h.

bool Alg1::m_Start [private]

Definition at line 53 of file Alg1.h.

tuple Alg1::g = gm.AppMgr()

Definition at line 3 of file Alg1.py.

tuple Alg1::a1 = g.algorithm('Alg1')

Definition at line 9 of file Alg1.py.

tuple Alg1::msv = g.service('MessageSvc')

Definition at line 11 of file Alg1.py.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:07:57 for Alg1 by doxygen 1.7.4