![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /BdbCond/BdbCondConverter.cc
Go to the documentation of this file.00001 /***************************************************************************** 00002 * Project: BaBar detector at the SLAC PEP-II B-factory 00003 * Package: BdbCond 00004 * Class: BdbCondConverter 00005 * Authors: 00006 * DK, David Kirkby, Stanford University, kirkby@hep.stanford.edu 00007 * IG, Igor Gaponenko, Lawrence Berkeley National Lab., IAGaponenko@lbl.gov 00008 * History: 00009 * 05-Sep-1999 DK Created initial version 00010 * 11-Apr-2000 DK Fix bug that prevented first interval from being converted 00011 * 23-May-2000 IA Replace the specific type UInt_t by the portable one 00012 * "int". 00013 * 00014 * Copyright (C) 1999 Stanford University 00015 *****************************************************************************/ 00016 #include "BdbCond/BdbCondConverter.hh" 00017 #include "BdbCond/BdbCondAbsWriter.hh" 00018 #include "BdbUtil/Bdb.hh" 00019 #include "BdbCond/BdbConditions.hh" 00020 #include "BdbCond/BdbObsoleteDatabase.hh" 00021 00022 template <class T, class P> 00023 int BdbCondConverter<T,P>::run(BdbObsoleteDatabase& db, const char* container, 00024 BdbCondAbsWriter<T>& writer) 00025 { 00026 // Check that there is no pending transaction on the objy conditions db 00027 BdbConditions* theApp = BdbConditions::instance(); 00028 if(theApp->mode() != BdbcNoOpen) { 00029 cout << "converter cannot run until previous transaction is closed" 00030 << endl; 00031 return 0; 00032 } 00033 00034 // Start a new read transaction from the objy conditions database 00035 theApp->startRead(); 00036 00037 // Find the first valid objy interval for this container 00038 BdbHandle(BdbInterval) beginH; 00039 db.firstInterval(beginH, container); 00040 if(!beginH.isValid()) { 00041 cout << "no valid first interval for container " << container << endl; 00042 theApp->commit(); 00043 return 0; 00044 } 00045 00046 // iterate over all intervals 00047 BdbHandle(BdbInterval) intervalH; 00048 BdbHandle(P) dataH; 00049 intervalH = beginH; 00050 int count= 0; 00051 do { 00052 // get this interval's persistent data 00053 dataH= (BdbHandle(P)&)intervalH->getObject(); 00054 00055 // check if this is a valid handle 00056 if(!dataH.isValid()) { 00057 cout << "skipping interval without any data" << endl; 00058 continue; 00059 } 00060 count++; 00061 00062 // convert it to a transient object on the heap 00063 T *trans= dataH->transient(); 00064 if(!trans) { 00065 cout << "cannot generate transient data from entry " << count << endl; 00066 continue; 00067 } 00068 00069 if(!writer.store(*intervalH, *trans)) { 00070 cout << "unable to store converted persistent data for entry " 00071 << count << endl; 00072 } 00073 delete trans; 00074 } while((intervalH = intervalH->next()) != NULL); 00075 cout << "found " << count << " intervals for " << container << endl; 00076 00077 // commit this objy read transaction 00078 theApp->commit(); 00079 00080 // commit this root write transaction 00081 int entries= writer.commit(); 00082 cout << "converted " << entries << " " << container << " entries" << endl; 00083 00084 return 1; 00085 } 00086
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002