split_fd.cc
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <EyeEvent.hh>
4 #include <EyeEventHeader.hh>
5 #include <EyeEventFile.hh>
6 
7 #include <TTree.h>
8 
9 #include <fstream>
10 
11 using namespace std;
12 
13 void
14 help(char *argv[])
15 {
16  cout << endl
17  << " Specify: List of input files, also with \"*\" etc. as well as number of events in output files" << endl;
18 
19  std::cout << "Usage: " << argv[0] << " <files> [n-events]" << std::endl << std::endl;
20 }
21 
22 
23 int
24 main (int argc, char *argv[])
25 {
26  if (argc<=2) {
27  help(argv);
28  return 1;
29  }
30 
31  const int nSplit = atoi(argv[argc-1]);
32  cout << "Your n-split is : " << nSplit << endl;
33 
34 
35  if (nSplit <= 0 || nSplit>1e7) {
36  help(argv);
37  return 1;
38  }
39 
40  ifstream filelist(argv[1]);
41 
42  while (filelist.good()) {
43 
44  string filename;
45  getline(filelist, filename);
46 
47  if (filename=="" || filename[0] == '#')
48  continue;
49 
50  const string nameIn = filename;
51  const string nameOut = nameIn.substr(nameIn.rfind('/')+1, nameIn.length() - nameIn.rfind('/') - 6);
52 
53  cout << "Reading file: " << nameIn << " writing to " << nameOut << endl;
54 
55  TEyeEvent* event = 0;//new TEyeEvent();
56  // TEyeEventFile file(nameIn.c_str(), "READ");
57  TFile* file = TFile::Open(nameIn.c_str());
58  TTree* data = (TTree*) file->Get("EyeEventTree");
59  data->SetBranchAddress("EyeEvent", &event);
60 
61  //TEyeEventFile *out = 0;
62  TFile* out = 0;
63  TTree* outTree = 0;
64  unsigned int iOut = 0;
65  unsigned int iOutFile = 0;
66 
67  // loop over events on file
68  //while (file.ReadEvent(&event)) {
69  for (int iEv=0; iEv<data->GetEntries(); ++iEv) {
70 
71  data->GetEntry(iEv);
72 
73  TEyeEventHeader* header = event->GetEventHeader();
74 
75  cout << " Eye: " << header->GetEyeNo() << " ";
76  cout << " Event Id: " << header->GetEventNo() << " ";
77  cout << " sec: " << header->GetTimeStamp()->GetGPSSec();
78  cout << endl;
79 
80  if (((iOut++) % nSplit) == 0 || !out) {
81  if (out) {
82  out->Close();
83  out = 0;
84  }
85  ostringstream name;
86  name << nameOut << "_split" << (iOutFile++) << ".root";
87  cout << "Opening new output file: " << name.str() << endl;
88  //out = new TEyeEventFile(name.str().c_str(), "RECREATE");
89  out = TFile::Open(name.str().c_str(), "CREATE");
90  out->cd();
91  outTree = new TTree("EyeEventTree", "EventEvent tree");
92  outTree->SetDirectory(out);
93  outTree->Branch("EyeEvent", &event);
94  }
95 
96  // out->WriteEvent(&event);
97  outTree->Fill();
98 
99  }// loop on events
100 
101  if (out) {
102  out->Write();
103  out->Close();
104  out = 0;
105  }
106 
107  cout << " closing file " << endl;
108  file->Close();
109 
110  } // loop input files
111 
112  filelist.close();
113 
114  return 0;
115 }
116 
vector< t2list > out
output of the algorithm: a list of clusters
Definition: XbAlgo.cc:32
int main(int argc, char *argv[])
Definition: DBSync.cc:58
const string file
uint16_t * data
Definition: dump1090.h:228
void help(char *argv[])
Definition: split_ad.cc:12
char * filename
Definition: dump1090.h:266

, generated on Tue Sep 26 2023.