00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "BaBar/BaBar.hh"
00013
00014 #include "CdbBase/CdbView.hh"
00015 #include "CdbBase/CdbFolder.hh"
00016 #include "CdbBase/CdbCondition.hh"
00017 #include "CdbBase/CdbObject.hh"
00018 #include "CdbBase/CdbTimeUtils.hh"
00019 #include "CdbBase/CdbEnvironment.hh"
00020 #include "CdbBase/CdbTransaction.hh"
00021
00022 #include "CdbTable/CdbNTupleBase.hh"
00023
00024 #include "CdbBdb/CdbBdbObjectConvertor.hh"
00025
00026 #include "BdbCond/BdbObject.hh"
00027
00028 #include "CdbBdbShared/CdbBdbShared.hh"
00029
00030 #include "CdbBdbTable/CdbBdbNTupleSimpleImplP_ooFloat64.hh"
00031
00032 #include <iostream>
00033 #include <string>
00034 using std::cout;
00035 using std::cerr;
00036 using std::endl;
00037 #include <vector>
00038 #include <map>
00039
00040 #include <stdio.h>
00041
00042 namespace {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 bool find_conditions( std::vector<std::string>& theListOfConditions,
00060 std::map<std::string,CdbFolderPtr>& theMapOfFolders,
00061 const std::string& theFolderName );
00062
00063 bool
00064 translate_int( int& theValue,
00065 const char* theBuf )
00066 {
00067 assert( 0 != theBuf );
00068
00069 int v;
00070
00071 if( 1 == sscanf( theBuf, "%d", &v )) {
00072 theValue = v;
00073 return true;
00074 }
00075 return false;
00076 }
00077 };
00078
00079 int
00080 main( int argc, char* argv[] )
00081 {
00082 CdbBdbShared::forceLoad( );
00083
00084
00085
00086 int numArgs = argc - 1;
00087 int nextArg = 1;
00088
00089
00090
00091 CdbTransaction transaction;
00092
00093
00094
00095 int debugMode = 0;
00096
00097 if( numArgs >= 2 ) {
00098 if( 0 == strcmp( argv[nextArg], "-debug" )) {
00099 if( translate_int( debugMode, argv[nextArg+1] )) {
00100 nextArg = nextArg + 2;
00101 numArgs = numArgs - 2;
00102 } else {
00103 cout << "Error:\n"
00104 << " Failed to translate '-debug <mode>' in a list of\n"
00105 << " command-line arguments." << endl;
00106 return 1;
00107 }
00108 }
00109 }
00110 CdbEnvironment::setDebugMode( debugMode );
00111 CdbStatus result = CdbStatus::Error;
00112
00113
00114
00115
00116 std::vector<std::string> listOfConditions;
00117 std::map<std::string,CdbFolderPtr> mapOfFolders;
00118
00119 const std::string baseFolderName = "/physicstools/pid/";
00120
00121 if( !find_conditions( listOfConditions,
00122 mapOfFolders,
00123 baseFolderName )) return 1;
00124
00125 cout << "Found the following conditions:\n"
00126 << "\n";
00127
00128 const unsigned int nConditions = listOfConditions.size( );
00129 for( unsigned int iCondition = 0; iCondition < nConditions; ++iCondition ) {
00130
00131 }
00132 cout << "\n"
00133 << "Total of " << nConditions << " found.\n"
00134 << endl;
00135
00136 CdbViewPtr viewPtr;
00137 if( CdbStatus::Success != ( result = CdbView::instance( viewPtr ))) {
00138 cerr << "Failed to find the default view because of: " << result << "." << endl;
00139 return 1;
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 const BdbTime now = BdbTime( 2450894400, 0000000000 );
00153
00154 unsigned int totalBytes = 0;
00155
00156 for( unsigned int iCondition = 0; iCondition < nConditions; ++iCondition ) {
00157
00158 CdbPathName fullPath( listOfConditions[iCondition] );
00159 CdbPathName folderPath( fullPath.beforeLast( ));
00160 CdbPathName conditionPath( fullPath.last( ));
00161
00162 const std::string folderName = folderPath.toString( ) + CdbPathName::separator( );
00163 const std::string conditionName = conditionPath.toString( ) ;
00164
00165 CdbFolderPtr folderPtr = mapOfFolders[folderName];
00166 if( folderPtr.isNull( )) {
00167 cout << "no folder found in the map for: '" << folderName << "'" << endl;
00168 continue;
00169 }
00170
00171 CdbConditionPtr conditionPtr;
00172 if( CdbStatus::Success != ( result = folderPtr->findCondition( conditionPtr,
00173 conditionName.c_str( )))) {
00174 cerr << "Failed to find the condition '" << folderName + conditionName << "' because of: " << result << "." << endl;
00175 return 1;
00176 }
00177
00178
00179
00180
00181
00182 cout << "'" << conditionPtr->name( ) << "':" << endl;
00183
00184 CdbObjectPtr objectPtr;
00185 if( CdbStatus::Success != ( result = conditionPtr->findObject( objectPtr,
00186 now ))) {
00187 cerr << "Failed to find an object from the condition '" << conditionName << "'\n"
00188 << "at the validity point: " << CdbTimeUtils::time2string2( now ) << "\n"
00189 << "because of: " << result << "." << endl;
00190 return 1;
00191 }
00192
00193 BdbHandle(BdbObject) persistentObjectH;
00194 if( CdbStatus::Success != ( result = CdbBdbObjectConvertor::narrow( persistentObjectH,
00195 objectPtr ))) {
00196 cerr << "Failed to narrow the found API object into the corresponding persistent one" << endl
00197 << "because of the following error: " << result << endl;
00198 return 1;
00199 }
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 }
00217 return 0;
00218 }
00219
00220 namespace {
00221
00222 bool
00223 find_conditions( std::vector<std::string>& theListOfConditions,
00224 std::map<std::string,CdbFolderPtr>& theMapOfFolders,
00225 const std::string& theFolderName )
00226 {
00227 CdbStatus result = CdbStatus::Error;
00228
00229
00230
00231 CdbFolderPtr folderPtr;
00232 if( CdbStatus::Success != ( result = CdbFolder::instance( folderPtr,
00233 theFolderName.c_str( )))) {
00234 cerr << "Failed to find the folder '" << theFolderName << "'\n"
00235 << "because of: " << result << "." << endl;
00236 return false;
00237 }
00238 theMapOfFolders[theFolderName] = folderPtr;
00239
00240
00241
00242
00243 CdbConditionItr conditionItr;
00244 if( CdbStatus::Success != folderPtr->conditionIterator( conditionItr )) {
00245 cerr << "Failed to set up an iterator of conditions within the folder '" << theFolderName << "'\n"
00246 << "because of: " << result << "." << endl;
00247 return false;
00248 }
00249 while( conditionItr.next( )) {
00250 const std::string conditionName = conditionItr.value( );
00251 theListOfConditions.push_back( theFolderName + conditionName );
00252 }
00253
00254
00255
00256 CdbFolderItr folderItr;
00257 if( CdbStatus::Success != folderPtr->folderIterator( folderItr )) {
00258 cerr << "Failed to set up an iterator of sub-folders within the folder '" << theFolderName << "'\n"
00259 << "because of: " << result << "." << endl;
00260 return false;
00261 }
00262 while( folderItr.next( ))
00263 if( !find_conditions( theListOfConditions,
00264 theMapOfFolders,
00265 theFolderName + folderItr.value( ) + std::string( "/" )));
00266
00267 return true;
00268 }
00269 }
00270
00271
00272
00273