00001
00002
00003
00004
00005
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
00027
00028 AlephROOTExManager::AlephROOTExManager()
00029 {
00030
00031 AlephManagerSetup("ROOTExManager");
00032 fout << " An AlephROOTExManager has been created " << endl;
00033 }
00034
00035
00036
00037
00038 AlephROOTExManager::~AlephROOTExManager() {}
00039
00040
00041
00042
00043 AlephRC AlephROOTExManager::initialize()
00044 {
00045
00046 int debug = (AlephSession::TheAlephSession())->debugLevel();
00047
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
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
00062 theseed = (((AlephIoManager*)ioManager)->theCardsReader()).getSeed();
00063 }
00064 }
00065 fout << theseed << endl;
00066 sgenrand(theseed);
00067
00068 AlephRegisteredAction<GeneralEventInfo> code100;
00069 AlephRegisteredAction<CollectTracks> code200;
00070 AlephRegisteredAction<CollectLeptons> code300;
00071 AlephRegisteredAction<CollectJets> code400;
00072
00073 fout << " AlephROOTExManager : calling user init " << endl;
00074 UserInit();
00075 return AlephOK;
00076 }
00077
00078
00079
00080
00081 AlephRC AlephROOTExManager::terminate()
00082 {
00083
00084 fout << " AlephROOTExManager : terminating .... " << endl;
00085 fout << " AlephROOTExManager : calling user term " << endl;
00086 UserTerm();
00087
00088 setStatus(TERMINATED);
00089 return AlephOK;
00090 }
00091
00092
00093
00094
00095 AlephRC AlephROOTExManager::run()
00096 {
00097
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
00107 AlephStatus dbManStatus = dbManager->status();
00108 if (dbManStatus != INITIALIZED) dbManager->initialize();
00109
00110 string sessionTy = (AlephSession::TheAlephSession())->sessionType();
00111
00112 fout << " The session type is " << sessionTy << endl;
00113 if (sessionTy == "BATCH")
00114 {
00115 AlephRC loopRC = loopAll();
00116 return loopRC;
00117 }
00118 else
00119 if (sessionTy == "INTER")
00120 {
00121
00122 AlephRC loopRC = loopInter();
00123 return loopRC;
00124 }
00125 else
00126 {
00127 fout << " FATAL : AlephROOTExManager : do not know this session Type !! " << endl;
00128 return AlephERROR;
00129 }
00130 }
00131 }
00132
00134
00136
00137 {
00138
00139
00140
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
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
00167
00168 {
00169
00170 AlephDbManager* rootMan = theDbm();
00171
00172 rootMan->startTransaction(READING);
00173
00174 int debug = (AlephSession::TheAlephSession())->debugLevel();
00176
00178
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
00193 bb->InitObjectStructure();
00194 if(!bb->isValid())
00195 fout << " AlephROOTExManager : inconsistency in event. Skipped " << endl;
00196 else
00197 UserEvent(*bb);
00198
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
00211
00212 fout << endl;
00213 fout << " *** " << EventCount << " Events have been read" << endl;
00214 fout << endl;
00215
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
00229
00230 {
00231 fout << " in loopInterWrite : doing nothing for the moment ... " << endl;
00232 return AlephOK;
00233 }
00234
00236
00238
00239 {
00240
00241
00242
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
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
00269
00270 {
00271
00272 AlephDbManager* rootMan = theDbm();
00273
00274 rootMan->startTransaction(READING);
00275
00276 int debug = (AlephSession::TheAlephSession())->debugLevel();
00277
00278 AlephInteractiveHandler* Handler = AlephInteractiveHandler::TheAlephInteractiveHandler();
00279 int ier1=0;
00280 Handler->InitiateConnection(ier1);
00282
00284
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
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
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
00320
00321 Handler->CloseConnection();
00322 fout << endl;
00323 fout << " *** " << EventCount << " Events have been read" << endl;
00324 fout << endl;
00325
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
00339
00340 {
00341 fout << " in loopInterWrite : doing nothing for the moment ... " << endl;
00342 return AlephOK;
00343 }
00344