00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00063 #include "iostream.h"
00064
00065 class StChain;
00066 StChain *chain=0;
00067 class St_db_Maker;
00068 St_db_Maker *dbMk =0;
00069 class StFileI;
00070 StFileI *setFiles =0;
00071 TString mainBranch;
00072
00073 Int_t iEvt=0,istat=0;
00074
00075 void doEvents()
00076 {
00077 cout << "Usage: doEvents.C(2) // work with default event.root file" << endl;
00078 cout << " doEvents.C(startEvent, nEvents,\"path/somefile.event.root\")" << endl;
00079 cout << " doEvents.C(nEvents, \"path/*.event.root\")" << endl;
00080 cout << " doEvents.C(nEvents, \"path/file.dst.root\", \"evout\") //Write out StEvent" << endl;
00081 cout << " doEvents.C(nEvents, \"path/file.dst.root\", \"display\") //EventDispay" << endl;
00082 cout << " doEvents.C(nEvents, \"path/file.dst.root\", \"dbon\") //DB on" << endl;
00083 cout << " doEvents.C(nEvents, \"@file.lis\") //list of files in file.lis " << endl;
00084 cout << " doEvents.C(nEvents, \"SELECT MuDST WHERE production=P04ih and zdc1Energy>50\", \"gc\") //GridCollector selects MuDST.root files " << endl;
00085 cout << " doEvents.C(nEvents, \"SELECT event WHERE production=P04ih and zdc1Energy>50\", \"gc\") //GridCollector selects event.root files" << endl;
00086 cout << " doEvents.C(nEvents, \"@GridCollector_commands.txt\", \"gc,evout\") //GridCollector commands in file" << endl;
00087 }
00088
00089
00090
00091
00092 void doEvents(Int_t nEvents, const char ** fileList, const char *qaflag =0);
00093 void doEvents(Int_t startEvent, Int_t nEvents, const char ** fileList, const char *qaflag =0);
00094
00095 void doEvents(Int_t nEvents,
00096 const char *file="/afs/rhic.bnl.gov/star/data/samples/example.event.root",
00097 const char *qaflag = 0);
00098
00099 void doEvents(Int_t startEvent,Int_t nEvents,
00100 const char *file="/afs/rhic.bnl.gov/star/data/samples/example.event.root",
00101 const char *qaflag = 0);
00102
00103 void doEvents(Int_t nEvents,
00104 const char *path,
00105 const char *file,
00106 const char *qaflag, int flag);
00107
00108 void loadLibs(const char *opt);
00109 int gcInit (const char *request);
00110
00111
00112
00113 void doEvents(Int_t startEvent, Int_t nEventsQQ, const char **fileList, const char *qaflag)
00114 {
00115
00116 if (!qaflag) qaflag = "";
00117 int nEvents = nEventsQQ;
00118 int eventNumber2Display = 0;
00119 TString tflag = qaflag; tflag.ToLower();
00120 int eventDisplay = tflag.Contains("disp");
00121 if (eventDisplay) {
00122 if (gROOT->IsBatch() )
00123 {
00124 cout << endl << endl <<" ** Warning ** You have started the EventDisplay version in a batch mode" << endl;
00125 return;
00126 }
00127 TObjArray *tokens = tflag.Tokenize(":");
00128 if ( tokens->GetEntries() >= 2 ) {
00129
00130 TString eventid = (tokens->At(tokens->GetEntries()-1))->GetName();
00131 if ( eventid.IsDigit() )
00132 eventNumber2Display = eventid.Atoi();
00133 }
00134 delete tokens;
00135 }
00136 cout << endl << endl <<" doEvents - input # events = " << nEvents << endl;
00137 Int_t ilist=0;
00138 while(fileList[ilist]){
00139 cout << " doEvents - input fileList = " << fileList[ilist] << endl;
00140 ilist++;
00141 }
00142 cout << " doEvents - input qaflag = " << qaflag << endl;
00143
00144
00145
00146 loadLibs("");
00147
00148
00149
00150 if (tflag.Contains("dbon")) {
00151 loadLibs("dbon");
00152 }
00153
00154
00155 if (eventDisplay) {
00156 loadLibs("disp");
00157 }
00158
00159 StMuDebug::setLevel(0);
00160
00161 chain = new StChain("StChain");
00162 setFiles =0;
00163
00164 if (tflag.Contains("gc")) {
00165 int nev = gcInit(fileList[0]);
00166 if (nev<=0) return;
00167 if (nEvents <= 0) nEvents = nev;
00168 } else {
00169 setFiles = new StFile(fileList);
00170 char line[999]; strcpy(line,fileList[0]);
00171 if (*line=='@') {
00172 TString command("grep '.root' "); command += line+1;
00173 FILE *pipe = gSystem->OpenPipe(command.Data(),"r");
00174 if (pipe) {fgets(line,999,pipe);line[strlen(line)-1] = 0;}
00175 fclose(pipe);
00176 }
00177 mainBranch = line;
00178
00179 mainBranch.ReplaceAll(".root","");
00180 int idot = strrchr((char*)mainBranch,'.') - mainBranch.Data();
00181 mainBranch.Replace(0,idot+1,"");
00182 mainBranch += "Branch";
00183 }
00184
00185
00186 if (eventDisplay) {
00187 int NwGeant=5000000, IwType=0, NwPaw=0;
00188 St_geant_Maker *geantMk = new St_geant_Maker("geant",NwGeant,NwPaw,IwType);
00189 geantMk->LoadGeometry("detp geometry y2004");
00190 geantMk->SetActive(kFALSE);
00191 }
00192
00193
00194 if (!mainBranch.IsNull()) {
00195 printf("*** mainBranch=%s ***\n",mainBranch.Data());
00196 }
00197
00198
00199
00200
00201
00202 StIOMaker *IOMk = new StIOMaker("IO","r",setFiles,"bfcTree");
00203 IOMk->SetIOMode("r");
00204 IOMk->SetBranch("*",0,"0");
00205 if(!mainBranch.IsNull()) IOMk->SetBranch(mainBranch,0,"r");
00206 IOMk->SetBranch("evtselBranch",0,"r");
00207
00208
00209 IOMk->SetDebug(1);
00210
00211
00212
00213 if (tflag.Contains("dbon")) {
00214 dbMk = new St_db_Maker("db","MySQL:StarDb","$STAR/StarDb","StarDb");
00215 }
00216
00217
00218 if (!mainBranch.Contains("mudstBranch") &&
00219 mainBranch.Contains("dstBranch")) {
00220 gSystem->Load("libStMagF");
00221 gSystem->Load("StDetectorDbMaker");
00222 gSystem->Load("StTpcDb");
00223 gSystem->Load("StEventMaker");
00224 new StMagFMaker;
00225 StEventMaker *readerMaker = new StEventMaker("events","title");
00226 }
00227
00228 StAnalysisMaker *analysisMaker = new StAnalysisMaker("analysis");
00229
00230
00231
00232
00234
00235
00236
00237
00238
00240
00241
00242 Int_t wrStEOut = tflag.Contains("evout");
00243 if (wrStEOut) {
00244 cout << "!!!! doEvents: will write out .event.root file !!" << endl << endl;
00245 StIOMaker *outMk = new StIOMaker("EvOut","w","test.event.root","bfcTree");
00246
00247 outMk->IntoBranch("evtselBranch","StEvent");
00248 IOMk->SetNotify("CloseFile",outMk);
00249 IOMk->SetNotify("OpenFile" ,outMk);
00250 }
00251
00252
00253
00254 if (eventDisplay) {
00255
00256 StEventDisplayMaker *displayMk = new StEventDisplayMaker();
00257 displayMk->SetEventIdToRender(eventNumber2Display);
00258 if (eventNumber2Display)
00259 printf("\n\n\n Display the Event %d only\n", eventNumber2Display);
00260
00261 displayMk->AddName("StEvent(Primary Tracks)");
00262
00263
00264
00265
00266
00267 displayMk->AddFilter(new StFilterDef("MainFilter"));
00268 displayMk->AddFilter(new StMuDstFilterHelper("MuL3Filter",kFALSE));
00269 displayMk->AddFilter(new StColorFilterHelper("Color schema",kFALSE));
00270
00271 if (!gSystem->Load("StCustomFilter")) {
00272 displayMk->AddFilter(new StCustomFilter("Custom filter",kFALSE));
00273 }
00274
00275 }
00276
00277
00278 cout << "----------------------------------------------------------" << endl;
00279 cout << " doEvents - Initializing and Printing chain information " << endl;
00280 Int_t iInit = chain->Init();
00281 if (iInit) chain->Fatal(iInit,"on init");
00282 chain->PrintInfo();
00283 cout << "----------------------------------------------------------" << endl << endl;
00284
00285
00286
00287 if (startEvent > 1) IOMk->Skip(startEvent-1);
00288
00289
00290 istat=0,iEvt=1;
00291 istat = chain->EventLoop(1,nEvents);
00292
00293
00294
00295 }
00296
00297 void doEvents(Int_t startEvent, Int_t nEvents, const char *file, const char *qaflag)
00298 {
00299 if (!qaflag) qaflag="";
00300 printf("*file = %s\n",file);
00301 const char *fileListQQ[]={0,0};
00302 fileListQQ[0]=file;
00303 cout << "Calling (startEvent,nEvents,fileListQQ,qaflag)" << endl;
00304 doEvents(startEvent,nEvents,fileListQQ,qaflag);
00305 }
00306
00307 void doEvents(Int_t nEvents, const char *file, const char *qaflag)
00308 {
00309 if (!qaflag) qaflag="";
00310 cout << "Calling (1,nEvents,file,qaflag)" << endl;
00311 doEvents(1,nEvents,file,qaflag);
00312 }
00313
00314
00315 void doEvents(Int_t nEvents, const char *path,const char *file, const char *qaflag, int flag)
00316 {
00317 if (!qaflag) qaflag="";
00318 TString F;
00319 if (path && path[0] && path[0]!='-') F = path;
00320 if (file && file[0] && file[0]!='-') {
00321 if (!F.IsNull()) F +="/";
00322 F += file;
00323 }
00324 TString opt = qaflag;
00325 if (flag) opt += " evout";
00326
00327 cout << "Calling (1,nEvents,F.Data(),opt.Data())" << endl;
00328 doEvents(1,nEvents,F.Data(),opt.Data());
00329 }
00330
00331
00332 void doEvents(Int_t nEvents, const char **fileList, const char *qaflag)
00333 {
00334 cout << "Calling (1,nEvents,fileList,qaflag)" << endl;
00335 doEvents(1,nEvents,fileList,qaflag);
00336 }
00337
00338 void loadLibs(const char *opt)
00339 {
00340
00341
00342 if (!opt[0]) {
00343
00344 gSystem->Load("libPhysics");
00345 gSystem->Load("libTable");
00346 gSystem->Load("libGeom");
00347
00348
00349 gSystem->Load("St_base");
00350 gSystem->Load("StChain");
00351 gSystem->Load("St_Tables");
00352 gSystem->Load("StUtilities");
00353 gSystem->Load("StTreeMaker");
00354 gSystem->Load("StIOMaker");
00355 gSystem->Load("StarClassLibrary");
00356 gSystem->Load("StTriggerDataMaker");
00357 gSystem->Load("StBichsel");
00358 gSystem->Load("StEvent");
00359 gSystem->Load("StEventUtilities");
00360 gSystem->Load("StEmcUtil");
00361 gSystem->Load("StTofUtil");
00362 gSystem->Load("StPmdUtil");
00363 gSystem->Load("StPreEclMaker");
00364 gSystem->Load("StStrangeMuDstMaker");
00365 gSystem->Load("StMuDSTMaker");
00366 gSystem->Load("StarMagField");
00367 gSystem->Load("StMagF");
00368 gSystem->Load("StAnalysisMaker");
00369 gSystem->Load("StMuAnalysisMaker");
00370 cout << " loading of shared libraries done" << endl;
00371 return;
00372 }
00373 if (strstr(opt,"dbon")) {
00374 gSystem->Load("StDbLib.so");
00375 gSystem->Load("StDbBroker.so");
00376 gSystem->Load("libStDb_Tables.so");
00377 gSystem->Load("St_db_Maker.so");
00378 gSystem->Load("StTpcDb");
00379 gSystem->Load("StDetectorDbMaker");
00380 }
00381
00382 if (strstr(opt,"disp")) {
00383 gSystem->Load("St_g2t");
00384 gSystem->Load("geometry");
00385 gSystem->Load("St_geant_Maker");
00386 gSystem->Load("StTableUtilities");
00387 gSystem->Load("StEventDisplayMaker");
00388 }
00389 }
00390
00391
00392
00393 int gcReadCommands(const char *file, TString& cmds)
00394 {
00395 if (*file != 0) {
00396 FILE *inp = 0;
00397 inp = fopen(file, "r");
00398 if (!inp) {
00399 printf("doEvents: ERROR. File Not Found // %s\n",req+1);
00400 return -1;
00401 }
00402
00403 char line[500], *comm, *fst;
00404 while(fgets(line, 500, inp)) {
00405 for (int i=0; line[i]; i++)
00406 if (line[i]=='\t' || line[i]=='\n') line[i]=' ';
00407
00408 fst = line + strspn(line," \t");
00409 if (fst[0] == 0 ) continue;
00410 if (fst[0] =='#') continue;
00411 if (strncmp(fst,"//",2)==0 ) continue;
00412
00413 comm = strstr(line," //"); if (comm) comm[0]=0;
00414 cmds += fst;
00415 }
00416 fclose(inp);
00417 }
00418
00419 return 0;
00420 }
00421
00422
00423
00424 int gcInit(const char *request)
00425 {
00426 Int_t ierr = 0;
00427 gSystem->Load("StGridCollector");
00428 StGridCollector *req = StGridCollector::Create();
00429 req->SetDebug(1);
00430
00431 if (request == 0 || *request == 0) {
00432
00433
00434 const char *argv[] = {
00435 "-v", "5",
00436 "-c", "/afs/rhic.bnl.gov/star/incoming/GCA/gca.rc"
00437 "-s", "MuDST",
00438 "-w", "production=P04ih and zdc1Energy>50"
00439 };
00440 const Int_t argc = sizeof(argv)/4;
00441 ierr = req->Init(argc, argv);
00442 if (0 != ierr) {
00443 std::cout << "doEvents.C can not initialize the Grid Collector "
00444 << "with argument \"";
00445 std::cout << *argv;
00446 for (Int_t i = 1; i < argc; ++ i)
00447 std::cout << " " << argv[i];
00448 std::cout << "\"\nError code is " << ierr
00449 << std::endl;
00450 }
00451 }
00452 else if (*request == '@') {
00453 TString cmds;
00454 ierr = gcReadCommands(request+1, cmds);
00455 if (!ierr) ierr = req->Init(cmds.Data());
00456 if (0 != ierr) {
00457 std::cout << "doEvents.C can not initialize the Grid Collector "
00458 << "with argument \"" << cmds.Data()
00459 << "\"\nError code is " << ierr
00460 << std::endl;
00461 }
00462 }
00463 else {
00464 ierr = req->Init(request);
00465 if (0 != ierr) {
00466 std::cout << "doEvents.C can not initialize the Grid Collector "
00467 << "with argument \"" << request
00468 << "\"\nError code is " << ierr
00469 << std::endl;
00470 }
00471 }
00472
00473 if (0 != ierr) {
00474 ierr = 0;
00475 }
00476 else {
00477 int nEvents = req->GetNEvents();
00478 std::cout << "INFO: actual number of events " << nEvents << std::endl;
00479 setFiles = req;
00480 mainBranch = req->GetCompName();
00481 mainBranch += "Branch";
00482 ierr = nEvents;
00483 }
00484 return ierr;
00485 }
00486
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649