/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 | Private Attributes
DybTrimIO Class Reference

#include <DybTrimIO.h>

Collaboration diagram for DybTrimIO:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DybTrimIO (const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize ()
StatusCode execute ()
StatusCode finalize ()

Private Attributes

bool m_saveFlag
std::string m_nowLocation
std::string m_regSeqLocation
ISaveB4TrimAesSvcm_pSaveB4TrimAesSvc
 all the needed services //////////////// Save before trimming
std::string m_pSaveB4TrimAesSvcName
IDybStorageSvcm_pDybStorageSvc
 dyb storage which do the real IO stuff
std::string m_pDybStorageSvcName
IDataManagerSvc * m_pArchiveSvc
 AES.
std::string m_pArchiveSvcName
IArchiveTrimSvcm_pTrimSvc
 triming
std::string m_pTrimSvcName

Detailed Description

Definition at line 26 of file DybTrimIO.h.


Constructor & Destructor Documentation

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

Definition at line 27 of file DybTrimIO.cc.

                                                                   :
  GaudiAlgorithm(name, pSvcLocator),
  m_pSaveB4TrimAesSvc(0),
  m_pDybStorageSvc(0),
  m_pArchiveSvc(0),
  m_pTrimSvc(0)
{
  declareProperty("SaveFlag",m_saveFlag=false,"Save or not");

  declareProperty("NowLocation",
                  m_nowLocation =  DayaBay::RegistrationSequenceLocation::Default, 
                  "Location to determine current time, default: RegistrationSequence");

  declareProperty("RegSeqLocation",
                  m_regSeqLocation=DayaBay::RegistrationSequenceLocation::Default,
                  "Location to RegistrationSequence");

  declareProperty("SaveB4TrimAesSvc",
                  m_pSaveB4TrimAesSvcName="SaveB4TrimAesSvc",
                  "Name of SaveB4TrimAesSvc");

  declareProperty("DybStorageSvc",
                  m_pDybStorageSvcName="DybStorageSvc",
                  "Name of an IDybStorageSvc");

  declareProperty("ArchiveSvc",
                  m_pArchiveSvcName="EventDataArchiveSvc",
                  "Name of AES");

  declareProperty("TrimSvc",
                  m_pTrimSvcName="ArchiveTrimSvc",
                  "Name of trimming service");

}

Member Function Documentation

StatusCode DybTrimIO::initialize ( )

all done now.

Definition at line 64 of file DybTrimIO.cc.

{
  //
  StatusCode status;
  debug() << " DybTrimIO initialize()" << endreq;

  if ( m_saveFlag ) {
    // SaveB4TrimAesSvc
    status = service(m_pSaveB4TrimAesSvcName,
                     m_pSaveB4TrimAesSvc);

    debug()<<"m_pSaveB4TrimAesSvc "<<m_pSaveB4TrimAesSvc<<endreq;
    if (status.isFailure()) {
      error()<<"Service [SaveB4TrimAesSvc] not found"<<endreq;
      return StatusCode::FAILURE;
    }

    // DybStorageSvc 
    status = service(m_pDybStorageSvcName,
                     m_pDybStorageSvc);
    
    debug()<<"m_pDybStorageSvc "<<m_pDybStorageSvc<<endreq;
    if (status.isFailure()) {
      error()<<"Service [DybStorageSvc] not found"<<endreq;
      return StatusCode::FAILURE;
    }
  }

  // Get archive store
  status = service(m_pArchiveSvcName,
                   m_pArchiveSvc);

  debug()<<"m_pArchiveSvc "<<m_pArchiveSvc<<endreq;
  if (status.isFailure()) {
    error()<<"Service [EventDataArchiveSvc] not found"<<endreq;
    return StatusCode::FAILURE;
  }

  // Get trimming Svc
  status = service(m_pTrimSvcName,
                   m_pTrimSvc);

  debug()<<"m_pTrimSvc "<<m_pTrimSvc<<endreq;
  if (status.isFailure()) {
    error()<<"Service [ArchiveTrimSvc] not found"<<endreq;
    return StatusCode::FAILURE;
  }

  return StatusCode::SUCCESS;
}
StatusCode DybTrimIO::execute ( )

Definition at line 161 of file DybTrimIO.cc.

{
  StatusCode sc;
  
  // get the data object at the "now" location
  SmartDataPtr<const DayaBay::RegistrationSequence> 
              pTemporal(eventSvc(),m_regSeqLocation);
  // check the pointer
  if (0 == pTemporal) {
    error()<<"Failed to retrieve RegistrationSequence from Event Store from "
           << m_regSeqLocation
           <<endreq;
    return StatusCode::FAILURE;
  }
  
  // save before trim
  if(m_saveFlag) {
    sc = m_pSaveB4TrimAesSvc->store(m_regSeqLocation,
                                    m_pDybStorageSvc,
                                    m_pArchiveSvc,
                                    m_pTrimSvc,
                                    pTemporal->earliest());
    if(sc.isFailure()) {
      debug()<<"Failed to write"<<endreq;
      return StatusCode::FAILURE;
    }
  }

  // Create handle to AES
  static DataSvc* pAes=0;
  if(!pAes){
    try{
      pAes=dynamic_cast<DataSvc*>(m_pArchiveSvc);
    }
    catch(...) {
      error() <<"Failed to cast AES" << endreq;
      return StatusCode::FAILURE;
    }
  }

  // Catch new data paths, index
  static std::map<std::string,DybArchiveList*> archiveMap;
  // First, catch the registration sequence archive
  if(archiveMap.empty()){
    DataObject* pObj=0;      
    StatusCode sc = pAes->retrieveObject(m_regSeqLocation,pObj);
    if(sc.isFailure()) {
      error() << "Failed to get archive for " << m_regSeqLocation << endreq;
      return StatusCode::FAILURE;
    }
    // Get Archive List
    DybArchiveList* pArchiveList=0;
    try{
      pArchiveList=dynamic_cast<DybArchiveList*>(pObj);
    }
    catch (...) {
      error() << "Failed to get DybArchiveList " << m_regSeqLocation << endreq;
      return StatusCode::FAILURE;
    }
    archiveMap[m_regSeqLocation] = pArchiveList;
    //info() << "Indexing archive list at " << m_regSeqLocation << endreq;
  }
  // Next, loop over paths in reg seq, and add to index if they are new
  IRegistrationSequence::Registrations::const_iterator regIter, 
    regEnd=pTemporal->registrations().end();
  for(regIter=pTemporal->registrations().begin(); 
      regIter != regEnd; 
      regIter++){
    const ObjectReg& objReg = (*regIter);
    if( archiveMap.find(objReg.path()) == archiveMap.end() ){
      // Found a new data path, add archive list to index
      DataObject* pObj=0;      
      StatusCode sc = pAes->retrieveObject(objReg.path(),pObj);
      if(sc.isFailure()) {
        error() << "Failed to get archive for " << objReg.path() << endreq;
        return StatusCode::FAILURE;
      }
      // Get Archive List
      DybArchiveList* pArchiveList=0;
      try{
        pArchiveList=dynamic_cast<DybArchiveList*>(pObj);
      }
      catch (...) {
        error() << "Failed to get DybArchiveList " << objReg.path() << endreq;
        return StatusCode::FAILURE;
      }
      archiveMap[objReg.path()] = pArchiveList;
      //info() << "Indexing archive list at " << objReg.path() << endreq;
    }
  }

  // Define trimming time window
  double window = m_pTrimSvc->window(m_regSeqLocation);
  TimeStamp threshold = pTemporal->earliest();
  threshold.Add(-1.0 * window);
  // Iterate on known paths, and trim  
  std::map<std::string,DybArchiveList*>::iterator archiveMapIter,
    archiveMapEnd=archiveMap.end();
  for(archiveMapIter=archiveMap.begin();
      archiveMapIter!=archiveMapEnd;
      archiveMapIter++){
    //info() << "trimming " << archiveMapIter->first << endreq;
    DybArchiveList* archiveList = archiveMapIter->second;
    if(archiveList->empty()) continue;
    // Stupid hoops I have to jump through to properly reverse iterate
    // and erase on DybArchiveList
    DybArchiveList::iterator archiveIter = archiveList->end();
    DybArchiveList::iterator archiveBegin = archiveList->begin();
    archiveIter--;
    //int count=0;
    while(true){
      DataObject* dataObject = (*archiveIter);
      // Protect against zero object.
      if ( 0 == dataObject) {
        error() << "Broken object in archive! " << archiveMapIter->first 
                << endreq;
        return StatusCode::FAILURE;
      }
      // Cast to Temporal object
      TemporalDataObject* temporalObject = 0;
      try{
        temporalObject = dynamic_cast<TemporalDataObject*>(dataObject);
      }catch(...){
        error() << "Broken temporal object in archive! " 
                << archiveMapIter->first << endreq;
        return StatusCode::FAILURE;
      }
      //info() << "  Checking object: " << archiveMapIter->first 
      //     << " : " << count << endreq;
      if (temporalObject->earliest() <= threshold) {
        //info() << "    Trimming object: " << archiveMapIter->first << endreq;
        static IIncidentSvc* incSvc=0;
        if(!incSvc){
          StatusCode status = service("IncidentSvc",incSvc,true);
          if (status.isFailure()) {
            return status;
          }
        }
        incSvc->fireIncident(EventStoreIncident(temporalObject,false,
                                                "TrimmingAgent"));
        DybArchiveList::iterator tmpIter(archiveIter);
        // Be sure to iterate before deleting target
        bool lastEntry=false;
        if(archiveIter==archiveBegin){
          lastEntry=true;
        }else{
          archiveIter--;
        }
        archiveList->erase(tmpIter);
        if(lastEntry) break;
        //count++;
      }else{
        // This archive is trimmed enough for now
        break;
      }
    }
  }

  return StatusCode::SUCCESS;
}
StatusCode DybTrimIO::finalize ( )

Definition at line 325 of file DybTrimIO.cc.

{
  StatusCode sc;
  debug() << "DybTrimIO finalize()" << endreq;

  // Trim the rest of elements off
  // Some data might still in AES and hasn't been written out.
  // Use the limit of TimeStamp to trigger the saving and trimming
  
  // save before trim
  if(m_saveFlag) {
    sc = m_pSaveB4TrimAesSvc->store(m_regSeqLocation,
                                    m_pDybStorageSvc,
                                    m_pArchiveSvc,
                                    m_pTrimSvc,
                                    TimeStamp::GetEOT());
    if(sc.isFailure()) {
      debug()<<"Failed to write"<<endreq;
      return StatusCode::FAILURE;
    }
  }

  // trim base on it
  sc = m_pTrimSvc->trim(m_pArchiveSvc,TimeStamp::GetEOT());
  if(sc.isFailure()) {
    debug()<<"Failed to trim"<<endreq;
    return StatusCode::FAILURE;
  }

  // Now release these service
  if (0 != m_pTrimSvc) {
    m_pTrimSvc->release();
  }

  if (0 != m_pArchiveSvc) {
    m_pArchiveSvc->release();
  }    

  if(m_saveFlag) {
    if (0 != m_pSaveB4TrimAesSvc) {
      m_pSaveB4TrimAesSvc->release();
    }

    if (0 != m_pDybStorageSvc) {
      m_pDybStorageSvc->release();
    }
  }

  return StatusCode::SUCCESS;
}

Member Data Documentation

bool DybTrimIO::m_saveFlag [private]

Definition at line 37 of file DybTrimIO.h.

std::string DybTrimIO::m_nowLocation [private]

Definition at line 40 of file DybTrimIO.h.

std::string DybTrimIO::m_regSeqLocation [private]

Definition at line 43 of file DybTrimIO.h.

all the needed services //////////////// Save before trimming

Definition at line 48 of file DybTrimIO.h.

std::string DybTrimIO::m_pSaveB4TrimAesSvcName [private]

Definition at line 49 of file DybTrimIO.h.

dyb storage which do the real IO stuff

Definition at line 52 of file DybTrimIO.h.

std::string DybTrimIO::m_pDybStorageSvcName [private]

Definition at line 53 of file DybTrimIO.h.

IDataManagerSvc* DybTrimIO::m_pArchiveSvc [private]

AES.

Definition at line 56 of file DybTrimIO.h.

std::string DybTrimIO::m_pArchiveSvcName [private]

Definition at line 57 of file DybTrimIO.h.

triming

Definition at line 60 of file DybTrimIO.h.

std::string DybTrimIO::m_pTrimSvcName [private]

Definition at line 61 of file DybTrimIO.h.


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:09:44 for DybAlg by doxygen 1.7.4