/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 | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
DybShuffle Class Reference

#include <DybShuffle.h>

Inheritance diagram for DybShuffle:
Inheritance graph
[legend]
Collaboration diagram for DybShuffle:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DybShuffle (const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize ()
StatusCode execute ()
StatusCode finalize ()
DayaBay::RandomHeaderGetCurrentHeaderObject () const
 Access last HeaderType HeaderObject made.
virtual StatusCode sysInitialize ()
 Will call initialize().
virtual StatusCode sysExecute ()
 Will call preExecute() execute() and postExecute().
virtual StatusCode preExecute ()
 be called before execute().
virtual StatusCode postExecute ()
 be called after execute().
virtual StatusCode sysFinalize ()
 Will call finalize().
IDataProviderSvc * arcSvc () const
 Utility methods for subclasses:
void putTES (DataObject *obj, std::string location) const
 Put data in the TES.
template<class TYPE >
TYPE * getTES (std::string location) const
 Access data from the TES.
template<class TYPE >
TYPE * getAES (std::string location, int index) const
 Access data from the Archive Event service at the given index.
std::vector< DataObject * > getAEScollection (std::string location) const
 Return the list of archived data objects at the given location.
int getExecNum ()
 Access current execution ("event") number.
std::string Location () const
 Access the TES location.

Protected Member Functions

DayaBay::RandomHeaderMakeHeaderObject ()
 Sub classes should call this towards the beginning of execute(), and certainly before any random numbers are consumed.
void InitializeHeader (DayaBay::HeaderObject *header)
 Initialize new header object. Set exec number, job id, etc.
template<class TYPE >
TYPE * MakeHeader ()
template<class TYPE >
TYPE * MakeHeader (std::vector< const DayaBay::IHeader * > &inputHeaders)
template<class TYPE >
TYPE * MakeHeader (const DayaBay::IHeader *referenceHeader)
void AppendInputHeader (const DayaBay::HeaderObject *header) const
 Explicitly add an input header that was retrieved directly instead of through this classes get* methods.

Protected Attributes

DayaBay::HeaderObjectm_headerObject
bool m_pullMode
 runing mode, push or pull
std::string m_location
 Property: Location.

Private Member Functions

std::vector< long > seed ()

Private Attributes

IRndmGenSvc * m_rndSvc
IRndmEngine * m_engine
std::string m_engineName
int m_hostid
 Property: HostID - Host ID (as output by, eg, hostid command, if given in hex preface with 0x)
int m_run
 Property: Run - run number.
int m_countOffset
 Property: Count - execution count top level algorithm chain.
int m_burnCount
 Property: burnCount - number of random numbers to burn with a new seed.
bool m_dohash
 Property: Hash - if true, hash the seed.
std::vector< long > m_seedvec
Rndm::Numbers m_uni

Detailed Description

Definition at line 12 of file DybShuffle.h.


Constructor & Destructor Documentation

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

Definition at line 18 of file DybShuffle.cc.

    : DybAlgorithm<DayaBay::RandomHeader>(name, pSvcLocator)
    , m_hostid(0)
    , m_run(1)
    , m_countOffset(0)
    , m_burnCount(100)
    , m_dohash(true)
{
  // Part 1: Declare the properties
  declareProperty("HostID", m_hostid, "The systems Host 'ID'entification number");
  declareProperty("Run",m_run,"The run number");
  declareProperty("ExecCountOffset",m_countOffset,"Number to add to the execution count");
  declareProperty("BurnCount",m_burnCount,"Number of random numbers to burn with a new seed");
  declareProperty("SeedVec", m_seedvec, "Random seed vector manually");
  declareProperty("Hash", m_dohash, "Hash the seed");
}

Member Function Documentation

StatusCode DybShuffle::initialize ( )

Definition at line 37 of file DybShuffle.cc.

                                 {
  
  // Part 1: Print where you are
  verbose() << " DybShuffle initialize()" << endreq;

  //Retrieve Engine and write to Header
  m_rndSvc = randSvc();
  m_engine = m_rndSvc->engine();

  IProperty* prop=0;
  StatusCode sc = m_rndSvc->queryInterface(IProperty::interfaceID(),(void**)&prop);
  if (sc.isFailure()) return sc;

  m_engineName = prop->getProperty("Engine").toString();
  
  if (m_uni.initialize(m_rndSvc, Rndm::Flat(0,1)).isFailure()) {
    fatal() << "Failed to initialize uniform random numbers" << endreq;
    return StatusCode::FAILURE;
  }

  this->seed();

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

Definition at line 64 of file DybShuffle.cc.

                               {
  
  verbose() << "DybShuffle execute()" << endreq;

  //make output header object
  DayaBay::RandomHeader* RndmHead = MakeHeaderObject();

  // wangzhe
  // Here the time stamps of earliest and latest are set to zero explicitly
  RndmHead->setEarliest(TimeStamp::GetBOT());
  RndmHead->setLatest(TimeStamp::GetBOT());
  // wz

  RndmHead->setHEPEngine(m_engineName);
  
  // Don't re-set the seed on first execution as this was done in initialize()
  if (this->getExecNum() > 1) {
    std::vector<long> NewSeeds = this->seed();
    RndmHead->setRndmSeeds(NewSeeds);
  }

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

Definition at line 169 of file DybShuffle.cc.

                                {
  
  // Part 1: Print where you are
  verbose() << "DybShuffle finalize()" << endreq;
  
  return StatusCode::SUCCESS;
}
std::vector< long > DybShuffle::seed ( ) [private]

Definition at line 88 of file DybShuffle.cc.

{

  std::vector<long> NewSeeds;
  std::vector<long> CurrSeeds;
  
  if(m_seedvec.size())
  {
    NewSeeds=m_seedvec;
  }

  else
  {

    //Determine and set seed(s).... some generators use more than one seed.
    if (m_hostid == 0)
    {
        m_hostid = (long) gethostid();
    }

    std::bitset<32> a ((long) 0);
    std::bitset<32> site ((long) 0);
    std::bitset<32> run ((long) 0);
    std::bitset<32> evt ((long) 0);
    std::bitset<32> seed ((long) 0);

    site = (long)m_hostid;
    run = m_run;

    //iterations on MakeHeader().... or, how many times this execute
    // method has been called.  Plus offset in order to reproduce
    // isolated execution cycle.
    evt = m_countOffset + this->getExecNum();

    for ( int i = 32-1-1; i >= 0 ; i-- )
    {
      if ( run.test(i) ) a.set(31-1-i) ;
    }

    seed = (a|evt)^site;
    // set highest bit to zero to avoid negative seed
    if ( seed.test(31) ) seed.reset(31);
    int MySeed = seed.to_ulong();

    if (m_dohash) {
      boost::hash<int> hasher;
      MySeed = hasher(MySeed);
    }

    NewSeeds.push_back(MySeed);

    debug () << "Run " << m_run 
            << ", exec# = " << evt.to_ulong()
            << ", host = " << (void*)site.to_ulong() 
            << ", seeds:";
    std::vector<long>::iterator it, done = NewSeeds.end();
    for (it=NewSeeds.begin(); it != done; ++it) {
      debug () << " " << *it;
    }
    debug () << endreq;

  }


  m_engine->setSeeds(NewSeeds);
  m_engine->seeds(CurrSeeds);
  gRandom->SetSeed(NewSeeds[0]);
  
  // now that the new seeds are set, burn some random numbers (to avoid correlations)
  int irndm;
  double b;
  for(irndm=0;irndm<m_burnCount;irndm++)
  {
    b=m_uni();
  }

  return NewSeeds;
}
DayaBay::RandomHeader * DybAlgorithm< DayaBay::RandomHeader >::GetCurrentHeaderObject ( ) const [inherited]

Access last HeaderType HeaderObject made.

DayaBay::RandomHeader * DybAlgorithm< DayaBay::RandomHeader >::MakeHeaderObject ( ) [protected, inherited]

Sub classes should call this towards the beginning of execute(), and certainly before any random numbers are consumed.

It makes and returns a new object of HeaderType, registers it in the TES and sets all the HeaderObject base class values it can (everything except for the TimeStamp and the input HeaderObjects which the subclass must take care of).

StatusCode DybBaseAlg::sysInitialize ( ) [virtual, inherited]

Will call initialize().

Definition at line 29 of file DybBaseAlg.cc.

{
    // Call parent
    StatusCode sc = this->GaudiAlgorithm::initialize();
    if (sc.isFailure()) return sc;

    // This insinuates on GaudiAlgorithm's operation in order to do
    // any "dybish" initialization:
    // do_dybstuff_init();

    // Trigger calling subclass, back to your regularly scheduled operations
    sc = this->Algorithm::sysInitialize();    
    if (sc.isFailure()) return sc;

    return StatusCode::SUCCESS;
}
StatusCode DybBaseAlg::sysExecute ( ) [virtual, inherited]

Will call preExecute() execute() and postExecute().

Definition at line 46 of file DybBaseAlg.cc.

{
  if(!m_pullMode) {
    if(preExecute().isFailure()) return StatusCode::FAILURE;
  }

  // Trigger subclass's execute();                                                                             
  if (this->Algorithm::sysExecute().isFailure()) return StatusCode::FAILURE;

  if(!m_pullMode) {
    if(postExecute().isFailure()) return StatusCode::FAILURE;
  }

  return StatusCode::SUCCESS;
}
StatusCode DybBaseAlg::preExecute ( ) [virtual, inherited]

be called before execute().

Definition at line 62 of file DybBaseAlg.cc.

{
    if (!m_saveRandomState) return StatusCode::SUCCESS;

    // Get random state
    IRndmEngine *engine = 0;
    if (randSvc()->queryInterface(IID_IRndmEngine,(void**)&engine).isFailure()) {
        warning() << "Could not get IRndmEngine interace from random service, "
            "no state saved!" << endreq;
    }
    else {
        engine->rndmState(m_state);
        debug () << "Storing random state: [";
        for (size_t ind=0; ind<m_state.size(); ++ind) {
            debug () << " " << m_state[ind];
        }
        debug () << " ]" << endreq;
    }
    
    return StatusCode::SUCCESS;
}
StatusCode DybBaseAlg::postExecute ( ) [virtual, inherited]

be called after execute().

Definition at line 84 of file DybBaseAlg.cc.

{
    // Set some base HeaderObject values
    if (m_headerObject) {
        m_headerObject->setRandomState(m_state);
        const std::vector<const DayaBay::IHeader*> iheaders(m_inputHeaders.begin(),m_inputHeaders.end());
        m_headerObject->setInputHeaders(iheaders);


        // Add to TES.  This must be done after algorithm has chance to
        // fill earliest/latest with non-default values as this put()
        // triggers an insert() into the RegistrationSequence.
        
        if (!m_pullMode) {
            put(m_headerObject,m_location);
        }
    }

    // Prepare alg for next execution cycle
    debug() <<"Clearing " << m_inputHeaders.size() << " cached input headers" << endreq;
    m_inputHeaders.clear();
    ++m_execNum;
    m_headerObject = 0;               // owned by TES

    return StatusCode::SUCCESS;
}
StatusCode DybBaseAlg::sysFinalize ( ) [virtual, inherited]

Will call finalize().

Definition at line 111 of file DybBaseAlg.cc.

{
    if (this->finalize().isFailure()) {
        return StatusCode::FAILURE;
    }
    return this->GaudiAlgorithm::finalize();
}
IDataProviderSvc * DybBaseAlg::arcSvc ( ) const [inherited]

Utility methods for subclasses:

Access the archive Event Service

Definition at line 148 of file DybBaseAlg.cc.

{
    return 0;                   // fixme
}
void DybBaseAlg::putTES ( DataObject *  obj,
std::string  location 
) const [inherited]

Put data in the TES.

It is like a normal put<>() but will build up the full path leading to the location with DataObjects.

Definition at line 153 of file DybBaseAlg.cc.

{
    // Look for pre-existing header object or make new one, creating
    // the supporting path as we go.
    std::string::size_type ind = location.find("/"); // skip initial "/".
    while (true) {
        ind = location.find("/",ind+1);
        if (ind == std::string::npos) {
            debug() << "Putting final: " << location << endreq;
            put(obj,location);
            break;
        }
        else {
            // make the supporting path from simple DataObjects
            debug() << "Making intermediate: " << location.substr(0,ind)
                   << endreq;
            getOrCreate<DataObject,DataObject>(location.substr(0,ind));
        }
    }
}
template<class TYPE >
TYPE * DybBaseAlg::getTES ( std::string  location) const [inherited]

Access data from the TES.

As a side effect, if this data is a HeaderObject it will be recorded into the current header objects list of input header objects.

Definition at line 142 of file DybBaseAlg.h.

{
    TYPE* obj = get<TYPE>(location);
    // If object happens to be a HeaderObject, save it in the intputHeaders
    DayaBay::HeaderObject* header = dynamic_cast<DayaBay::HeaderObject*>(obj);
    if (header) {
        if (std::find(m_inputHeaders.begin(),m_inputHeaders.end(),header) == m_inputHeaders.end()) {
            this->AppendInputHeader(header);
            debug() << "Saved " << m_inputHeaders.size() 
                   << " input headers from TES, latest: " 
                   << header->name() 
                   << endreq;
        }
    }
    return obj;
}
template<class TYPE >
TYPE * DybBaseAlg::getAES ( std::string  location,
int  index 
) const [inherited]

Access data from the Archive Event service at the given index.

Index==0 is the most recent. As a side effect, if this data is a HeaderObject it will be recorded into the current header objects list of input header objects.

Definition at line 160 of file DybBaseAlg.h.

{
    if (index<0) return 0;

    std::vector<DataObject*> vec = this->getAEScollection(location);
    if (!vec.size() || index >= vec.size()) return 0;
    DataObject* dobj = vec[index];
    TYPE* obj = dynamic_cast<TYPE*>(dobj);
    if (!obj) return 0;

    DayaBay::HeaderObject* header = dynamic_cast<DayaBay::HeaderObject*>(obj);
    if (header) {
        if (std::find(m_inputHeaders.begin(),m_inputHeaders.end(),header) == m_inputHeaders.end()) {
            this->AppendInputHeader(header);
            debug() << "Saved " << m_inputHeaders.size() 
                   << " input headers from TES, latest: " 
                   << header->name() 
                   << endreq;
        }
    }

    return obj;
}
std::vector< DataObject * > DybBaseAlg::getAEScollection ( std::string  location) const [inherited]

Return the list of archived data objects at the given location.

Note: this does NOT automatically add anything into the list of input headers for this algorithm's output. If your subclass uses anything from this list you MUST add it to the input headers manually or people will not know what when in to your output.

Definition at line 175 of file DybBaseAlg.cc.

{
    DybArchiveList* lst = get<DybArchiveList>(arcSvc(),location);
    if (!lst) return std::vector<DataObject*>();
    return std::vector<DataObject*>(lst->begin(),lst->end());
}
int DybBaseAlg::getExecNum ( ) [inline, inherited]

Access current execution ("event") number.

Definition at line 76 of file DybBaseAlg.h.

{ return m_execNum; }
std::string DybBaseAlg::Location ( ) const [inline, inherited]

Access the TES location.

Definition at line 79 of file DybBaseAlg.h.

{ return m_location; }
void DybBaseAlg::InitializeHeader ( DayaBay::HeaderObject header) [protected, inherited]

Initialize new header object. Set exec number, job id, etc.

Definition at line 120 of file DybBaseAlg.cc.

{
  // Set some standard parameters for this header

  // Set execution number
  header->setExecNumber(m_execNum);    
  
  // Document the ID of the job which made this header
  if(!m_jobInfoSvc){
    // Get the job information service
    m_jobInfoSvc = svc<IJobInfoSvc>("JobInfoSvc",true);
  }
  if(m_jobInfoSvc){
    header->setJobId(m_jobInfoSvc->currentJobInfo()->jobId());
  }else{
    warning() << "MakeHeaderObject, failed to get current job ID" << endreq;
  }
  // Set the header time range
  header->setEarliest(TimeStamp::GetBOT());
  header->setLatest(TimeStamp::GetBOT());
}
template<class TYPE >
TYPE * DybBaseAlg::MakeHeader ( ) [protected, inherited]

Definition at line 185 of file DybBaseAlg.h.

{
    TYPE* obj = new TYPE();
    InitializeHeader(obj);
    return obj;
}
template<class TYPE >
TYPE * DybBaseAlg::MakeHeader ( std::vector< const DayaBay::IHeader * > &  inputHeaders) [protected, inherited]

Definition at line 193 of file DybBaseAlg.h.

{
    TYPE* obj = MakeHeader<TYPE>();
    obj->setInputHeaders(inputHeaders);
    size_t size = inputHeaders.size();
    if (size == 0) {
        warning() << "input header has zero size" << endreq;
        return obj; 
    }
    const DayaBay::HeaderObject* firstHeader = dynamic_cast<const DayaBay::HeaderObject*>(inputHeaders[0]);
    obj->setContext(firstHeader->context());
    obj->setEarliest(firstHeader->earliest());
    if (size > 1) {
        const DayaBay::HeaderObject* lastHeader = dynamic_cast<const DayaBay::HeaderObject*>(inputHeaders[size-1]);
        obj->setLatest(lastHeader->latest());
    }
    else {
        obj->setLatest(firstHeader->latest());
    }
    
    // make sure the time span covers inputHeaders' range
    for (size_t i=1; i<inputHeaders.size(); i++) {
        const DayaBay::HeaderObject* inputHdr = dynamic_cast<const DayaBay::HeaderObject*>(inputHeaders[i]);
        if (inputHdr->earliest() < obj->earliest()) {
            obj->setEarliest(inputHdr->earliest());
        }
        if (inputHdr->latest() > obj->latest()) {
            obj->setLatest(inputHdr->latest());
        }
    }
    
    return obj;
}
template<class TYPE >
TYPE * DybBaseAlg::MakeHeader ( const DayaBay::IHeader referenceHeader) [protected, inherited]

Definition at line 228 of file DybBaseAlg.h.

{
    std::vector<const DayaBay::IHeader*> inputHeaders = std::vector<const DayaBay::IHeader*>();
    inputHeaders.push_back(referenceHeader);
    TYPE* obj = MakeHeader<TYPE>(inputHeaders);
    return obj;
}
void DybBaseAlg::AppendInputHeader ( const DayaBay::HeaderObject header) const [protected, inherited]

Explicitly add an input header that was retrieved directly instead of through this classes get* methods.

Definition at line 142 of file DybBaseAlg.cc.

{
    m_inputHeaders.push_back(header);
}

Member Data Documentation

IRndmGenSvc* DybShuffle::m_rndSvc [private]

Definition at line 24 of file DybShuffle.h.

IRndmEngine* DybShuffle::m_engine [private]

Definition at line 25 of file DybShuffle.h.

std::string DybShuffle::m_engineName [private]

Definition at line 26 of file DybShuffle.h.

int DybShuffle::m_hostid [private]

Property: HostID - Host ID (as output by, eg, hostid command, if given in hex preface with 0x)

Definition at line 30 of file DybShuffle.h.

int DybShuffle::m_run [private]

Property: Run - run number.

Definition at line 33 of file DybShuffle.h.

Property: Count - execution count top level algorithm chain.

Definition at line 36 of file DybShuffle.h.

int DybShuffle::m_burnCount [private]

Property: burnCount - number of random numbers to burn with a new seed.

Definition at line 39 of file DybShuffle.h.

bool DybShuffle::m_dohash [private]

Property: Hash - if true, hash the seed.

Definition at line 42 of file DybShuffle.h.

std::vector<long> DybShuffle::m_seedvec [private]

Definition at line 44 of file DybShuffle.h.

Rndm::Numbers DybShuffle::m_uni [private]

Definition at line 46 of file DybShuffle.h.

Definition at line 108 of file DybBaseAlg.h.

bool DybBaseAlg::m_pullMode [protected, inherited]

runing mode, push or pull

Definition at line 111 of file DybBaseAlg.h.

std::string DybBaseAlg::m_location [protected, inherited]

Property: Location.

Set non-standard TES location for the object this algorithm produces. Default is result of class method HeaderType::defaultLocation().

Definition at line 137 of file DybBaseAlg.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