123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- #include <iostream>
- #include <vector>
- #include <TString.h>
- #include <TFile.h>
- #include <TStopwatch.h>
- #include <mciParticle.h>
- #include <mciEvent.h>
- #include <mciReader_manager.h>
- #include <mciReader_smash_root.h>
- #include <mciReader_mcpico.h>
- #include <mciWriter_manager.h>
- #include <mciWriter_mcpico.h>
- #include <Utility.h>
- #ifdef _MCINI_
- #include <mciReader_mcini.h>
- #endif
- #ifdef _PHQMD_
- #include <mciReader_phqmd.h>
- #endif
- #ifdef _HSD_ROOT_
- #include <mciReader_hsd_root.h>
- #endif
- int main(int argc, char **argv)
- {
- TString iFileName, oFileName;
-
- if (argc < 9)
- {
- std::cerr << "./ModelConverter -i input.list -o output.root -input-format [FORMAT] -output-format [FORMAT] [OPTIONAL: -debug]" << std::endl;
- std::cerr << "Available input formats:" << std::endl;
- std::cerr << "\tmcpico - simple custom ROOT format to store model data." << std::endl;
- std::cerr << "\tparticle - ROOT format that is used by the SMASH model." << std::endl;
- #ifdef _MCINI_
- std::cerr << "\tmcini - custom ROOT format to store both initial state and final state (UniGen data format) model data. Fully compatible with UniGen format." << std::endl;
- #endif
- #ifdef _PHQMD_
- std::cerr << "\tphqmd - custom ROOT format to store PHQMD (with MST) model data." << std::endl;
- #endif
- #ifdef _HSD_ROOT_
- std::cerr << "\thsd - custom ROOT format to store HSD model data." << std::endl;
- #endif
- std::cerr << "Available output formats:" << std::endl;
- std::cerr << "\tmcpico - simple custom ROOT format to store model data." << std::endl;
- return 1;
- }
- for (int i = 1; i < argc; i++)
- {
- if (std::string(argv[i]) != "-i" &&
- std::string(argv[i]) != "-o" &&
- std::string(argv[i]) != "-input-format" &&
- std::string(argv[i]) != "-output-format" &&
- std::string(argv[i]) != "-debug")
- {
- std::cerr << "\n[ERROR]: Unknown parameter " << i << ": " << argv[i] << std::endl;
- return 2;
- }
- else
- {
- if (std::string(argv[i]) == "-i" && i != argc - 1)
- {
- iFileName = argv[++i];
- continue;
- }
- if (std::string(argv[i]) == "-i" && i == argc - 1)
- {
- std::cerr << "\n[ERROR]: Input file name was not specified " << std::endl;
- return 1;
- }
- if (std::string(argv[i]) == "-o" && i != argc - 1)
- {
- oFileName = argv[++i];
- continue;
- }
- if (std::string(argv[i]) == "-o" && i == argc - 1)
- {
- std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
- return 1;
- }
- if (std::string(argv[i]) == "-input-format" && i != argc - 1)
- {
- mciUtility::GetInstance()->input_format = argv[++i];
- continue;
- }
- if (std::string(argv[i]) == "-input-format" && i == argc - 1)
- {
- std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
- return 1;
- }
- if (std::string(argv[i]) == "-output-format" && i != argc - 1)
- {
- mciUtility::GetInstance()->output_format = argv[++i];
- continue;
- }
- if (std::string(argv[i]) == "-output-format" && i == argc - 1)
- {
- std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
- return 1;
- }
- if (std::string(argv[i]) == "-debug" && i != argc - 1)
- {
- mciUtility::GetInstance()->debug = 1;
- continue;
- }
- }
- }
- TStopwatch timer;
- timer.Start();
-
- if (mciUtility::GetInstance()->debug)
- {
- std::cout << "Input format = " << mciUtility::GetInstance()->input_format << std::endl;
- std::cout << "Output format = " << mciUtility::GetInstance()->output_format << std::endl;
- std::cout << "debug = " << mciUtility::GetInstance()->debug << std::endl;
- std::cout << "Nevents = " << mciUtility::GetInstance()->Nevents << std::endl;
- std::cout << std::endl;
- }
- mciReader_manager *readerManager = nullptr;
- if (mciUtility::GetInstance()->input_format == "mcpico")
- {
- readerManager = new mciReader_mcpico();
- }
- #ifdef _MCINI_
- if (mciUtility::GetInstance()->input_format == "mcini")
- {
- readerManager = new mciReader_mcini();
- }
- #endif
- #ifdef _PHQMD_
- if (mciUtility::GetInstance()->input_format == "phqmd")
- {
- readerManager = new mciReader_phqmd();
- }
- #endif
- #ifdef _HSD_ROOT_
- if (mciUtility::GetInstance()->input_format == "hsd")
- {
- readerManager = new mciReader_hsd_root();
- }
- #endif
- if (mciUtility::GetInstance()->input_format == "particles")
- {
- readerManager = new mciReader_smash_root();
- }
- if (!readerManager)
- {
- std::cerr << "This input format is not found!" << std::endl;
- return 20;
- }
- readerManager->SetChain(iFileName.Data());
- Long64_t Nentries_chain = readerManager->GetEntries();
- Long64_t Nentries = (mciUtility::GetInstance()->Nevents > Nentries_chain) ? Nentries_chain : mciUtility::GetInstance()->Nevents;
- if (mciUtility::GetInstance()->Nevents == -1)
- Nentries = Nentries_chain;
- Int_t Nparticles;
- mciWriter_manager *writerManager = nullptr;
- if (mciUtility::GetInstance()->output_format == "mcpico")
- {
- writerManager = new mciWriter_mcpico();
- }
- if (!writerManager)
- {
- std::cerr << "This output format is not found!" << std::endl;
- return 30;
- }
- writerManager->SetFile(oFileName.Data());
- mciEvent *event = nullptr;
- mciParticle *particle = nullptr;
- for (Long64_t ievent=0; ievent<Nentries; ievent++)
- {
- if (ievent % 1000 == 0)
- std::cout << "Event [" << ievent << "/" << Nentries << "]" << std::endl;
-
- event = (mciEvent *)readerManager->ReadEvent(ievent);
- if (!event) continue;
- writerManager->SetEvent(event);
- Nparticles = event->GetNparticles();
- for (int iparticle = 0; iparticle < Nparticles; iparticle++)
- {
- particle = readerManager->ReadParticle(iparticle);
- if (!particle) continue;
- writerManager->SetParticle(particle, iparticle);
- }
- writerManager->Fill();
- }
- writerManager->Write();
- writerManager->Close();
- timer.Stop();
- timer.Print();
- return 0;
- }
|