00001 #ifndef CDBBDB_LOADLIST_HH 00002 #define CDBBDB_LOADLIST_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbBdbLoadList.hh,v 1.3 2002/09/23 22:39:08 gapon Exp $ 00006 00007 #include "BdbCond/BdbObject.hh" 00008 #include "BdbCond/BdbCondProxyBase.hh" 00009 00010 #include <string> 00011 00012 /// Multiple objects loader 00013 /** 00014 // Description: CdbBdbLoadList. is a utility class intended to be used to 00015 // simplify loading multiple objects in the conditions database. It pulls together 00016 // code for manipulating date-time strings in one place, avoiding code duplication 00017 // and hopefully simplifying user code. Unfortunately, the task of loading conditions 00018 // data is somewhat complicated, so this class is not trivial to use; please read the 00019 // following instructions carefully!! 00020 // 00021 // File format: 00022 // CdbBdbLoadList will load a set of objects into a specified container in the 00023 // conditions database. The list of 'objects' is passed to the constructor of this class 00024 // in the form of a filename, where each line in the file specifies an 'object'. 00025 // The filename must be fully specified: we recommend use AbsParmFilename, and passing 00026 // the value of the 'pathname()' function. 00027 // The format of the lines in this file is fixed, according to the following perscription: 00028 // 00029 // 'RWDate string' ['RWTime string'] ['object specification'] 00030 // 00031 // Valid RWDate string formats are described in the Tools.h++ handbook, and include 00032 // the BaBar standard '01Jan1901' (ddMmmyyyy). Valid RWTime strings are similairly 00033 // described in the manual and include the BaBar standard '00:00:01' (hh:mm:ss). 00034 // Valid 'object specification' format is defined by user code, as described below. 00035 // The object list file may have as many lines of the format above as required to 00036 // define the desired timeline in the conditions database. The date/times must be 00037 // in ascending order. The time specified on the line is interpreted as the objects 00038 // start-validity time, and the time specified on the _following_ line is interpreted 00039 // as the end-validity time of this object. If there is no new object with start-validity 00040 // of this 2nd time (IE if you wish to insert 'gaps' into the conditions timeline), simply 00041 // leave the 'object specification' string blank. The last line in every file must _always_ 00042 // have a null object specification, to correctly terminate the validity timeline. 00043 // For instance, to allow the last object specified to have 00044 // indefinite validity, the last line in the file should be simply "+Infinity". 'Dates' 00045 // of +Infinity do not need to have a corresponding time, and no object is allowed to have 00046 // start-validity of +Infinity. 00047 // 00048 // Comments can be inserted anywhere in the object specfication file by starting the line with 00049 // the "#" character. mid-line comments are not supported. 00050 // 00051 // The times specified in the file are by default assumed to be in UTC. If instead the 00052 // times correspond to the local time zone (the one in which the program is being run), 00053 // the following line will change the default: 00054 // 00055 // Zone Local 00056 // 00057 // Please note that the local time zone should only be used if the objects correspond to 00058 // actual measurments made at the specified time; it should _never_ be used to describe 00059 // simulation parameters for instance. 00060 // 00061 // Object specification 00062 // CdbBdbLoadList does not understand how to create an instance of your object. 00063 // Instead, it defers to a function provided by the user on construction to convert 00064 // the 'object specification' string to an object. One simple way of doing this is 00065 // to put the data members for each object in their own file, and have the 'object 00066 // specification' represent the name of that file. Other strategies may be implemented 00067 // as appropriate. CdbBdbLoadList does not need to know the type (class) of the object 00068 // being loaded, as it uses persistent polymorphism. 00069 // On construction, the user must provide a function of the following prototype: 00070 // void createObject(const RWCString& object_specification, 00071 // BdbRefAny& clusterhint, 00072 // BdbRef(BdbObject)& objecthandle); 00073 // This function should interpret the object specification as required, 00074 // and construct a persistent object of the correct type, clustered at the specified, 00075 // and set the supplied object handle to point to it. 00076 // 00077 // Environment: 00078 // Software developed for the BaBar Detector at the SLAC B-Factory. 00079 // 00080 // Author List: 00081 // Dave Brown 04-24-2000 ( original author ) 00082 // Igor Gaponenko 05-13-2002 ( adapted for the new Condition/DB ) 00083 // 00084 // Copyright Information: 00085 // Copyright (C) 2000, 2002 Lawrence Berkeley National LAboratory 00086 // 00087 //------------------------------------------------------------------------ 00088 */ 00089 00090 // prototype for the function required on construction (type pointer-to-function; can be 00091 // a member function of a class, a static function, or a global function). 00092 00093 typedef bool (*CdbBdbCreateCondObject)( const char*, 00094 BdbRefAny&, 00095 BdbRef(BdbObject)& ); 00096 00097 00098 class CdbBdbLoadList : public BdbCondProxyBase { 00099 00100 private: 00101 00102 /// Default constructor (NOT IMPLEMENTED) 00103 00104 CdbBdbLoadList( ); 00105 00106 /// Assignment operator (NOT IMPLEMENTED) 00107 00108 CdbBdbLoadList& operator=( const CdbBdbLoadList& theList ); 00109 00110 public: 00111 00112 // construct with subsystem name, container name, and creation function 00113 00114 CdbBdbLoadList( const char* sysname, 00115 const char* containername, 00116 CdbBdbCreateCondObject function ); 00117 00118 // this class probably doesn't need to be inherited from, but... 00119 00120 virtual ~CdbBdbLoadList(); 00121 00122 // the real function; pass in the filename, it'll create objects and store them in the 00123 // conditions DB for you. Return status is the for the last stored object; if any object 00124 // fails to be created or stored, the transaction will _not_ be committed, and it 00125 // will be up to the caller to cleanup. If every object is successfully created and stored, 00126 // the transaction will be committed and the return value will be BdbCSuccess 00127 00128 virtual BdbStatus storeObjects( const char* filename ); 00129 00130 private: 00131 00132 // obvious data members 00133 00134 std::string _sysname; 00135 std::string _contname; 00136 00137 CdbBdbCreateCondObject _createfunction; 00138 }; 00139 00140 #endif // CDBBDB_LOADLIST_HH 00141
1.3-rc3