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

AlephROOTExManager.cpp

Go to the documentation of this file.
00001 
00002 //
00003 //  Implementation of class AlephROOTExManager
00004 //
00005 //  Author : G. Dissertori  ,  15.08.2002
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 "AlephROOTExManager.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 AlephROOTExManager::AlephROOTExManager()
00029 {
00030   // call the constructor of the base class
00031   AlephManagerSetup("ROOTExManager");
00032   fout << " An AlephROOTExManager has been created " << endl;
00033 }
00034 
00035 //
00036 // the destructor
00037 //
00038 AlephROOTExManager::~AlephROOTExManager() {}
00039 
00040 //
00041 // the initialization step
00042 //
00043 AlephRC AlephROOTExManager::initialize()
00044 {
00045   // get debug level
00046   int debug = (AlephSession::TheAlephSession())->debugLevel();
00047   // say something
00048   fout << " AlephROOTExManager :  initializing .... " << endl << endl;;
00049   fout << " WARNING: BOS structure will NOT be loaded." << endl;
00050   fout << " Methods wrapping Fortran ARE NOT AVAILABLE and WILL CRASH the code... " << endl;
00051   fout << " When writing those lines, this includes b-tagging and kinematical fit." << endl;
00052   // first check is the IoManager is there 
00053   fout << " AlephROOTExManager :  Setting random generator seed to ";
00054   AlephManager* ioManager = (AlephSession::TheAlephSession())->aAlephManager("IoManager");
00055   unsigned long theseed = 1;
00056   if (ioManager != NULL)
00057     {
00058       AlephStatus ioManStatus = ioManager->status();
00059       if (ioManStatus == INITIALIZED)
00060        {
00061         // get the SEED card (if not, there is an unknown value)
00062         theseed = (((AlephIoManager*)ioManager)->theCardsReader()).getSeed();
00063        }
00064     }
00065   fout << theseed << endl;
00066   sgenrand(theseed);
00067   // initialisation of default interactive functions
00068   AlephRegisteredAction<GeneralEventInfo> code100;
00069   AlephRegisteredAction<CollectTracks> code200;
00070   AlephRegisteredAction<CollectLeptons> code300;
00071   AlephRegisteredAction<CollectJets> code400;
00072   // User Initialization
00073   fout << " AlephROOTExManager :  calling user init " << endl;
00074   UserInit();
00075   return AlephOK;
00076 }
00077 
00078 //
00079 // the termination step
00080 //
00081 AlephRC AlephROOTExManager::terminate()
00082 {
00083   // say something
00084   fout << " AlephROOTExManager :  terminating .... " << endl;
00085   fout << " AlephROOTExManager :  calling user term " << endl;
00086   UserTerm();
00087   // set the status
00088   setStatus(TERMINATED); 
00089   return AlephOK;
00090 }
00091 
00092 //
00093 // the running step
00094 //
00095 AlephRC AlephROOTExManager::run()
00096 {
00097   // check first if the database manager is up
00098   AlephManager* dbManager = (AlephSession::TheAlephSession())->aAlephManager("DbManager");
00099   if (dbManager == NULL)
00100     {
00101       fout << " FATAL : AlephROOTExManager : there is NO DbManager !! " << endl;
00102       return AlephERROR;
00103     }
00104   else
00105     {
00106       // check if it is initialized
00107       AlephStatus dbManStatus = dbManager->status();
00108       if (dbManStatus != INITIALIZED) dbManager->initialize(); 
00109       // check the session type
00110       string sessionTy = (AlephSession::TheAlephSession())->sessionType();
00111       // if it is batch, call the loop function
00112       fout << " The session type is " << sessionTy << endl;
00113       if (sessionTy == "BATCH") 
00114         {
00115           AlephRC  loopRC = loopAll();
00116           return loopRC;
00117         }
00118       else // else do interactive stuff
00119       if (sessionTy  == "INTER")
00120         {
00121           // call next user request
00122           AlephRC  loopRC = loopInter();
00123           return loopRC;
00124         }
00125       else  // do nothing
00126         {
00127           fout << "  FATAL : AlephROOTExManager : do not know this session Type !! " << endl;
00128           return AlephERROR;
00129         }
00130     }
00131 }
00132 
00134 // batch loop
00136 AlephRC AlephROOTExManager::loopAll()
00137 {
00138   // check if user wants a reading or writing transaction
00139   // get it from the cards
00140   // first check if the IoManager is there
00141   AlephManager* ioManager = (AlephSession::TheAlephSession())->aAlephManager("IoManager");
00142   if (ioManager == NULL) 
00143     {
00144       fout << "  FATAL : AlephROOTExManager : there is no IoManager !! " << endl;
00145       return AlephERROR;
00146     }
00147   else
00148     {
00149       AlephStatus ioManStatus = ioManager->status();    
00150       if (ioManStatus != INITIALIZED) ioManager->initialize();
00151       // get the TATY card
00152       string transType = (((AlephIoManager*)ioManager)->theCardsReader()).getTaType();
00153       if (transType == "write")
00154         {         
00155           return loopAllWrite();
00156         }
00157       else
00158         {
00159           return loopAllRead();
00160         }
00161     }
00162 }
00163 
00165 // batch reading loop
00167 AlephRC AlephROOTExManager::loopAllRead()
00168 {
00169   // get the db manager
00170   AlephDbManager* rootMan = theDbm();
00171   // start a read transaction if not already done
00172   rootMan->startTransaction(READING);
00173   // get the debug level
00174   int debug = (AlephSession::TheAlephSession())->debugLevel();
00176 // main event loop
00178   int ier1;
00179   EventCount = 0;
00180   do {
00181     AlphaBanks *bb = new AlphaBanks(AlphaBanks::ROOT);
00182     ier1 = rootMan->GetEvent(bb)-1;
00183     if (ier1 != 0) { delete bb; break; }
00184     EventCount++;
00185     if (debug >= 2) 
00186     {
00187       fout << endl;
00188       fout << "*************************************************" << endl;
00189       fout << "** Run # " << getCurrentRun() << " , Evt # " << getCurrentEvt() << "  --> " << endl;
00190       fout << "*************************************************" << endl;
00191     }
00192     // prepare AlphaBanks for analysis
00193     bb->InitObjectStructure();
00194     if(!bb->isValid())
00195             fout << " AlephROOTExManager : inconsistency in event. Skipped " << endl;
00196     else
00197             UserEvent(*bb);
00198     // some status report
00199     if (! (EventCount % 1000))
00200       {
00201         fout << endl;
00202         fout << "******* " << EventCount << " events read " << endl;
00203         fout << "******* current Run # = " << getCurrentRun() << endl;
00204         fout << "******* current Evt # = " << getCurrentEvt() << endl;
00205         fout << endl;
00206       }
00207     delete bb;
00209 // end main event loop
00211   } while (ier1 == 0);
00212   fout << endl;
00213   fout << " *** " << EventCount << " Events have been read" << endl;
00214   fout << endl;
00215   // stop the transaction
00216   AlephRC stopRC = rootMan->stopTransaction();
00217   if (debug >= 0)
00218   {
00219     fout << endl;
00220     fout << " ****** AlephROOTExManager::loopAllRead : transaction stopped ****** " << endl;
00221     fout << endl;
00222   }
00223   return stopRC;
00224 }
00225  
00227 // batch writing loop
00229 AlephRC AlephROOTExManager::loopAllWrite()
00230 {
00231   fout << " in loopInterWrite : doing nothing for the moment ... " << endl;
00232   return AlephOK;
00233 }
00234 
00236 // interactive loop
00238 AlephRC AlephROOTExManager::loopInter()
00239 {
00240   // check if user wants a reading or writing transaction
00241   // get it from the cards
00242   // first check if the IoManager is there
00243   AlephManager* ioManager = (AlephSession::TheAlephSession())->aAlephManager("IoManager");
00244   if (ioManager == NULL) 
00245     {
00246       fout << "  FATAL : AlephROOTExManager : there is no IoManager !! " << endl;
00247       return AlephERROR;
00248     }
00249   else
00250     {
00251       AlephStatus ioManStatus = ioManager->status();    
00252       if (ioManStatus != INITIALIZED) ioManager->initialize(); 
00253       // get the TATY card
00254       string transType = (((AlephIoManager*)ioManager)->theCardsReader()).getTaType();
00255       if (transType == "write")
00256         {         
00257           return loopInterWrite();
00258         }
00259       else
00260         {
00261           return loopInterRead();
00262         }
00263     }
00264 }
00265 
00267 // interactive reading loop
00269 AlephRC AlephROOTExManager::loopInterRead()
00270 {
00271   // get the db manager
00272   AlephDbManager* rootMan = theDbm();
00273   // start a read transaction if not already done
00274   rootMan->startTransaction(READING);
00275   // get the debug level
00276   int debug = (AlephSession::TheAlephSession())->debugLevel();
00277   // instanciate the AlephInteractiveHandler
00278   AlephInteractiveHandler* Handler = AlephInteractiveHandler::TheAlephInteractiveHandler();
00279   int ier1=0;
00280   Handler->InitiateConnection(ier1);
00282 // main event loop
00284   EventCount = 0;
00285   while(!ier1)
00286   {
00287     AlphaBanks *bb = new AlphaBanks(AlphaBanks::ROOT);
00288     ier1 = rootMan->GetEvent(bb);
00289     if (ier1 != 0) { delete bb; break; }
00290     EventCount++;
00291     if (debug >= 2) {
00292       fout << endl;
00293       fout << "*************************************************" << endl;
00294       fout << "** Run # " << getCurrentRun() << " , Evt # " << getCurrentEvt() << "  --> " << endl;
00295       fout << "*************************************************" << endl;
00296     }
00297     // prepare AlphaBanks for analysis
00298     bb->InitObjectStructure();
00299     if(!bb->isValid())
00300             fout << " AlephROOTExManager : inconsistency in event. Skipped " << endl;
00301     else
00302             if(UserEvent(*bb)||Handler->KeepAllEvents()) 
00303             {
00304                     ier1 = Handler->HandleEvent(*bb);
00305             }
00306     // some status report
00307     if (! (EventCount % 1000))
00308       {
00309         fout << endl;
00310         fout << "******* " << EventCount << 
00311                 " events read " << endl;
00312         fout << "******* current Run # = " << getCurrentRun() << endl;
00313         fout << "******* current Evt # = " << getCurrentEvt() << endl;
00314         fout << endl;
00315       }
00316     delete bb;
00318 // end main event loop
00320   };
00321   Handler->CloseConnection();
00322   fout << endl;
00323   fout << " *** " << EventCount << " Events have been read" << endl;
00324   fout << endl;
00325 // stop the transaction
00326   AlephRC stopRC = rootMan->stopTransaction();
00327   if (debug >= 0)
00328   {
00329     fout << endl;
00330     fout << " ****** AlephROOTExManager::loopInterRead : transaction stopped ****** " << endl;
00331     fout << endl;
00332   }
00333   return stopRC;
00334 }
00335  
00337 // interactive writing loop
00339 AlephRC AlephROOTExManager::loopInterWrite()
00340 {
00341   fout << " in loopInterWrite : doing nothing for the moment ... " << endl;
00342   return AlephOK;
00343 }
00344 

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