Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

RecRecordImp.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // RecRecordImp
00004 //
00005 // RecRecordImp is the Base Class for MINOS records
00006 //
00007 // Author:  S. Kasahara   9/02
00008 //
00010 
00011 #include "Record/RecRecordImp.h"
00012 
00013 #ifdef MACOSX
00014  using namespace std;
00015 #endif
00016 
00017 ClassImpT(RecRecordImp,T)
00018 
00019 // Definition of methods (alphabetical order)
00020 // ***************************************************
00021 
00022 template<class T>
00023 const VldContext* RecRecordImp<T>::GetVldContext() const {
00024   //
00025   //  Purpose:  Return a const pointer to the VldContext in the header.
00026   //
00027   //  Arguments: none.
00028   //
00029   //  Return:  ptr to VldContext or null if none.  
00030   //
00031   //  Contact:   S. Kasahara
00032   // 
00033 
00034   const RecHeader* hdr = dynamic_cast<const RecHeader*>(&GetHeader());
00035   if ( hdr) 
00036     return &(hdr->GetVldContext());
00037   else
00038     return 0;
00039 
00040 }
00041 
00042 template<class T>
00043 void RecRecordImp<T>::HasBeenModified() {
00044   //
00045   //  Purpose:  Handle generic record tasks appropriate for when record
00046   //            has been newly modified.
00047   //
00048   //  Arguments: none.
00049   //
00050   //  Return:  none.
00051   //
00052   //  Contact:   S. Kasahara
00053   // 
00054   //  Notes:  The default behavior provided by this method is to clear
00055   //          the Registry value associated with the key "outstream" in
00056   //          the Registry fTempTags data member.  This indicates to
00057   //          any output module(s) in the user's job path(s) that the modified
00058   //          record should be re-persisted.
00059   // 
00060 
00061   fTempTags.RemoveKey("outstream");
00062   return;
00063 
00064 }
00065 
00066 template<class T>
00067 void RecRecordImp<T>::PersistedToOutputStream(const char* stream,
00068                       const char* file, const char* tree, int index) {
00069   //
00070   //  Purpose:  Mark the record as having been stored in the named stream,file,
00071   //            tree, tree index location.
00072   //
00073   //  Arguments: stream name, file name, tree name, tree index to which record 
00074   //             was stored.  
00075   //
00076   //  Return:  none.
00077   //
00078   //  Contact:   S. Kasahara
00079   // 
00080   //  Notes:  The output stream,file,tree,treeindex will be stored in
00081   //          Registry fTempTags in the following manner:
00082   //          key         type/value
00083   //          ===         ==========
00084   //          "outstream" Registry/see below:
00085   //                      key     type/value
00086   //                      ===     ==========
00087   //                      "nout"  int/# times this record has been persisted
00088   //                       "0"    Registry/see below:
00089   //                       "1"    Registry/   "
00090   //                       ...    Registry/   "
00091   //                     "nout-1" Registry/   "
00092   //                              key      type/value
00093   //                              ===      ==========
00094   //                              "stream" const char*/output stream name
00095   //                              "file"   const char*/output file name
00096   //                              "tree"   const char*/output tree name
00097   //                              "index"  int        /output tree index
00098   //          
00099 
00100   Registry outStreamRegistry;
00101   int nout = 0;
00102   if ( fTempTags.Get("outstream",outStreamRegistry) ) {
00103     outStreamRegistry.Get("nout",nout); 
00104   }
00105   outStreamRegistry.UnLockValues();
00106 
00107   // New output stream registry
00108   Registry newOutStream;
00109   newOutStream.Set("stream",stream);
00110   newOutStream.Set("file",file);
00111   newOutStream.Set("tree",tree);
00112   newOutStream.Set("index",index);
00113 
00114   // Insert new output stream registry at key nout of "outstream" registry
00115   char cnoutkey[20];
00116   sprintf(cnoutkey,"%i",nout);
00117   outStreamRegistry.Set(cnoutkey,newOutStream);
00118   nout++;
00119   outStreamRegistry.Set("nout",nout); 
00120   outStreamRegistry.LockValues();
00121   
00122   // Store revised "outstream" registry
00123   fTempTags.UnLockValues();
00124   fTempTags.Set("outstream",outStreamRegistry);
00125   fTempTags.LockValues();
00126 
00127 }
00128 
00129 template<class T>
00130 bool RecRecordImp<T>::IsPersistedToOutputStream(const char* stream,
00131                           const char* file,const char* tree,int index) const {
00132   //
00133   //  Purpose:  Check to see if record has been persisted to the output
00134   //            stream/file/tree/tree index of interest. 
00135   //
00136   //  Arguments: stream/tree/file/tree index of interest.  If a value is
00137   //             left at default ("" for stream/tree/file, or -1 for index),
00138   //             that argument will not be checked. 
00139   //
00140   //  Return:  true or false. Result will be true if all non-default arguments 
00141   //           match those of one of the output streams to which this record
00142   //           has been persisted.
00143   //
00144   //  Contact:   S. Kasahara
00145   // 
00146 
00147   std::string s(stream);
00148   std::string f(file);
00149   std::string t(tree);
00150 
00151   Registry outStreamRegistry;
00152   int nout = 0;
00153   if ( fTempTags.Get("outstream",outStreamRegistry) ) {
00154     outStreamRegistry.Get("nout",nout);
00155     for ( int iout = 0; iout < nout; iout++) {
00156       char cioutkey[20];
00157       sprintf(cioutkey,"%i",iout);
00158       Registry outStream;
00159       outStreamRegistry.Get(cioutkey,outStream);
00160       bool isMatch = true;
00161       if ( !s.empty() ) {
00162         const char* cstream = 0;
00163         outStream.Get("stream",cstream);
00164         if ( std::string(cstream) != s ) isMatch = false;
00165       }        
00166       if ( !f.empty() ) {
00167         const char* cfile = 0;
00168         outStream.Get("file",cfile);
00169         if ( std::string(cfile) != f ) isMatch = false;
00170       }
00171 
00172       if ( !t.empty() ) {
00173         const char* ctree = 0;
00174         outStream.Get("tree",ctree);
00175         if ( std::string(ctree) != t ) isMatch = false;
00176       }
00177       if ( index > -1 ) {
00178         int storedindex = -1;
00179         outStream.Get("index",storedindex);
00180         if ( storedindex != index ) isMatch = false;
00181       }
00182       if ( isMatch ) {
00183         return true;  // found match in registry
00184       }
00185     } 
00186   }
00187 
00188   return false; // failed to find match in registry
00189 
00190 }
00191 
00192 template<class T>
00193 bool RecRecordImp<T>::IsPerOwned() const {
00194   //
00195   //  Purpose:  If IsPerOwned (def=false), record is owned by Persistency
00196   //            Mom should only Remove the record from its array of
00197   //            fragments, but not delete it.
00198   //
00199   //  Arguments: none.
00200   //
00201   //  Return:  true or false. 
00202   //
00203   //  Contact:   S. Kasahara
00204   // 
00205 
00206   int isPerOwned = 0;
00207   if ( !fTempTags.Get("isPerOwned",isPerOwned) ) return false;
00208   return ( isPerOwned ) ? true : false;
00209 
00210 }
00211 
00212 template<class T>
00213 bool RecRecordImp<T>::IsTransient() const {
00214   //
00215   //  Purpose:  If IsTransient (def=true), record will exist in memory for one
00216   //            job cycle only. 
00217   //
00218   //  Arguments: none.
00219   //
00220   //  Return:  true or false. 
00221   //
00222   //  Contact:   S. Kasahara
00223   // 
00224 
00225   int isTransient = 1;
00226   if ( !fTempTags.Get("isTransient",isTransient) ) return true;
00227   return ( isTransient ) ? true : false;
00228 
00229 }
00230 
00231 template<class T>
00232 void RecRecordImp<T>::SetTransient(bool isTransient) {
00233   //
00234   //  Purpose:  Set transient state of record.  If set true(def), record will
00235   //            exist in memory for one job cycle only.
00236   //
00237   //  Arguments: true or false.
00238   //
00239   //  Return:  none.
00240   //
00241   //  Contact:   S. Kasahara
00242   // 
00243 
00244   fTempTags.UnLockValues();
00245   if ( isTransient ) fTempTags.Set("isTransient",1);
00246   else fTempTags.Set("isTransient",0);
00247   fTempTags.LockValues();
00248   return;
00249 
00250 }
00251 
00252 template<class T>
00253 void RecRecordImp<T>::SetPerOwned(bool isPerOwned) {
00254   //
00255   //  Purpose:  Set ownership status of record.  If set true(def), record is
00256   //            owned by Persistency and the user should not delete.
00257   //
00258   //  Arguments: true or false.
00259   //
00260   //  Return:  none.
00261   //
00262   //  Contact:   S. Kasahara
00263   // 
00264 
00265   fTempTags.UnLockValues();
00266   if ( isPerOwned ) fTempTags.Set("isPerOwned",1);
00267   else fTempTags.Set("isPerOwned",0);
00268   fTempTags.LockValues();
00269   return;
00270 
00271 }
00272 
00273 template<class T>
00274 std::ostream& RecRecordImp<T>::Print(std::ostream& os) const {
00275   //
00276   //  Purpose:  Print status of record on ostream.
00277   //
00278   //  Arguments: os ostream to display on.
00279   //
00280   //  Return:  ostream reference.
00281   //
00282   //  Contact:   S. Kasahara
00283   // 
00284 
00285   os << "RecRecordImp::Print:\n" <<  fHeader << std::endl;
00286   fJobHistory.Print();
00287   
00288   return os;
00289 
00290 }
00291 
00292 template<class T>
00293 void  RecRecordImp<T>::Print(Option_t* /* option */) const {
00294   //
00295   //  Purpose:  Print header in form supported by TObject::Print.
00296   //
00297   //  Arguments: option (not used)
00298   //
00299   //  Return:  none.
00300   //
00301   //  Contact:   S. Kasahara
00302   // 
00303 
00304   Print(std::cout);
00305 
00306   return;
00307 
00308 }
00309 
00310 
00311 
00312 
00313 

Generated on Mon Feb 15 11:07:30 2010 for loon by  doxygen 1.3.9.1