3#include "FairRootManager.h"
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 cerr <<
"GetNumEvents ERROR: No generator file was found: " << strFilePath << endl;
158 int ret_code = libz->
open(
"rb");
161 cerr <<
"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 cerr <<
"GetNumPHSDEvents ERROR: selftest error in header, scan " << res <<
" of 2\n" << endl;
182 libz->
gets(fbuffer, 256);
185 cerr <<
"GetNumPHSDEvents ERROR: unexpected end of file " << endl;
191 libz->
gets(fbuffer, 256);
194 cerr <<
"GetNumPHSDEvents ERROR: unexpected end of file" << endl;
206 cout <<
"The total number of events in the PHSD file will be processed - " << num << endl;
220 bool wrong_file =
false;
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 cerr <<
"GetQGSMEventHeader ERROR: Wrong file header! 1 " << endl;
276 if (fQGSM_format_ID >= 2)
280 cerr <<
"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 cerr <<
"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;
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 cerr <<
"GetNumEvents ERROR: No generator file was found: " << strFilePath << endl;
369 int ret_code = libz->
open(
"rb");
372 cerr <<
"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 cerr <<
"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 cerr <<
"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 cerr <<
"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) && (iVerbose > 1))
461 cerr <<
"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);
468 libz->
gets(read, 128);
477 cout <<
"The total number of events in the DCMSMM file will be processed - " << num << endl;
484 TFile* rootFile =
new TFile(filename,
"READ");
485 if (!rootFile->
IsOpen()) {
487 cerr <<
"GetNumROOTEvents ERROR: could not open ROOT file: " << filename << endl;
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 cerr <<
"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 cerr <<
"GetNumEvents ERROR: No generator file was found: " << strFilePath << endl;
523 if (treename ==
nullptr) {
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);
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 cerr <<
"GetNumEvents ERROR: No generator file was found: " << strFilePath << endl;
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 cerr <<
"GetNumEvents ERROR: Wrong input file format, generator type was not defined" << endl;
585 switch (iGenerator) {
R__EXTERN TSystem * gSystem
static Int_t GetNumROOTEvents(const char *filename, const char *treename="", int iVerbose=2)
static Int_t GetNumPHSDEvents(const char *filename, int iVerbose=2)
static std::string FindFirstTree(const char *filename, int iVerbose)
static Int_t GetNumQGSMEvents(const char *fileName, int iVerbose=2)
static Int_t GetNumEvents(const char *filename, int iVerbose=2)
static bool GetQGSMEventHeader(char *ss, MpdLibZ *libz, Int_t &fQGSM_format_ID, int iVerbose)
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)
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
Long64_t GetEntries() const override
TList * GetListOfKeys() const override
virtual Bool_t IsOpen() const
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const