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

AlephSession.cpp

Go to the documentation of this file.
00001 
00002 //
00003 //  Implementation of class AlephSession
00004 //
00005 //  The Base Class for an AlephSession.
00006 //  It is a Singleton
00007 //
00008 //  Author : G. Dissertori  ,  30.10.98
00009 //  Modified: C. Delaere    ,  16.08.02 renewed timing
00010 //
00012 
00013 #include <fstream>
00014 #include "AlephSession.h"
00015 #include "AlephIoManager.h"
00016 #include "AlephDbManager.h"
00017 #include "AlephExManager.h"
00018 
00019 extern ofstream fout;
00020 
00021 //
00022 // set the global instance variable
00023 //
00024 AlephSession* AlephSession::_theAlephSession=0;
00025 
00026 //
00027 // implementation of the instance member
00028 //
00029 AlephSession* AlephSession::TheAlephSession()
00030 {
00031   if (_theAlephSession == 0) 
00032   {
00033     _theAlephSession = new AlephSession;
00034   } 
00035   return _theAlephSession;
00036 
00037 }
00038 
00039 //
00040 // the constructor sets the default sessionType and initializes other
00041 // private members 
00042 //
00043 AlephSession::AlephSession()
00044 {
00045   // set the default session type
00046   _thisSessionType = "BATCH";
00047   _startTime = 0;
00048   _endTime   = 0;
00049   _theAlephIoManager=0;
00050   _theAlephDbManager=0;
00051   _theAlephExManager=0;
00052 }
00053 
00054 //
00055 // the destructor clears the memory
00056 //
00057 AlephSession::~AlephSession()
00058 {
00059   //  call the destructor of the managers
00060   //  _theAlephIoManager->~AlephIoManager();
00061   //  _theAlephDbManager->~AlephDbManager();
00062   //  _theAlephExManager->~AlephExManager();
00063 }
00064 
00065 //
00066 // the setSessiontype Method
00067 //
00068 void AlephSession::setSessionType(const string& theType)
00069 {
00070   // analyze the character string, just the first 5 characters 
00071   string theTypeShort;
00072   theTypeShort.resize(5);
00073   int i;
00074   for (i=0 ; i<5 ; i++)
00075   {
00076     theTypeShort[i] = toupper(theType[i]);
00077   }
00078   if (!theTypeShort.compare("BATCH"))
00079   {
00080     _thisSessionType = "BATCH";
00081   }
00082   else
00083   if (!theTypeShort.compare("INTER"))
00084   {
00085     _thisSessionType = "INTER";
00086   }
00087   fout << " The session is set to type " << _thisSessionType << endl;
00088 }
00089 
00090 //
00091 // get the sessiontype Method
00092 //
00093 string AlephSession::sessionType() const
00094 {
00095   return _thisSessionType;
00096 }
00097 
00098 //
00099 // get the pointer to a specific manager, defined by the input string
00100 //
00101 AlephManager* AlephSession::aAlephManager(const string& aManager) const
00102 {
00103   // compare the string
00104   if (!aManager.compare("IoManager"))
00105       return _theAlephIoManager;
00106   else
00107   if (!aManager.compare("DbManager"))
00108       return _theAlephDbManager;
00109   else
00110   if (!aManager.compare("ExManager"))
00111       return _theAlephExManager;
00112   else
00113   {
00114     fout << "AlephSession : there is no manager of type " << aManager 
00115          << " !  Warning : returning NULL pointer " << endl;
00116     return 0;
00117   }
00118 }
00119 
00120 //
00121 // monitoring :  grap the starting time
00122 //
00123 void AlephSession::startTimer(bool precision)
00124 {
00125   if(precision)
00126         _startClock = clock();
00127   else
00128         _startTime = time(0);
00129 }
00130 
00131 //
00132 // monitoring :  grap the ending time
00133 //
00134 void AlephSession::stopTimer(bool precision)
00135 {
00136   if(precision)
00137         _endClock = clock();
00138   else
00139         _endTime = time(0);
00140 }
00141 
00142 //
00143 // debug level setting and getting
00144 //
00145 void AlephSession::setDebugLevel(const int& aLevel)
00146 {
00147   _debugLevel = aLevel;
00148 }
00149 
00150 int AlephSession::debugLevel() const
00151 {
00152   return _debugLevel;
00153 }
00154 
00155 //
00156 // the initialization step
00157 //
00158 AlephRC AlephSession::initialize()
00159 {
00160   AlephRC rc;
00161   // start the timer
00162   startTimer();
00163   startTimer(true);
00164   // print out some stuff
00165   const  time_t aStartTime = _startTime; 
00166   struct tm* aTimePointer = gmtime(&aStartTime);
00167   char* aTimeCharA = asctime(aTimePointer);
00168   // need this manipulation to cut out the newline character created by asctime
00169   char* aTimeCharB = new char[strlen(aTimeCharA)];
00170   strncpy(aTimeCharB,aTimeCharA,strlen(aTimeCharA)-1);
00171 
00172   fout << "**************************************************" << endl;
00173   fout << "*                                                *" << endl;
00174   fout << "*                  ALEPHSESSION                  *" << endl;
00175   fout.setf(ios::showpoint);
00176   fout.precision(2);
00177   fout << "*                  Version  " << AlephSessionVersion 
00178        << "                  *" << endl;
00179   fout << "*                                                *" << endl;
00180   fout << "*     The session has been initialized at:       *" << endl;
00181   fout << "*           " << aTimeCharB <<     "             *" << endl;
00182   fout << "*                                                *" << endl;
00183   fout << "**************************************************" << endl;
00184 
00185   fout.precision(6);
00186   delete[] aTimeCharB;
00187 
00188   cout << "    **************************************************" << endl;
00189   cout << "    *                                                *" << endl;
00190   cout << "    *                     ALPHA++                    *" << endl;
00191   cout << "    *                                                *" << endl;
00192   cout << "    *    You can find more outputs in the file       *" << endl;
00193   cout << "    *    defined with the APPL_OUT env. variable.    *" << endl;
00194   cout << "    *                                                *" << endl;
00195   cout << "    **************************************************" << endl;
00196 
00197   cout << endl << endl << "Initialisation of ALPHA++ managers..." << endl;
00198   // create and init the various managers
00199   // the IO manager
00200   _theAlephIoManager = AlephIoManager::TheAlephIoManager();
00201   rc = _theAlephIoManager->initialize();
00202   // the DB manager
00203   _theAlephDbManager = AlephDbManager::TheAlephDbManager();
00204   rc = _theAlephDbManager->initialize();
00205   // the Ex manager
00206   _theAlephExManager = AlephExManager::TheAlephExManager();
00207   rc = _theAlephExManager->initialize();
00208   // precise time report for the initialisation
00209   stopTimer(true);
00210   init_time = ( _endClock - _startClock)/(CLOCKS_PER_SEC / (double) 1000.0);
00211   fout << endl << "Session initialized in " << init_time << " miliseconds" << endl;
00212   return rc;
00213 }
00214 
00215 //
00216 // the running step
00217 //
00218 AlephRC AlephSession::run()
00219 {
00220   AlephRC rc;
00221   // Say Hello...
00222   fout << " AlephSession starts running ... " << endl;
00223   cout << "AlephSession starts running ... " << endl<< endl<< endl;
00224   // run the execution manager
00225   startTimer(true);
00226   rc = ((AlephExManager*)_theAlephExManager)->run();
00227   stopTimer(true);
00228   run_time = ( _endClock - _startClock)/(CLOCKS_PER_SEC / (double) 1000.0)/(double) 1000.0;
00229   // Say Goodbye...
00230   cout << endl << endl << endl << "AlephSession stops running ... " << endl;
00231   fout << " AlephSession stops running ... " << endl;
00232   return rc;
00233 }
00234 
00235 //
00236 // the terminating step
00237 //
00238 AlephRC AlephSession::terminate()
00239 {
00240   AlephRC rc;
00241   // start the timer
00242   startTimer(true);
00243   // a last comment...
00244   cout <<  "Termination of ALPHA++ managers..." << endl << endl;
00245   // send the terminate to the various managers
00246   // order is important : it is the inverse order of initialization
00247   // the Ex manager
00248   long EventCount = ((AlephExManager*)_theAlephExManager)->getEventCount();
00249   rc = _theAlephExManager->terminate();
00250   // the DB manager
00251   rc = _theAlephDbManager->terminate();
00252   // the IO manager
00253   rc = _theAlephIoManager->terminate();
00254   // stop the timer
00255   stopTimer();
00256   stopTimer(true);
00257   // compute finally elapsed time
00258   run_time = difftime(_endTime,_startTime) > 900 ? difftime(_endTime,_startTime) : run_time;
00259   // print out some stuff
00260   const  time_t aEndTime = _endTime; 
00261   struct tm* aTimePointer = gmtime(&aEndTime);
00262   char* aTimeCharA = asctime(aTimePointer);
00263   // need this manipulation to cut out the newline character created by asctime
00264   char* aTimeCharB = new char[strlen(aTimeCharA)];
00265   strncpy(aTimeCharB,aTimeCharA,strlen(aTimeCharA)-1);
00266   
00267   term_time = ( _endClock - _startClock)/(CLOCKS_PER_SEC / (double) 1000.0);
00268   fout << "Session terminated in " << term_time << " miliseconds" << endl << endl;
00269 
00270   fout << "**************************************************" << endl;
00271   fout << "*                                                *" << endl;
00272   fout << "*                  ALEPHSESSION                  *" << endl;
00273   fout.setf(ios::showpoint);
00274   fout.precision(2);
00275   fout << "*                  Version  " << AlephSessionVersion 
00276        << "                  *" << endl;
00277   fout << "*                                                *" << endl;
00278   fout << "*        The session has terminated at:          *" << endl;
00279   fout << "*           " << aTimeCharB <<      "            *" << endl;
00280   fout << "*                                                *" << endl;
00281   fout.precision(10);
00282   fout << "*   Elapsed time in seconds = " << run_time << 
00283           "        *" << endl;
00284   fout << "**************************************************" << endl;
00285 
00286   fout.precision(6);
00287   delete[] aTimeCharB;
00288 
00289   cout << " ------------ " << endl;
00290   cout << " Time Report: " << endl;
00291   cout << " ------------ " << endl;
00292   cout << "    Initialisation : " << init_time << " miliseconds" << endl;
00293   cout << "    Running : " << endl;
00294   cout << "         " << EventCount << " events : " << run_time << " seconds" << endl;
00295   cout << "         " << "1 event : " << ( EventCount > 0 ? (run_time/EventCount)*1000 : 0. ) << " miliseconds" << endl;
00296   cout << "    Termination : " << term_time << " miliseconds" << endl;
00297   cout << " ------------ " << endl << endl;
00298 
00299   cout << "    **************************************************" << endl;
00300   cout << "    *                                                *" << endl;
00301   cout << "    *                     ALPHA++                    *" << endl;
00302   cout << "    *                                                *" << endl;
00303   cout << "    *      The session has terminated normaly        *" << endl;
00304   cout << "    *              Have a nice Day ;-)               *" << endl;
00305   cout << "    *                                                *" << endl;
00306   cout << "    **************************************************" << endl << endl;
00307   
00308   return AlephOK;
00309 }

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