count_data.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <string>
  5. #include <TChain.h>
  6. #include <TString.h>
  7. int main(int argc, char** argv)
  8. {
  9. TString iFileName, iTreeName;
  10. if (argc < 5){
  11. std::cerr << "./get_dca -i filelist --tree-name TreeName" << std::endl;
  12. return 1;
  13. }
  14. for (int i=1; i<argc; i++){
  15. if(std::string(argv[i]) != "-i" &&
  16. std::string(argv[i]) != "--tree-name"){
  17. std::cerr << "\n[ERROR]: Unknown parameter " << i << ": " << argv[i] << std::endl;
  18. return 1;
  19. } else {
  20. if(std::string(argv[i]) == "-i" && i!=argc-1) {
  21. iFileName = argv[++i];
  22. continue;
  23. }
  24. if(std::string(argv[i]) == "-i" && i==argc-1) {
  25. std::cerr << "\n[ERROR]: Input file name was not specified " << std::endl;
  26. return 1;
  27. }
  28. if(std::string(argv[i]) == "--tree-name" && i!=argc-1) {
  29. iTreeName = argv[++i];
  30. continue;
  31. }
  32. if(std::string(argv[i]) == "--tree-name" && i==argc-1) {
  33. std::cerr << "\n[ERROR]: Tree name was not specified " << std::endl;
  34. return 1;
  35. }
  36. }
  37. }
  38. std::cout << "Processing count-data..." << std::endl;
  39. std::ifstream infile(iFileName.Data());
  40. std::string line;
  41. TChain *chain = new TChain(iTreeName.Data());
  42. int iFiles = 0;
  43. while (std::getline(infile, line))
  44. {
  45. chain->Add(line.c_str());
  46. iFiles++;
  47. }
  48. std::cout << iFiles << " files were processed." << std::endl;
  49. std::cout << "Total number of events:" << std::endl;
  50. Long64_t nEntries = chain->GetEntries();
  51. std::cout << nEntries << std::endl;
  52. std::cout << std::endl;
  53. return 0;
  54. }