main.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #include <iostream>
  2. #include <vector>
  3. #include <TString.h>
  4. #include <TFile.h>
  5. #include <TStopwatch.h>
  6. #include <mciParticle.h>
  7. #include <mciEvent.h>
  8. #include <mciReader_manager.h>
  9. #include <mciReader_smash_root.h>
  10. #include <mciReader_mcpico.h>
  11. #include <mciWriter_manager.h>
  12. #include <mciWriter_mcpico.h>
  13. #include <Utility.h>
  14. #ifdef _MCINI_
  15. #include <mciReader_mcini.h>
  16. #endif
  17. #ifdef _PHQMD_
  18. #include <mciReader_phqmd.h>
  19. #endif
  20. #ifdef _HSD_ROOT_
  21. #include <mciReader_hsd_root.h>
  22. #endif
  23. int main(int argc, char **argv)
  24. {
  25. TString iFileName, oFileName;
  26. if (argc < 9)
  27. {
  28. std::cerr << "./ModelConverter -i input.list -o output.root -input-format [FORMAT] -output-format [FORMAT] [OPTIONAL: -debug]" << std::endl;
  29. std::cerr << "Available input formats:" << std::endl;
  30. std::cerr << "\tmcpico - simple custom ROOT format to store model data." << std::endl;
  31. std::cerr << "\tparticle - ROOT format that is used by the SMASH model." << std::endl;
  32. #ifdef _MCINI_
  33. 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;
  34. #endif
  35. #ifdef _PHQMD_
  36. std::cerr << "\tphqmd - custom ROOT format to store PHQMD (with MST) model data." << std::endl;
  37. #endif
  38. #ifdef _HSD_ROOT_
  39. std::cerr << "\thsd - custom ROOT format to store HSD model data." << std::endl;
  40. #endif
  41. std::cerr << "Available output formats:" << std::endl;
  42. std::cerr << "\tmcpico - simple custom ROOT format to store model data." << std::endl;
  43. return 1;
  44. }
  45. for (int i = 1; i < argc; i++)
  46. {
  47. if (std::string(argv[i]) != "-i" &&
  48. std::string(argv[i]) != "-o" &&
  49. std::string(argv[i]) != "-input-format" &&
  50. std::string(argv[i]) != "-output-format" &&
  51. std::string(argv[i]) != "-debug")
  52. {
  53. std::cerr << "\n[ERROR]: Unknown parameter " << i << ": " << argv[i] << std::endl;
  54. return 2;
  55. }
  56. else
  57. {
  58. if (std::string(argv[i]) == "-i" && i != argc - 1)
  59. {
  60. iFileName = argv[++i];
  61. continue;
  62. }
  63. if (std::string(argv[i]) == "-i" && i == argc - 1)
  64. {
  65. std::cerr << "\n[ERROR]: Input file name was not specified " << std::endl;
  66. return 1;
  67. }
  68. if (std::string(argv[i]) == "-o" && i != argc - 1)
  69. {
  70. oFileName = argv[++i];
  71. continue;
  72. }
  73. if (std::string(argv[i]) == "-o" && i == argc - 1)
  74. {
  75. std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
  76. return 1;
  77. }
  78. if (std::string(argv[i]) == "-input-format" && i != argc - 1)
  79. {
  80. mciUtility::GetInstance()->input_format = argv[++i];
  81. continue;
  82. }
  83. if (std::string(argv[i]) == "-input-format" && i == argc - 1)
  84. {
  85. std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
  86. return 1;
  87. }
  88. if (std::string(argv[i]) == "-output-format" && i != argc - 1)
  89. {
  90. mciUtility::GetInstance()->output_format = argv[++i];
  91. continue;
  92. }
  93. if (std::string(argv[i]) == "-output-format" && i == argc - 1)
  94. {
  95. std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
  96. return 1;
  97. }
  98. if (std::string(argv[i]) == "-debug" && i != argc - 1)
  99. {
  100. mciUtility::GetInstance()->debug = 1;
  101. continue;
  102. }
  103. }
  104. }
  105. TStopwatch timer;
  106. timer.Start();
  107. if (mciUtility::GetInstance()->debug)
  108. {
  109. std::cout << "Input format = " << mciUtility::GetInstance()->input_format << std::endl;
  110. std::cout << "Output format = " << mciUtility::GetInstance()->output_format << std::endl;
  111. std::cout << "debug = " << mciUtility::GetInstance()->debug << std::endl;
  112. std::cout << "Nevents = " << mciUtility::GetInstance()->Nevents << std::endl;
  113. std::cout << std::endl;
  114. }
  115. mciReader_manager *readerManager = nullptr;
  116. if (mciUtility::GetInstance()->input_format == "mcpico")
  117. {
  118. readerManager = new mciReader_mcpico();
  119. }
  120. #ifdef _MCINI_
  121. if (mciUtility::GetInstance()->input_format == "mcini")
  122. {
  123. readerManager = new mciReader_mcini();
  124. }
  125. #endif
  126. #ifdef _PHQMD_
  127. if (mciUtility::GetInstance()->input_format == "phqmd")
  128. {
  129. readerManager = new mciReader_phqmd();
  130. }
  131. #endif
  132. #ifdef _HSD_ROOT_
  133. if (mciUtility::GetInstance()->input_format == "hsd")
  134. {
  135. readerManager = new mciReader_hsd_root();
  136. }
  137. #endif
  138. if (mciUtility::GetInstance()->input_format == "particles")
  139. {
  140. readerManager = new mciReader_smash_root();
  141. }
  142. if (!readerManager)
  143. {
  144. std::cerr << "This input format is not found!" << std::endl;
  145. return 20;
  146. }
  147. readerManager->SetChain(iFileName.Data());
  148. Long64_t Nentries_chain = readerManager->GetEntries();
  149. Long64_t Nentries = (mciUtility::GetInstance()->Nevents > Nentries_chain) ? Nentries_chain : mciUtility::GetInstance()->Nevents;
  150. if (mciUtility::GetInstance()->Nevents == -1)
  151. Nentries = Nentries_chain;
  152. Int_t Nparticles;
  153. mciWriter_manager *writerManager = nullptr;
  154. if (mciUtility::GetInstance()->output_format == "mcpico")
  155. {
  156. writerManager = new mciWriter_mcpico();
  157. }
  158. if (!writerManager)
  159. {
  160. std::cerr << "This output format is not found!" << std::endl;
  161. return 30;
  162. }
  163. writerManager->SetFile(oFileName.Data());
  164. mciEvent *event = nullptr;
  165. mciParticle *particle = nullptr;
  166. for (Long64_t ievent=0; ievent<Nentries; ievent++)
  167. {
  168. if (ievent % 1000 == 0)
  169. std::cout << "Event [" << ievent << "/" << Nentries << "]" << std::endl;
  170. event = (mciEvent *)readerManager->ReadEvent(ievent);
  171. if (!event) continue;
  172. writerManager->SetEvent(event);
  173. Nparticles = event->GetNparticles();
  174. for (int iparticle = 0; iparticle < Nparticles; iparticle++)
  175. {
  176. particle = readerManager->ReadParticle(iparticle);
  177. if (!particle) continue;
  178. writerManager->SetParticle(particle, iparticle);
  179. }
  180. writerManager->Fill();
  181. }
  182. writerManager->Write();
  183. writerManager->Close();
  184. timer.Stop();
  185. timer.Print();
  186. return 0;
  187. }