Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/BdbEventStore/BdbCollectionTInspector.cc

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: BdbCollectionTInspector.cc,v 1.4 2002/06/14 01:29:50 becla Exp $
00004 //
00005 // Description:
00006 //      Class BdbCollectionTInspector interface (.cc) file.
00007 //          This class returns the events store collection one by one.
00008 //          It is based on BdbInspector (from David R. Quarrie)
00009 //
00010 // Environment:
00011 //      Software developed for the BaBar Detector at the SLAC B-Factory
00012 //
00013 // Author List:
00014 //      Jean-Noel Albert            Original Author (source in BdbCollectionInspector)
00015 //      Jacek Becla             Modified to break dependency between Event Store
00016 //                              and BdbEvent
00017 //
00018 // Copyright Information:
00019 //      Copyright (C) 2002      Stanford Linear Accelerator Center
00020 //
00021 //------------------------------------------------------------------------------
00022 
00023 //------------------
00024 // Class's Header --
00025 //------------------
00026 #include "BdbEventStore/BdbCollectionTInspector.hh"
00027 
00028 //-----------------------
00029 // BaBar class headers --
00030 //-----------------------
00031 #include "BdbEventStore/BdbEventStore.hh"
00032 #include "BdbEventStore/BdbCollectionP.hh"
00033 #include "BdbEventStore/BdbEventStoreIterator.hh"
00034 #include "BdbTrees/BdbTreeNodeP.hh"
00035 #include "BdbTrees/BdbTreeNodeSimpleIterator.hh"
00036 
00037 extern "C" {
00038 #include <strings.h>
00039 }
00040 
00041 ;
00042 
00043 ///////////////////////////////////////////////////////////////////////////////
00044 
00045 // Constructor
00046 BdbCollectionTInspector::BdbCollectionTInspector (d_Boolean autoCommit)
00047 {
00048     _colls.resize(64);
00049     _nbcolls = 0;
00050     _nxtcoll = 0;
00051     _autoCommit = autoCommit;
00052 }
00053 
00054 // Destructor
00055 BdbCollectionTInspector::~BdbCollectionTInspector()
00056 {}
00057 
00058 // Internal routine - iterate over the tree of tree nodes
00059 BdbStatus BdbCollectionTInspector::scan(BdbTreeNode& node)
00060 {
00061     BdbHandleAny itemP;
00062     BdbTreeNodeSimpleIterator nditr(node);
00063 
00064     while (BdbcSuccess == nditr.next(itemP)) {
00065         if (BdbcSuccess == BdbEventStore::instance()->readAttempt(itemP)) {
00066             ooTypeNumber collPType = ooTypeN(BdbCollectionP);
00067             if (itemP->ooIsKindOf(collPType)) {
00068                 if (_nbcolls >= _colls.size()) {
00069                     _colls.resize(_nbcolls + 64);
00070                     // Commit and restart a transaction...
00071                     if (_autoCommit) {
00072                         BdbEventStore::instance()->commit();
00073                         BdbEventStore::instance()->startRead();
00074                     }
00075                 }
00076                 BdbHandle(BdbCollectionP) collP = 
00077                                 (BdbHandle(BdbCollectionP)&) itemP;
00078         _colls[_nbcolls++] = BdbEventStore::getCollection(collP);
00079             }
00080 
00081             if (BdbTreeNodeP::isTreeNode(itemP)) {
00082                 BdbTreeNode child;
00083                 child.setPersistent((BdbHandle(BdbTreeNodeP)&) itemP);
00084                 scan(child);
00085             }
00086         }
00087     }
00088     return BdbcSuccess;
00089 }
00090 
00091 // Scan the tree of tree nodes and convert it to a list
00092 BdbStatus BdbCollectionTInspector::scan ()
00093 {
00094     d_Boolean localTransaction;
00095     BdbTreeNode node;
00096     BdbEventStoreIterator evsitr;
00097 
00098     if ( BdbcNoOpen != BdbEventStore::instance()->mode() ) {
00099         if (!_autoCommit)
00100             return BdbcError;
00101         localTransaction = d_False;
00102     }
00103     else {
00104         localTransaction = d_True;
00105         BdbEventStore::instance()->startRead();
00106     }
00107 
00108     while (BdbcSuccess == evsitr.next(node))
00109         scan(node);     // Bypass the errors...
00110 
00111     if (localTransaction)
00112         BdbEventStore::instance()->commit();
00113     return BdbcSuccess;
00114 }
00115 
00116 BdbStatus BdbCollectionTInspector::scan (BdbDomain::AuthLevels level, const char* name)
00117 {
00118     d_Boolean localTransaction;
00119     BdbTreeNode node;
00120 
00121     if ( BdbcNoOpen != BdbEventStore::instance()->mode() ) {
00122         if (!_autoCommit)
00123             return BdbcError;
00124         localTransaction = d_False;
00125     }
00126     else {
00127         localTransaction = d_True;
00128         BdbEventStore::instance()->startRead();
00129     }
00130 
00131     if (BdbcSuccess != BdbEventStore::instance()->treeNode(node, level, name))
00132         return BdbcError;
00133 
00134     BdbStatus status =  scan(node);
00135 
00136     if (localTransaction)
00137         BdbEventStore::instance()->commit();
00138     return status;
00139 }
00140 
00141 BdbStatus BdbCollectionTInspector::scan (const char* treepath)
00142 {
00143     d_Boolean localTransaction;
00144     BdbTreeNode node;
00145 
00146     if ( BdbcNoOpen != BdbEventStore::instance()->mode() ) {
00147         if (!_autoCommit)
00148             return BdbcError;
00149         localTransaction = d_False;
00150     }
00151     else {
00152         localTransaction = d_True;
00153         BdbEventStore::instance()->startRead();
00154     }
00155 
00156     if (BdbcSuccess != node.moveTo(treepath))
00157         return BdbcError;
00158 
00159     BdbStatus status =  scan(node);
00160 
00161     if (localTransaction)
00162         BdbEventStore::instance()->commit();
00163     return status;
00164 }
00165 
00166 
00167 BdbStatus BdbCollectionTInspector::scan (BdbHandle(BdbDBObj)& db)
00168 {
00169     BdbItr(BdbCollectionP) tcollPitr;
00170 
00171     if (BdbcSuccess != tcollPitr.scan(db))
00172         return BdbcError;
00173 
00174     while (tcollPitr.next()) {
00175         if (_nbcolls >= _colls.size()) {
00176             _colls.resize(_nbcolls + 64);
00177             // Commit and restart a transaction...
00178             if (_autoCommit) {
00179                 BdbEventStore::instance()->commit();
00180                 BdbEventStore::instance()->startRead();
00181             }
00182         }
00183         if (0 != tcollPitr->name())
00184             _colls[_nbcolls++] = BdbEventStore::getCollection(tcollPitr);
00185     }
00186 /***
00187 printf("collPitr isDelete: %d\n", collPitr->isDeleted());
00188 printf("collPitr name: %s\n", (collPitr->name() == 0) ? "<no name>" : collPitr->name());
00189 printf("collPitr pathname: %s\n", (collPitr->name() == 0) ? "<no path>" : collPitr->pathName());
00190 ***/
00191     return BdbcSuccess;
00192 }
00193 
00194 BdbStatus BdbCollectionTInspector::scanDatabase (const char* dbname)
00195 {
00196     BdbHandle(BdbDBObj)db;
00197     if (BdbcSuccess != db.exist(BdbEventStore::instance()->fd(), dbname, BdbcRead))
00198         return BdbcError;
00199     return scan (db);
00200 }
00201 
00202 d_Boolean BdbCollectionTInspector::exist (const char* treepath)
00203 {
00204     BdbTreeNode node;
00205 
00206     return (BdbcSuccess == node.moveTo(treepath));
00207 }
00208 
00209 // Accessor
00210 
00211 BdbAbsCollectionT<BdbEventT>* BdbCollectionTInspector::next()
00212 {
00213     if (_nxtcoll < _nbcolls)
00214         return _colls[_nxtcoll++];
00215     return 0;
00216 }
00217 
00218 // Reset the iterator at the beginning of the list
00219 void BdbCollectionTInspector::reset ()
00220 {
00221     _nxtcoll = 0;
00222 }
00223 
00224 // Clear the iterator
00225 void BdbCollectionTInspector::clear ()
00226 {
00227     _colls.resize(64);
00228     _nbcolls = 0;
00229     _nxtcoll = 0;
00230 }
00231 

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002