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

RecMinos.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // RecMinos
00004 //
00005 // RecMinos is the Base Class for MINOS records
00006 //
00007 // Author:  R. Hatcher   4/2001
00008 //
00010 
00011 #include <iostream>
00012 using std::cout;
00013 using std::endl;
00014 
00015 #include "Record/RecMinos.h"
00016 #include "Record/RecMinosHdr.h"
00017 
00018 ClassImp(RecMinos)
00019 
00020 //_____________________________________________________________________________
00021 RecMinos::RecMinos()
00022    : fHeader(new RecMinosHdr())
00023 {
00024    // Default constructor
00025    fComponents.SetOwner(true);
00026    fTemporaries.SetOwner(true);
00027 }
00028 
00029 //_____________________________________________________________________________
00030 RecMinos::RecMinos(RecMinosHdr* header)
00031    : fHeader(header)
00032 {
00033    // normal ctor, adopts the RecMinosHdr for ownership
00034    fComponents.SetOwner(true);
00035    fTemporaries.SetOwner(true);
00036 }
00037 
00038 
00039 //_____________________________________________________________________________
00040 RecMinos::~RecMinos()
00041 {
00042   // delete all owned sub-objects 
00043   fComponents.Delete(); 
00044   fTemporaries.Delete(); 
00045 
00046   if (fHeader) delete fHeader; fHeader = 0;
00047 
00048 }
00049 
00050 //_____________________________________________________________________________
00051 void RecMinos::AdoptComponent(TObject* component) 
00052 {
00053   fComponents.Add(component);
00054 }
00055 //_____________________________________________________________________________
00056 void RecMinos::AdoptTemporary(TObject* temporary) 
00057 {
00058   fTemporaries.Add(temporary);
00059 }
00060 
00061 //_____________________________________________________________________________
00062 TObject* RecMinos::RemoveComponent(TObject* component) 
00063 {
00064   return fComponents.Remove(component);
00065 }
00066 //_____________________________________________________________________________
00067 TObject* RecMinos::RemoveTemporary(TObject* temporary) 
00068 {
00069   return fTemporaries.Remove(temporary);
00070 }
00071 
00072 //_____________________________________________________________________________
00073 const TObject* RecMinos::FindComponent(const char *classname,
00074                                        const char *objname) const
00075 {
00076 
00077 // Returns the *last* selected Component.  If classname is a null ptr
00078 // or blank string, no class selection is done.  If classname is
00079 // provided, the qualifying object must InheritFrom() or be a classname.
00080 // The objname is optional, but, if filled, will further qualify the
00081 // selection by requiring agreement with the GetName() method of the
00082 // selected object.
00083 
00084    TString classtr("");
00085    if (classname)
00086       classtr.Append(TString(classname).Strip(TString::kBoth));
00087 
00088    TString objstr("");
00089    if (objname)
00090      objstr.Append(TString(objname).Strip(TString::kBoth));
00091 
00092    TObjArrayIter itr(&fComponents,kIterBackward);
00093    TObject *obj;
00094 
00095    while ((obj = itr())) {
00096 
00097 // First check whether object InheritsFrom "classname"
00098      if (classtr.IsNull() || obj->InheritsFrom(classtr)) {
00099 
00100 // Then check whether object name equals "objname"
00101        if (objstr.IsNull() || (objstr == obj->GetName()))
00102          return obj;
00103      }
00104    }
00105    return 0;
00106 
00107 }
00108 
00109 //_____________________________________________________________________________
00110 const TObject* RecMinos::FindTemporary(const char *classname,
00111                                        const char *objname) const
00112 {
00113 
00114 // Returns the *last* selected Temporary.  If classname is a null ptr
00115 // or blank string, no class selection is done.  If classname is
00116 // provided, the qualifying object must InheritFrom() or be a classname.
00117 // The objname is optional, but, if filled, will further qualify the
00118 // selection by requiring agreement with the GetName() method of the
00119 // selected object.
00120 
00121    TString classtr("");
00122    if (classname)
00123       classtr.Append(TString(classname).Strip(TString::kBoth));
00124 
00125    TString objstr("");
00126    if (objname)
00127      objstr.Append(TString(objname).Strip(TString::kBoth));
00128 
00129    TObjArrayIter itr(&fTemporaries,kIterBackward);
00130    TObject *obj;
00131 
00132    while ((obj = itr())) {
00133 
00134 // First check whether object InheritsFrom "classname"
00135      if (classtr.IsNull() || obj->InheritsFrom(classtr)) {
00136 
00137 // Then check whether object name equals "objname"
00138        if (objstr.IsNull() || (objstr == obj->GetName()))
00139          return obj;
00140      }
00141    }
00142    return 0;
00143 
00144 }
00145 
00146 //_____________________________________________________________________________
00147 const VldContext* RecMinos::GetVldContext() const
00148 {
00149    // return a pointer to the VldContext in the header
00150    // (if there is one, otherwise 0 ptr) 
00151    const RecMinosHdr* head = GetHeader();
00152    if (head) return &(head->GetVldContext());
00153    return 0;
00154 }
00155 
00156 //_____________________________________________________________________________
00157 void RecMinos::Print(Option_t * /* option */) const
00158 {
00159    cout << "RecMinos::Print Header: " << endl;
00160    if (fHeader) fHeader -> Print();
00161    else         cout << "  ... no RecMinosHdr" << endl;
00162    fJobHistory.Print();
00163    
00164    TObject *obj;
00165 
00166    cout << "RecMinos::Print Components: " << endl;
00167    TObjArrayIter itr(&fComponents);
00168    while ((obj = itr())) {
00169       cout << obj->ClassName() << " " << obj->GetName() << endl;
00170    }
00171 
00172 }
00173 
00174 //_____________________________________________________________________________
00175 
00176 void RecMinos::HasBeenModified() {
00177   //
00178   //  Purpose:  Handle generic record tasks appropriate for when record
00179   //            has been newly modified.
00180   //
00181   //  Arguments: none.
00182   //
00183   //  Return:  none.
00184   //
00185   //  Contact:   S. Kasahara
00186   // 
00187   //  Notes:  The default behavior provided by this method is to clear
00188   //          the Registry value associated with the key "outstream" in
00189   //          the Registry fTempTags data member.  This indicates to
00190   //          any output module(s) in the user's job path(s) that the modified
00191   //          record should be re-persisted.
00192   // 
00193 
00194   fTempTags.RemoveKey("outstream");
00195   return;
00196 
00197 }
00198 
00199 //_____________________________________________________________________________
00200 
00201 void RecMinos::PersistedToOutputStream(const char* stream,
00202                       const char* file, const char* tree, int index) {
00203   //
00204   //  Purpose:  Mark the record as having been stored in the named stream,file,
00205   //            tree, tree index location.
00206   //
00207   //  Arguments: stream name, file name, tree name, tree index to which record 
00208   //             was stored.  
00209   //
00210   //  Return:  none.
00211   //
00212   //  Contact:   S. Kasahara
00213   // 
00214   //  Notes:  The output stream,file,tree,treeindex will be stored in
00215   //          Registry fTempTags in the following manner:
00216   //          key         type/value
00217   //          ===         ==========
00218   //          "outstream" Registry/see below:
00219   //                      key     type/value
00220   //                      ===     ==========
00221   //                      "nout"  int/# times this record has been persisted
00222   //                       "0"    Registry/see below:
00223   //                       "1"    Registry/   "
00224   //                       ...    Registry/   "
00225   //                     "nout-1" Registry/   "
00226   //                              key      type/value
00227   //                              ===      ==========
00228   //                              "stream" const char*/output stream name
00229   //                              "file"   const char*/output file name
00230   //                              "tree"   const char*/output tree name
00231   //                              "index"  int        /output tree index
00232   //          
00233 
00234   Registry outStreamRegistry;
00235   int nout = 0;
00236   if ( fTempTags.Get("outstream",outStreamRegistry) ) {
00237     outStreamRegistry.Get("nout",nout); 
00238   }
00239   outStreamRegistry.UnLockValues();
00240 
00241   // New output stream registry
00242   Registry newOutStream;
00243   newOutStream.Set("stream",stream);
00244   newOutStream.Set("file",file);
00245   newOutStream.Set("tree",tree);
00246   newOutStream.Set("index",index);
00247 
00248   // Insert new output stream registry at key nout of "outstream" registry
00249   char cnoutkey[20];
00250   sprintf(cnoutkey,"%i",nout);
00251   outStreamRegistry.Set(cnoutkey,newOutStream);
00252   nout++;
00253   outStreamRegistry.Set("nout",nout); 
00254   outStreamRegistry.LockValues();
00255   
00256   // Store revised "outstream" registry
00257 
00258   fTempTags.UnLockValues();
00259   fTempTags.Set("outstream",outStreamRegistry);
00260   fTempTags.LockValues();
00261 
00262 }
00263 
00264 //_____________________________________________________________________________
00265 
00266 bool RecMinos::IsPersistedToOutputStream(const char* stream,
00267                           const char* file,const char* tree,int index) const {
00268   //
00269   //  Purpose:  Check to see if record has been persisted to the output
00270   //            stream/file/tree/tree index of interest. 
00271   //
00272   //  Arguments: stream/tree/file/tree index of interest.  If a value is
00273   //             left at default ("" for stream/tree/file, or -1 for index),
00274   //             that argument will not be checked. 
00275   //
00276   //  Return:  true or false. Result will be true if all non-default arguments 
00277   //           match those of one of the output streams to which this record
00278   //           has been persisted.
00279   //
00280   //  Contact:   S. Kasahara
00281   // 
00282 
00283   std::string s(stream);
00284   std::string f(file);
00285   std::string t(tree);
00286 
00287   Registry outStreamRegistry;
00288   int nout = 0;
00289   if ( fTempTags.Get("outstream",outStreamRegistry) ) {
00290     outStreamRegistry.Get("nout",nout);
00291     for ( int iout = 0; iout < nout; iout++) {
00292       char cioutkey[20];
00293       sprintf(cioutkey,"%i",iout);
00294       Registry outStream;
00295       outStreamRegistry.Get(cioutkey,outStream);
00296       bool isMatch = true;
00297       if ( !s.empty() ) {
00298         const char* cstream = 0;
00299         outStream.Get("stream",cstream);
00300         if ( std::string(cstream) != s ) isMatch = false;
00301       }        
00302       if ( !f.empty() ) {
00303         const char* cfile = 0;
00304         outStream.Get("file",cfile);
00305         if ( std::string(cfile) != f ) isMatch = false;
00306       }
00307 
00308       if ( !t.empty() ) {
00309         const char* ctree = 0;
00310         outStream.Get("tree",ctree);
00311         if ( std::string(ctree) != t ) isMatch = false;
00312       }
00313       if ( index > -1 ) {
00314         int storedindex = -1;
00315         outStream.Get("index",storedindex);
00316         if ( storedindex != index ) isMatch = false;
00317       }
00318       if ( isMatch ) {
00319         return true;  // found match in registry
00320       }
00321     } 
00322   }
00323 
00324   return false; // failed to find match in registry
00325 
00326 }
00327 
00328 
00329 //_____________________________________________________________________________
00330 
00331 bool RecMinos::IsTransient() const {
00332   //
00333   //  Purpose:  If IsTransient (def), record will exist in memory for one
00334   //            job cycle only. 
00335   //
00336   //  Arguments: none.
00337   //
00338   //  Return:  true or false. 
00339   //
00340   //  Contact:   S. Kasahara
00341   // 
00342 
00343   int isTransient = 1;
00344   fTempTags.Get("isTransient",isTransient);
00345   return ( isTransient ) ? true : false;
00346 
00347 }
00348 
00349 
00350 //_____________________________________________________________________________
00351 
00352 void RecMinos::SetTransient(bool isTransient) {
00353   //
00354   //  Purpose:  Set transient state of record.  If set true(def), record will
00355   //            exist in memory for one job cycle only.
00356   //
00357   //  Arguments: true or false.
00358   //
00359   //  Return:  none.
00360   //
00361   //  Contact:   S. Kasahara
00362   // 
00363 
00364   fTempTags.UnLockValues();
00365   if ( isTransient ) fTempTags.Set("isTransient",1);
00366   else fTempTags.Set("isTransient",0);
00367   fTempTags.LockValues();
00368   return;
00369 
00370 }
00371 
00372 //_____________________________________________________________________________

Generated on Mon Jun 16 14:58:28 2008 for loon by  doxygen 1.3.9.1