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 "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
00027
00028 AlephEpioExManager::AlephEpioExManager()
00029 {
00030
00031 AlephManagerSetup("EpioExManager");
00032 fout << " An AlephEpioExManager has been created " << endl;
00033 }
00034
00035
00036
00037
00038 AlephEpioExManager::~AlephEpioExManager() {}
00039
00040
00041
00042
00043 AlephRC AlephEpioExManager::initialize()
00044 {
00045
00046 int debug = (AlephSession::TheAlephSession())->debugLevel();
00047
00048 fout << " AlephEpioExManager : initializing .... " << endl;
00049 fout << " AlephEpioExManager : Setting random generator seed to ";
00050
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
00059 theseed = (((AlephIoManager*)ioManager)->theCardsReader()).getSeed();
00060 }
00061 }
00062 fout << theseed << endl;
00063 sgenrand(theseed);
00064
00065 BOS_INITIALIZE();
00066 if (debug >= 0)
00067 {
00068 fout << endl;
00069 fout << " C bos_initialize CALLED ******* "<< endl;
00070 fout << endl;
00071 }
00072
00073 AlephRegisteredAction<GeneralEventInfo> code100;
00074 AlephRegisteredAction<CollectTracks> code200;
00075 AlephRegisteredAction<CollectLeptons> code300;
00076 AlephRegisteredAction<CollectJets> code400;
00077
00078 fout << " AlephEpioExManager : calling user init " << endl;
00079 UserInit();
00080 return AlephOK;
00081 }
00082
00083
00084
00085
00086 AlephRC AlephEpioExManager::terminate()
00087 {
00088
00089 fout << " AlephEpioExManager : terminating .... " << endl;
00090 fout << " AlephEpioExManager : calling user term " << endl;
00091 UserTerm();
00092
00093 CLOSE_RUN();
00094
00095 setStatus(TERMINATED);
00096 return AlephOK;
00097 }
00098
00099
00100
00101
00102 AlephRC AlephEpioExManager::run()
00103 {
00104
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
00114 AlephStatus dbManStatus = dbManager->status();
00115 if (dbManStatus != INITIALIZED) dbManager->initialize();
00116
00117 string sessionTy = (AlephSession::TheAlephSession())->sessionType();
00118
00119 fout << " The session type is " << sessionTy << endl;
00120 if (sessionTy == "BATCH")
00121 {
00122 AlephRC loopRC = loopAll();
00123 return loopRC;
00124 }
00125 else
00126 if (sessionTy == "INTER")
00127 {
00128
00129 AlephRC loopRC = loopInter();
00130 return loopRC;
00131 }
00132 else
00133 {
00134 fout << " FATAL : AlephEpioExManager : do not know this session Type !! " << endl;
00135 return AlephERROR;
00136 }
00137 }
00138 }
00139
00141
00143
00144 {
00145
00146
00147
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
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
00174
00175 {
00176
00177 AlephDbManager* epioMan = theDbm();
00178
00179 AlephCardsReader& cardsReader = theIom()->theCardsReader();
00180
00181
00182 epioMan->startTransaction(READING);
00183
00184 int debug = (AlephSession::TheAlephSession())->debugLevel();
00186
00188
00189 EventCount = 0;
00190 do {
00191 READ_EVENT(krun,kevt,ier1);
00192 if (ier1 != 0) break;
00193
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
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
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
00222
00223 fout << endl;
00224 fout << " *** " << EventCount << " Events have been read" << endl;
00225 fout << endl;
00226
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
00240
00241 {
00242
00243 AlephDbManager* epioMan = theDbm();
00244
00245 AlephCardsReader& cardsReader = theIom()->theCardsReader();
00246
00247 epioMan->startTransaction(READING);
00248
00249 int debug = (AlephSession::TheAlephSession())->debugLevel();
00251
00253
00254 EventCount = 0;
00255 AlephManager* dbManager = (AlephSession::TheAlephSession())->aAlephManager("DbManager");
00256 do {
00257 READ_EVENT(krun,kevt,ier1);
00258 if (ier1 != 0) break;
00259
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
00269 AlphaBanks bb(AlphaBanks::BOS);
00270 bb.InitObjectStructure();
00271
00272 ((AlephDbManager*)dbManager)->StoreEvent(&bb);
00273
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
00286
00287 fout << endl;
00288 fout << " *** " << EventCount << " Events have been read and written to file." << endl;
00289 fout << endl;
00290
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
00304
00305 {
00306
00307
00308
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
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
00335
00336 {
00337
00338 AlephDbManager* epioMan = theDbm();
00339
00340 AlephCardsReader& cardsReader = theIom()->theCardsReader();
00341
00342
00343 epioMan->startTransaction(READING);
00344
00345 int debug = (AlephSession::TheAlephSession())->debugLevel();
00346
00347 AlephInteractiveHandler* Handler = AlephInteractiveHandler::TheAlephInteractiveHandler();
00348 int ier1=0;
00349 Handler->InitiateConnection(ier1);
00351
00353
00354 EventCount = 0;
00355 while(!ier1)
00356 {
00357 READ_EVENT(krun,kevt,ier1);
00358 if (ier1 != 0) break;
00359
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
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
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
00391
00392 Handler->CloseConnection();
00393 fout << endl;
00394 fout << " *** " << EventCount << " Events have been read" << endl;
00395 fout << endl;
00396
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
00410
00411 {
00412 fout << " in loopInterWrite : doing nothing for the moment ... " << endl;
00413 return AlephOK;
00414 }
00415