3#include "FairRootManager.h"
42 file = gzopen(fileName, mode);
62 int ret = gzclose(file);
74 return gzputs(file, s);
84 return gzgets(file, buf, len);
94 return gzread(file, buf, len);
102 return gzwrite(file, buf, len);
123 return gzseek(file, pos, SEEK_SET);
125 return gzseek(file, pos, SEEK_CUR);
127 return gzseek(file, pos, SEEK_END);
148 string file_path = filename;
149 TString strFilePath(file_path);
150 gSystem->ExpandPathName(strFilePath);
151 if (gSystem->AccessPathName(strFilePath.Data()) ==
true) {
153 cout <<
"GetNumEvents ERROR: No generator file was found: " << strFilePath << endl;
158 int ret_code = libz->
open(
"rb");
161 cout <<
"GetNumPHSDEvents ERROR while opening file: " << filename << endl;
170 while (!libz->
eof()) {
171 libz->
gets(fbuffer, 256);
175 int res = sscanf(fbuffer,
"%d %*d %*d %e", &fntr, &fb);
178 printf(
"GetNumPHSDEvents ERROR: selftest error in header, scan %d of 2\n", res);
182 libz->
gets(fbuffer, 256);
185 printf(
"GetNumPHSDEvents ERROR: unexpected end of file\n");
189 for (Int_t
i = 1;
i <= fntr;
i++) {
191 libz->
gets(fbuffer, 256);
194 printf(
"GetNumPHSDEvents ERROR: unexpected end of file\n");
206 cout <<
"The total number of events in the PHSD file will be processed - " << num << endl;
211bool MpdGetNumEvents::GetQGSMEventHeader(
char* ss,
MpdLibZ* libz, Int_t& fQGSM_format_ID,
int iVerbose)
220 bool wrong_file =
false;
223 if (tss.Contains(
"QGSM"))
228 while (!(tss.Contains(
"particles, b,bx,by"))) {
229 if (tss.Contains(
"QGSM format ID")) {
230 sscanf(ss,
"QGSM format ID=%d", &fQGSM_format_ID);
233 if (fQGSM_format_ID == 2) {
234 off_t file_pos = libz->
tell();
235 for (
int k = 0; k < 5; k++)
241 libz->
seek(file_pos, SEEK_SET);
249 if ((fQGSM_format_ID >= 2) && (lines >= 4))
258 if (fQGSM_format_ID >= 2)
261 if (!tss.Contains(
"particles, b,bx,by")) {
269 cout <<
"GetQGSMEventHeader ERROR: Wrong file header! 1 " << endl;
275 if (!tss.Contains(
"event")) {
276 if (fQGSM_format_ID >= 2)
280 cout <<
"GetQGSMEventHeader ERROR: Wrong event header! 2 " << endl;
282 printf(
"Format id:%d \n %s \n", fQGSM_format_ID, ss);
290 switch (fQGSM_format_ID) {
293 libz->
gets(tmp, 250);
313 string file_path = filename;
314 TString strFilePath(file_path);
315 gSystem->ExpandPathName(strFilePath);
316 if (gSystem->AccessPathName(strFilePath.Data()) ==
true) {
318 cout <<
"GetNumEvents ERROR: No generator file was found: " << strFilePath << endl;
322 Int_t fQGSM_format_ID = 0;
324 int ret_code = libz->
open(
"rb");
327 cout <<
"GetNumQGSMEvents ERROR while opening file: " << filename << endl;
333 Int_t eventId = 0, nTracks = 0, num = 0;
335 while (GetQGSMEventHeader(ss, libz, fQGSM_format_ID, iVerbose)) {
340 sscanf(ss,
" %d %d", &eventId, &nTracks);
342 for (Int_t itrack = 0; itrack < nTracks; itrack++)
350 cout <<
"The total number of events in the QGSM file will be processed - " << num << endl;
359 string file_path = filename;
360 TString strFilePath(file_path);
361 gSystem->ExpandPathName(strFilePath);
362 if (gSystem->AccessPathName(strFilePath.Data()) ==
true) {
364 cout <<
"GetNumEvents ERROR: No generator file was found: " << strFilePath << endl;
369 int ret_code = libz->
open(
"rb");
372 cout <<
"GetNumURQMDEvents ERROR: Failure of opening file: " << filename << endl;
377 int ntracks, num = 0;
378 while (!libz->
eof()) {
380 libz->
gets(read, 200);
381 Int_t urqmdVersion = 0;
382 sscanf(read,
"UQMD version: %d 1000 %d output_file 14", &urqmdVersion, &urqmdVersion);
389 if (read[0] !=
'U') {
391 cout <<
"GetNumURQMDEvents ERROR: Wrong event header!" << endl;
396 for (
int iline = 0; iline < ((urqmdVersion == 30400) ? 16 : 13); iline++)
397 libz->
gets(read, 200);
399 libz->
gets(read, 200);
400 sscanf(read,
"%d", &ntracks);
401 libz->
gets(read, 200);
403 for (
int itrack = 0; itrack < ntracks; itrack++)
404 libz->
gets(read, 200);
413 cout <<
"The total number of events in the UrQMD file will be processed - " << num << endl;
421 string file_path = filename;
422 TString strFilePath(file_path);
423 gSystem->ExpandPathName(strFilePath);
424 if (gSystem->AccessPathName(strFilePath.Data()) ==
true) {
426 cout <<
"GetNumEvents ERROR: No generator file was found: " << strFilePath << endl;
434 Int_t header_size = 1;
435 for (Int_t
i = 0;
i < header_size;
i++) {
436 libz->
gets(r200, 200);
439 if (str0.find(
"Results of DCM-SMM") != string::npos)
441 else if (str0.find(
"Results of QGSM") != string::npos)
445 cout <<
"GetNumDCMSMMEvents ERROR: Wrong input file format" << endl;
452 int ntracks, num = 0;
453 Int_t evnr = 0, last_evnr = 0;
454 while (!libz->
eof()) {
455 char* gets_res = libz->
gets(read, 128);
456 if (gets_res == Z_NULL)
458 sscanf(read,
"%d", &evnr);
460 if (evnr - last_evnr != 1)
461 cout <<
"ERROR: the sequence of events was interrupted " << last_evnr <<
"-" << evnr << endl;
464 for (Int_t ibeam = 0; ibeam < 3; ibeam++) {
465 libz->
gets(read, 128);
466 sscanf(read,
"%d", &ntracks);
467 for (Int_t
i = 0;
i < ntracks;
i++)
468 libz->
gets(read, 128);
477 cout <<
"The total number of events in the DCMSMM file will be processed - " << num << endl;
481string MpdGetNumEvents::FindFirstTree(
const char* filename,
int iVerbose)
484 TFile* rootFile =
new TFile(filename,
"READ");
485 if (!rootFile->IsOpen()) {
487 cout <<
"GetNumROOTEvents ERROR: could not open ROOT file: " << filename << endl;
491 TIter next(rootFile->GetListOfKeys());
493 while ((key =
static_cast<TKey*
>(next())) !=
nullptr) {
494 if (strcmp(
key->GetClassName(),
"TTree") != 0)
496 string tree_name = (
static_cast<TTree*
>(
key->ReadObj()))->GetName();
503 cout <<
"GetNumROOTEvents ERROR: could not find a tree in the ROOT file: " <<
filename << endl;
513 string file_path = filename;
514 TString strFilePath(file_path);
515 gSystem->ExpandPathName(strFilePath);
516 if (gSystem->AccessPathName(strFilePath.Data()) ==
true) {
518 cout <<
"GetNumEvents ERROR: No generator file was found: " << strFilePath << endl;
523 if (treename ==
nullptr) {
524 string tree_name = FindFirstTree(filename, iVerbose);
527 fileTree =
new TChain(tree_name.c_str());
528 }
else if (treename[0] ==
'\0')
529 fileTree =
new TChain(FairRootManager::GetTreeName());
531 fileTree =
new TChain(treename);
532 fileTree->Add(filename);
534 Int_t num = fileTree->GetEntries();
539 cout <<
"The total number of events in the ROOT file will be processed - " << num << endl;
547 string file_path = filename;
548 TString strFilePath(file_path);
549 gSystem->ExpandPathName(strFilePath);
550 if (gSystem->AccessPathName(strFilePath.Data()) ==
true) {
552 cout <<
"GetNumEvents ERROR: No generator file was found: " << strFilePath << endl;
556 if (strFilePath.Contains(
".root", TString::kIgnoreCase))
559 if (strFilePath.Contains(
".f14", TString::kIgnoreCase))
562 if (strFilePath.Contains(
".r12", TString::kIgnoreCase)) {
570 libz->
gets(r200, 200);
572 if (str0.find(
"Results of QGSM") != string::npos)
574 else if (str0.find(
"Results of DCM-SMM") != string::npos)
578 cout <<
"GetNumEvents ERROR: Wrong input file format, generator type was not defined" << endl;
585 switch (iGenerator) {
static Int_t GetNumROOTEvents(const char *filename, const char *treename="", int iVerbose=2)
static Int_t GetNumPHSDEvents(const char *filename, int iVerbose=2)
static Int_t GetNumQGSMEvents(const char *fileName, int iVerbose=2)
static Int_t GetNumEvents(const char *filename, int iVerbose=2)
static Int_t GetNumURQMDEvents(const char *fileName, int iVerbose=2)
static Int_t GetNumDCMSMMEvents(const char *fileName, int iVerbose=2)
int read(voidp buf, unsigned len)
int write(voidpc buf, unsigned len)
MpdLibZ(const char *filename)
int open(const char *mode)
off_t seek(off_t pos, int whence)
char * gets(char *buf, int len)