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

AlephEpioExManager.cpp

Go to the documentation of this file.
00001 
00002 //
00003 //  Implementation of class AlephEpioExManager
00004 //
00005 //  Author : G. Dissertori  ,  30.08.2000
00006 //
00008 
00009 #include <stdlib.h>
00010 #include <iostream>
00011 #include <fstream>
00012 #include <string>
00013 #include "mt19937-1.h"
00014 #include "AlephExManager.h"
00015 #include "AlephEpioExManager.h"
00016 #include "AlephDbManager.h"
00017 #include "AlephIoManager.h"
00018 #include "AlephCardsReader.h"
00019 #include "AlephInteractiveHandler.h"
00020 #include "DefaultInteractiveActions.h"
00021 #include "AlephRegisteredAction.h"
00022 
00023 extern ofstream fout;
00024 
00025 //
00026 // the constructor
00027 //
00028 AlephEpioExManager::AlephEpioExManager()
00029 {
00030   // call the constructor of the base class
00031   AlephManagerSetup("EpioExManager");
00032   fout << " An AlephEpioExManager has been created " << endl;
00033 }
00034 
00035 //
00036 // the destructor
00037 //
00038 AlephEpioExManager::~AlephEpioExManager() {}
00039 
00040 //
00041 // the initialization step
00042 //
00043 AlephRC AlephEpioExManager::initialize()
00044 {
00045   // get debug level
00046   int debug = (AlephSession::TheAlephSession())->debugLevel();
00047   // say something
00048   fout << " AlephEpioExManager :  initializing .... " << endl;
00049   fout << " AlephEpioExManager :  Setting random generator seed to ";
00050   // first check is the IoManager is there 
00051   AlephManager* ioManager = (AlephSession::TheAlephSession())->aAlephManager("IoManager");
00052   unsigned long theseed = 1;
00053   if (ioManager != NULL)
00054     {
00055       AlephStatus ioManStatus = ioManager->status();
00056       if (ioManStatus == INITIALIZED)
00057        {
00058         // get the SEED card (if not, there is an unknown value)
00059         theseed = (((AlephIoManager*)ioManager)->theCardsReader()).getSeed();
00060        }
00061     }
00062   fout << theseed << endl;
00063   sgenrand(theseed);
00064   // initialize alpha and bos
00065   BOS_INITIALIZE();
00066   if (debug >= 0) 
00067   {
00068     fout << endl;
00069     fout << " C bos_initialize CALLED ******* "<< endl;  
00070     fout << endl;
00071   }
00072   // initialisation of default interactive functions
00073   AlephRegisteredAction<GeneralEventInfo> code100;
00074   AlephRegisteredAction<CollectTracks> code200;
00075   AlephRegisteredAction<CollectLeptons> code300;
00076   AlephRegisteredAction<CollectJets> code400;
00077   // User Initialization
00078   fout << " AlephEpioExManager :  calling user init " << endl;
00079   UserInit();
00080   return AlephOK;
00081 }
00082 
00083 //
00084 // the termination step
00085 //
00086 AlephRC AlephEpioExManager::terminate()
00087 {
00088   // say something
00089   fout << " AlephEpioExManager :  terminating .... " << endl;
00090   fout << " AlephEpioExManager :  calling user term " << endl;
00091   UserTerm();
00092   // This is here to close alpha and  to write out the histograms (if there have been created any)
00093   CLOSE_RUN();
00094   // set the status
00095   setStatus(TERMINATED); 
00096   return AlephOK;
00097 }
00098 
00099 //
00100 // the running step
00101 //
00102 AlephRC AlephEpioExManager::run()
00103 {
00104   // check first if the database manager is up
00105   AlephManager* dbManager = (AlephSession::TheAlephSession())->aAlephManager("DbManager");
00106   if (dbManager == NULL)
00107     {
00108       fout << " FATAL : AlephEpioExManager : there is NO DbManager !! " << endl;
00109       return AlephERROR;
00110     }
00111   else
00112     {
00113       // check if it is initialized
00114       AlephStatus dbManStatus = dbManager->status();
00115       if (dbManStatus != INITIALIZED) dbManager->initialize(); 
00116       // check the session type
00117       string sessionTy = (AlephSession::TheAlephSession())->sessionType();
00118       // if it is batch, call the loop function
00119       fout << " The session type is " << sessionTy << endl;
00120       if (sessionTy == "BATCH") 
00121         {
00122           AlephRC  loopRC = loopAll();
00123           return loopRC;
00124         }
00125       else // else do interactive stuff
00126       if (sessionTy  == "INTER")
00127         {
00128           // call next user request
00129           AlephRC  loopRC = loopInter();
00130           return loopRC;
00131         }
00132       else  // do nothing
00133         {
00134           fout << "  FATAL : AlephEpioExManager : do not know this session Type !! " << endl;
00135           return AlephERROR;
00136         }
00137     }
00138 }
00139 
00141 // batch loop
00143 AlephRC AlephEpioExManager::loopAll()
00144 {
00145   // check if user wants a reading or writing transaction
00146   // get it from the cards
00147   // first check if the IoManager is there
00148   AlephManager* ioManager = (AlephSession::TheAlephSession())->aAlephManager("IoManager");
00149   if (ioManager == NULL) 
00150     {
00151       fout << "  FATAL : AlephEpioExManager : there is no IoManager !! " << endl;
00152       return AlephERROR;
00153     }
00154   else
00155     {
00156       AlephStatus ioManStatus = ioManager->status();    
00157       if (ioManStatus != INITIALIZED) ioManager->initialize(); 
00158       // get the TATY card
00159       string transType = (((AlephIoManager*)ioManager)->theCardsReader()).getTaType();
00160       if (transType == "write")
00161         {         
00162           return loopAllWrite();
00163         }
00164       else
00165         {
00166           return loopAllRead();
00167         }
00168     }
00169 }
00170 
00172 // batch reading loop
00174 AlephRC AlephEpioExManager::loopAllRead()
00175 {
00176   // for epio reading we just use default dbmanager
00177   AlephDbManager* epioMan = theDbm();
00178   // get the cards Reader
00179   AlephCardsReader& cardsReader = theIom()->theCardsReader();
00180   // start a read transaction if not already done
00181   // HTLs are needed, than start a writing transaction
00182   epioMan->startTransaction(READING);
00183   // get the debug level
00184   int debug = (AlephSession::TheAlephSession())->debugLevel();
00186 // main event loop
00188   int krun,kevt,ier1;
00189   EventCount = 0;
00190   do {
00191     READ_EVENT(krun,kevt,ier1);
00192     if (ier1 != 0) break;
00193     // set current Run and event numbers
00194     setCurrentRunEvt(krun,kevt);    
00195     EventCount++;
00196     if (debug >= 2) {
00197       fout << endl;
00198       fout << "*************************************************" << endl;
00199       fout << "** Run # " << krun << " , Evt # " << kevt << "  --> " << endl;
00200       fout << "*************************************************" << endl;
00201     }
00202     // prepare AlphaBanks for analysis
00203     AlphaBanks bb(AlphaBanks::BOS);
00204     bb.InitObjectStructure();
00205     if(!bb.isValid())
00206             fout << " AlephEpioExManager : inconsistency in event. Skipped " << endl;
00207     else
00208             UserEvent(bb);
00209     // some status report
00210     if (! (EventCount % 1000))
00211       {
00212         fout << endl;
00213         fout << "******* " << EventCount << 
00214                 " events read " << endl;
00215         fout << "******* current Run # = " << krun << endl;
00216         fout << "******* current Evt # = " << kevt << endl;
00217         fout << endl;
00218       }
00220 // end main event loop
00222   } while (ier1 == 0);
00223   fout << endl;
00224   fout << " *** " << EventCount << " Events have been read" << endl;
00225   fout << endl;
00226   // stop the transaction
00227   AlephRC stopRC = epioMan->stopTransaction();
00228   if (debug >= 0)
00229   {
00230     fout << endl;
00231     fout << " ****** AlephEpioExManager::loopAllRead : transaction stopped ****** " << endl;
00232     fout << endl;
00233   }
00234   return stopRC;
00235 }
00236  
00238 // batch writing loop
00240 AlephRC AlephEpioExManager::loopAllWrite()
00241 {
00242   // for epio reading we just use default dbmanager
00243   AlephDbManager* epioMan = theDbm();
00244   // get the cards Reader
00245   AlephCardsReader& cardsReader = theIom()->theCardsReader();
00246   // start a read transaction 
00247   epioMan->startTransaction(READING);
00248   // get the debug level
00249   int debug = (AlephSession::TheAlephSession())->debugLevel();
00251 // main event loop
00253   int krun,kevt,ier1;
00254   EventCount = 0;
00255   AlephManager* dbManager = (AlephSession::TheAlephSession())->aAlephManager("DbManager");
00256   do {
00257     READ_EVENT(krun,kevt,ier1);
00258     if (ier1 != 0) break;
00259     // set current Run and event numbers
00260     setCurrentRunEvt(krun,kevt);    
00261     EventCount++;
00262     if (debug >= 2) {
00263       fout << endl;
00264       fout << "*************************************************" << endl;
00265       fout << "** Run # " << krun << " , Evt # " << kevt << "  --> " << endl;
00266       fout << "*************************************************" << endl;
00267     }
00268     // read the event from the BOS
00269     AlphaBanks bb(AlphaBanks::BOS);
00270     bb.InitObjectStructure();
00271     // the AlphaBanks will now be made persistant.
00272     ((AlephDbManager*)dbManager)->StoreEvent(&bb);
00273     // some status report
00274     if (! (EventCount % 1000))
00275       {
00276         fout << endl;
00277         fout << "******* " << EventCount << 
00278                 " events read " << endl;
00279         fout << "******* current Run # = " << krun << endl;
00280         fout << "******* current Evt # = " << kevt << endl;
00281         fout << endl;
00282       }
00284 // end main event loop
00286   } while (ier1 == 0);
00287   fout << endl;
00288   fout << " *** " << EventCount << " Events have been read and written to file." << endl;
00289   fout << endl;
00290   // stop the transaction
00291   AlephRC stopRC = epioMan->stopTransaction();
00292   if (debug >= 0)
00293   {
00294     fout << endl;
00295     fout << " ****** AlephEpioExManager::loopAllRead : transaction stopped ****** " << endl;
00296     fout << endl;
00297   }
00298   return stopRC;
00299 }
00300 
00302 // interactive loop
00304 AlephRC AlephEpioExManager::loopInter()
00305 {
00306   // check if user wants a reading or writing transaction
00307   // get it from the cards
00308   // first check if the IoManager is there
00309   AlephManager* ioManager = (AlephSession::TheAlephSession())->aAlephManager("IoManager");
00310   if (ioManager == NULL) 
00311     {
00312       fout << "  FATAL : AlephEpioExManager : there is no IoManager !! " << endl;
00313       return AlephERROR;
00314     }
00315   else
00316     {
00317       AlephStatus ioManStatus = ioManager->status();    
00318       if (ioManStatus != INITIALIZED) ioManager->initialize(); 
00319       // get the TATY card
00320       string transType = (((AlephIoManager*)ioManager)->theCardsReader()).getTaType();
00321       if (transType == "write")
00322         {         
00323           return loopInterWrite();
00324         }
00325       else
00326         {
00327           return loopInterRead();
00328         }
00329     }
00330 }
00331 
00333 // interactive reading loop
00335 AlephRC AlephEpioExManager::loopInterRead()
00336 {
00337   // for epio reading we just use default dbmanager
00338   AlephDbManager* epioMan = theDbm();
00339   // get the cards Reader
00340   AlephCardsReader& cardsReader = theIom()->theCardsReader();
00341   // start a read transaction if not already done
00342   // HTLs are needed, than start a writing transaction
00343   epioMan->startTransaction(READING);
00344   // get the debug level
00345   int debug = (AlephSession::TheAlephSession())->debugLevel();
00346   // instanciate the AlephInteractiveHandler
00347   AlephInteractiveHandler* Handler = AlephInteractiveHandler::TheAlephInteractiveHandler();
00348   int ier1=0;
00349   Handler->InitiateConnection(ier1);
00351 // main event loop
00353   int krun,kevt;
00354   EventCount = 0;
00355   while(!ier1)
00356   {
00357     READ_EVENT(krun,kevt,ier1);
00358     if (ier1 != 0) break;
00359     // set current Run and event numbers
00360     setCurrentRunEvt(krun,kevt);    
00361     EventCount++;
00362     if (debug >= 2) {
00363       fout << endl;
00364       fout << "*************************************************" << endl;
00365       fout << "** Run # " << krun << " , Evt # " << kevt << "  --> " << endl;
00366       fout << "*************************************************" << endl;
00367     }
00368     // prepare AlphaBanks for analysis
00369     AlphaBanks bb(AlphaBanks::BOS);
00370     bb.InitObjectStructure();
00371     if(!bb.isValid())
00372             fout << " AlephEpioExManager : inconsistency in event. Skipped " << endl;
00373     else
00374             if(UserEvent(bb)||Handler->KeepAllEvents()) 
00375             {
00376                     ier1 = Handler->HandleEvent(bb);
00377             }
00378     // some status report
00379     if (! (EventCount % 1000))
00380       {
00381         fout << endl;
00382         fout << "******* " << EventCount << 
00383                 " events read " << endl;
00384         fout << "******* current Run # = " << krun << endl;
00385         fout << "******* current Evt # = " << kevt << endl;
00386         fout << endl;
00387       }
00389 // end main event loop
00391   };
00392   Handler->CloseConnection();
00393   fout << endl;
00394   fout << " *** " << EventCount << " Events have been read" << endl;
00395   fout << endl;
00396 // stop the transaction
00397   AlephRC stopRC = epioMan->stopTransaction();
00398   if (debug >= 0)
00399   {
00400     fout << endl;
00401     fout << " ****** AlephEpioExManager::loopInterRead : transaction stopped ****** " << endl;
00402     fout << endl;
00403   }
00404   return stopRC;
00405 }
00406  
00408 // interactive writing loop
00410 AlephRC AlephEpioExManager::loopInterWrite()
00411 {
00412   fout << " in loopInterWrite : doing nothing for the moment ... " << endl;
00413   return AlephOK;
00414 }
00415 

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