Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

AlephExManager.cpp

Go to the documentation of this file.
00001 
00002 //
00003 //  Implementation of class AlephExManager
00004 //
00005 //  Author : G. Dissertori  ,  10.8.99
00006 //                             31.8.2000
00007 //
00009 
00010 
00011 #include <stdlib.h>
00012 #include <iostream>
00013 #include <fstream>
00014 #include <string>
00015 #include "mt19937-1.h"
00016 #include "AlephSession.h"
00017 #include "AlephIoManager.h"
00018 #include "AlephExManager.h"
00019 #include "AlephEpioExManager.h"
00020 #include "AlephROOTExManager.h"
00021 
00022 extern ofstream fout;
00023 
00024 
00025 //
00026 // bos declaration
00027 //
00028 BCS_DEF BCS;
00029 
00030 
00031 //
00032 // set the global instance variable
00033 //
00034 AlephManager* AlephExManager::_theAlephExManager=0;
00035 
00036 //
00037 // the instance function of the  Singleton
00038 //
00039 AlephManager* AlephExManager::TheAlephExManager()
00040 {
00041   if (_theAlephExManager == 0) 
00042     {
00043 
00044       // check which type of database we want
00045 
00046       string databaseType;
00047       // first check is the IoManager is there and has a card DBTY
00048       AlephManager* ioManager = (AlephSession::TheAlephSession())->aAlephManager("IoManager");
00049       if (ioManager != NULL) 
00050         {
00051           AlephStatus ioManStatus = ioManager->status();
00052           if (ioManStatus == INITIALIZED) 
00053             {
00054               // get the DBTY card
00055               databaseType = (((AlephIoManager*)ioManager)->theCardsReader()).getDbType();
00056             }
00057         }
00058       // else look for an environment variable
00059       else
00060         {
00061           databaseType = getenv("DATABASETYPE");
00062         }
00063       
00064       if (databaseType == "")
00065         {
00066           fout << " AlephExManager Warning : env variable DATABASETYPE not set" 
00067                << endl;
00068           fout << " Therefore creating a default database manager..." << endl;
00069           _theAlephExManager = new AlephExManager;
00070         }
00071       else
00072         {
00073           if ((databaseType == "epio") ||
00074               (databaseType == "epio/root"))
00075             {
00076               _theAlephExManager = new AlephEpioExManager;
00077             }
00078           else
00079           if (databaseType == "root")
00080             {
00081               _theAlephExManager = new AlephROOTExManager;
00082             }
00083           else  // else just create a default execution manager
00084             {
00085               fout << " AlephExManager Warning : env variable DATABASETYPE " 
00086                    << databaseType << " is not a valid db type " << endl;
00087               fout << " Therefore creating a default database manager..." << endl;
00088               _theAlephExManager = new AlephExManager;
00089             }
00090         }  
00091     }
00092   return _theAlephExManager;
00093 } 
00094 
00095 
00096 
00097 //
00098 // the constructor
00099 //
00100 AlephExManager::AlephExManager()
00101 {
00102   // call the constructor of the base class
00103   AlephManagerSetup("ExManager");
00104 
00105   // set the pointer to the database manager
00106   _theDbManager = (AlephDbManager*)(alephSession()->aAlephManager("DbManager"));
00107 
00108   // set current run and event numbers
00109   _currentRun = 0;
00110   _currentEvt = 0;
00111 }
00112 
00113 
00114 //
00115 // the destructor
00116 //
00117 AlephExManager::~AlephExManager() 
00118 {
00119   AlephManagerShutDown();
00120   delete [] _theAlephExManager;
00121 }
00122 
00123 
00124 //
00125 // the initialization step
00126 //
00127 AlephRC AlephExManager::initialize()
00128 {
00129   
00130   // say something
00131   fout << " AlephExManager :  initializing .... " << endl;
00132   fout << " AlephExManager :  Setting random generator seed to ";
00133   // first check is the IoManager is there 
00134   AlephManager* ioManager = (AlephSession::TheAlephSession())->aAlephManager("IoManager");
00135   unsigned long theseed = 1;
00136   if (ioManager != NULL) 
00137   {
00138     AlephStatus ioManStatus = ioManager->status();
00139     if (ioManStatus == INITIALIZED) 
00140      {
00141       // get the SEED card (if not, there is an unknown value)
00142       theseed = (((AlephIoManager*)ioManager)->theCardsReader()).getSeed();
00143      }
00144   }
00145   fout << theseed << endl;
00146   sgenrand(theseed);
00147   fout << " AlephExManager :  calling the user initialization " << endl;
00148 
00149   // call the user init
00150   UserInit();
00151 
00152   // set the status
00153   setStatus(INITIALIZED); 
00154 
00155   return AlephOK;
00156 }
00157 
00158 
00159 //
00160 // the running step
00161 //
00162 AlephRC AlephExManager::run()
00163 {
00164   
00165   // set the status
00166   setStatus(RUNNING); 
00167 
00168   // say something
00169   fout << " AlephExManager :  start running .... " << endl;
00170   fout << " AlephExManager :  calling the user event routine " << endl;
00171 
00172   // call the user event : note : in the default version bb may be null!!
00173   AlphaBanks bb(AlphaBanks::BOS);
00174   bb.InitObjectStructure();
00175   if (!bb.isValid())
00176         fout << " AlephExManager :  inconsistency in Event. Skipped " << endl;
00177   else
00178         UserEvent(bb);
00179 
00180   return AlephOK;
00181 }
00182 
00183 
00184 
00185 //
00186 // the termination step
00187 //
00188 AlephRC AlephExManager::terminate()
00189 {
00190   
00191   // say something
00192   fout << " AlephExManager :  terminating .... " << endl;
00193   fout << " AlephExManager :  calling the user termination " << endl;
00194 
00195   // call the user term and clear Ntuple Image
00196   UserTerm();
00197 
00198   // set the status
00199   setStatus(TERMINATED); 
00200 
00201   return AlephOK;
00202 }
00203 
00204 //
00205 // set current run and event number
00206 //
00207 void AlephExManager::setCurrentRunEvt(const long& CurrentRun,
00208                                       const long& CurrentEvt)
00209 {
00210   _currentRun = CurrentRun;
00211   _currentEvt = CurrentEvt;
00212 }
00213 
00214 //
00215 // get current Run number
00216 //
00217 long AlephExManager::getCurrentRun() const
00218 {
00219   return _currentRun;
00220 }
00221 
00222 //
00223 // get current Evt number
00224 //
00225 long AlephExManager::getCurrentEvt() const
00226 {
00227   return _currentEvt;
00228 }
00229 
00230 //
00231 // get the event counter
00232 //
00233 long AlephExManager::getEventCount() const
00234 {
00235   return EventCount;
00236 }
00237 
00238 //
00239 // give pointers to managers, NtupleWriter, cardsreader, ...
00240 //
00241 AlephSession* AlephExManager::theSession() const
00242 {
00243   return AlephSession::TheAlephSession();
00244 }
00245 
00246 AlephDbManager* AlephExManager::theDbm() const
00247 {
00248   return (AlephDbManager*)AlephSession::TheAlephSession()->aAlephManager("DbManager");
00249 }
00250 
00251 AlephIoManager* AlephExManager::theIom() const
00252 {
00253   return (AlephIoManager*)theSession()->aAlephManager("IoManager");
00254 }
00255 
00256 AlephCardsReader* AlephExManager::theCardsReader() const
00257 {
00258   AlephIoManager* iom = theIom();
00259   if (iom == NULL) 
00260     {
00261       fout << " AlephExManager::theCardsReader : WARNING!! " << endl;
00262       fout << "       no IoManager has been created!! " << endl;
00263       fout << "       therefore returning NULL pointer !! " << endl;
00264       return NULL;     
00265     }
00266   else
00267     return &(iom->theCardsReader());
00268 }
00269 
00270 AlephNtupleWriter* AlephExManager::theNtupleWriter() const
00271 {
00272   AlephIoManager* iom = theIom();
00273   if (iom == NULL)
00274     {
00275       fout << " AlephExManager::theCardsReader : WARNING!! " << endl;
00276       fout << "       no IoManager has been created!! " << endl;
00277       fout << "       therefore returning NULL pointer !! " << endl;
00278       return NULL;
00279     }
00280   else
00281    return &(iom->theNtupleWriter());
00282 }
00283 

Generated at Wed Jun 18 17:19:09 2003 for ALPHA++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001