split_ad.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <IoAuger.h>
3 
4 #include <EyeEvent.hh>
5 #include <EyeEventHeader.hh>
6 
7 #include <fstream>
8 
9 using namespace std;
10 
11 void
12 help(char *argv[])
13 {
14  cout << endl
15  << " Specify: List of input files, also with \"*\" etc. as well as number of events in output files" << endl;
16 
17  std::cout << "Usage: " << argv[0] << " <files> [n-events]" << std::endl << std::endl;
18 }
19 
20 
21 int
22 main (int argc, char *argv[])
23 {
24  if (argc<=2) {
25  help(argv);
26  return 1;
27  }
28 
29  const int nSplit = atoi(argv[argc-1]);
30 
31  if (nSplit <= 0 || nSplit>1e7) {
32  help(argv);
33  return 1;
34  }
35 
36  ifstream filelist(argv[1]);
37 
38  while (filelist.good()) {
39 
40  string filename;
41  getline(filelist, filename);
42 
43  if (filename=="" || filename[0] == '#')
44  continue;
45 
46  const string nameIn = filename;
47  const string nameOut = nameIn.substr(nameIn.rfind('/')+1, nameIn.length() - nameIn.rfind('/') - 6);
48 
49  cout << "Reading file: " << nameIn << " writing to " << nameOut << endl;
50 
51  AugerFile file(nameIn.c_str(), AugerFile::eRead);
52 
53  AugerFile *out = 0;
54  unsigned int iOut = 0;
55  unsigned int iOutFile = 0;
56 
57  // loop over events on file
58  AugerEvent event;
59  while (file.ReadNext(event) != AugerFile::eEOF) {
60 
61  unsigned int nstations = 0;
62  if (event.HasSd()) {
63  IoSdEvent sd = event.Sd();
64  nstations = sd.NumberOfErrorZeroStation;
65  }
66 
67  cout << " Event Id " << event.Id() << " ";
68  cout << " Nstations: " << setw(2) << nstations;
69  cout << " NEyes: " << event.Eyes.size( ) << endl;
70 
71  if (event.Eyes.size() == 0)
72  continue;
73 
74  // loop on eye events
75  bool hasHEorCO = false;
76  AugerEvent::EyeIterator eye;
77  for(eye= event.EyesBegin(); eye!=event.EyesEnd(); ++eye) {
78 
79  if (eye->GetEventHeader()->GetEyeNo() >= 4)
80  hasHEorCO = true;
81 
82  cout << " ";
83  cout << " eye: "<<eye->GetEventHeader()->GetEyeNo()
84  << " sec: " << eye->GetEventHeader()->GetTimeStamp()->GetGPSSec()
85  << endl;
86  // add here cut on TIMES, if you want
87  } // loop on eyes
88 
89  if (!hasHEorCO)
90  continue;
91 
92  if (((iOut++) % nSplit) == 0 || !out) {
93  if (out) {
94  out->Close();
95  out = 0;
96  }
97  ostringstream name;
98  name << nameOut << "_split" << (iOutFile++) << ".root";
99  cout << "Opening new output file: " << name.str() << endl;
100  out = new AugerFile(name.str().c_str(), AugerFile::eWrite);
101  }
102 
103  // out->Write(*(event.RawAugerEvent()), "VERBOSE");
104  out->Write(event, "VERBOSE");
105 
106  }// loop on events
107 
108  if (out) {
109  out->Close();
110  out = 0;
111  }
112 
113  cout << " closing file " << endl;
114  file.Close();
115 
116  } // loop input files
117 
118  filelist.close();
119 
120  return 0;
121 }
122 
vector< t2list > out
output of the algorithm: a list of clusters
Definition: XbAlgo.cc:32
Read Only access.
Definition: IoCodes.h:18
int main(int argc, char *argv[])
Definition: DBSync.cc:58
const string file
void help(char *argv[])
Definition: split_ad.cc:12
char * filename
Definition: dump1090.h:266

, generated on Tue Sep 26 2023.