Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPulseFinder_IO.hh
Go to the documentation of this file.
1 #ifndef __INPUT_OUTPUT__
2 #define __INPUT_OUTPUT__
3 
4 //c++ standard library
5 #include <iostream>
6 
7 // Jpp
8 #include "JDAQ/JDAQTimeslice.hh"
10 #include "Jeep/JParser.hh"
11 #include "Jeep/JMessage.hh"
13 #include "JDetector/JDetector.hh"
15 
16 //root
17 #include "TVector.h"
18 
19 // namespaces
20 using namespace std;
21 using namespace KM3NETDAQ ; // for JDAQTimeSlice
22 using namespace JSUPPORT; // for JFileScanner
23 using namespace JLANG; // for JMultipleFileScanner
24 using namespace JDETECTOR; // for JModuleLocation
25 
26 
27 
28 
29 /**
30  * \author rgruiz
31  */
32 
33 
34 
35 /**
36  * Structure to store the different command line arguments for JPulseFinder.
37  */
38 struct IO{
39 
41 
42  string ofname ;
43 
44  string detector_file ;
45 
46  int string_number ;
47 
48  unsigned int pulse_period_16ns ;
49 
50  int up_pmts ;
51 
52  int down_pmts ;
53 
54  int number_neighbors ;
55 
57 
59 
60  double voltage ;
61 
62 };
63 
64 
65 /**
66  * Parses the command line options and fills an IO structure with them.
67  *
68  * \param options an option structure
69  * \param argc the number of command line arguments
70  * \param argv the command line arguments
71  *
72  * \return 1 if works 2 if it doesn't work
73  */
74 inline int read_user_options(IO &options, int argc, char **argv){
75 
76  int a = 0;
77 
78  try {
79 
80  JParser<string> zap;
81 
82  zap["o"] = make_field(options.ofname) = "out.root" ;
83 
84  zap["f"] = make_field(options.ifnames) ;
85 
86  zap["a"] = make_field(options.detector_file) ;
87 
88  zap["V"] = make_field(options.voltage) = 0;
89 
90  zap["s"] = make_field(options.string_number) ;
91 
92  zap["p"] = make_field(options.pulse_period_16ns) ;
93 
94  zap["n"] = make_field(options.number_neighbors) = 2 ;
95 
96  zap["t"] = make_field(options.up_pmts) = 1 ;
97 
98  zap["b"] = make_field(options.down_pmts) = 4 ;
99 
100  zap["d"] = make_field(options.overall_delay_16ns) = 0;
101 
102  zap["stagger"] = make_field(options.stagger_16ns) = 0;
103 
104  if (zap.read(argc, argv) != 0)
105 
106  a = 1;
107 
108  }
109 
110  catch(const exception &error) {
111 
112  ERROR(error.what() << endl);
113 
114  a = 2;
115 
116  }
117 
118  return a;
119 
120 }
121 
122 
123 
124 /**
125  * Writes a .root file with the nanobeacon pulses found by JPulseFinder.
126  *
127  * \param options an IO structure
128  * \param ToT_vs_time vector of TH2D with the nanobeacon pulses
129  * \param ToT vector of TH1 with the ToT distribution of the nanobeacon pulses
130  * \param time vector of TH1 with the time distribution of the nanobeacon pulses
131  */
132 void write_output(IO options , vector < vector < TH2D* > > ToT_vs_time , vector < vector < TH1D* > > ToT , vector < vector < TH1D* > > time){
133 
134  JMultipleFileScanner<JDAQTimeslice> inputFile(options.ifnames) ;
135 
136  int run_number = 0 ;
137 
138  inputFile.rewind() ;
139 
140  if(inputFile.hasNext()){
141 
142  run_number = inputFile.next()->getRunNumber() ;
143 
144  }
145 
146  TFile* f = new TFile(options.ofname.c_str(),"RECREATE") ;
147 
148  TVectorD Run (2) ;
149 
150  Run[0] = run_number ;
151 
152  Run[1] = options.voltage ;
153 
154  Run.Write("Run_Info") ;
155 
156  for( int i = 0 ; i < (int)ToT_vs_time.size() ; ++i ) {
157 
158  char dirname[200] ;
159 
160  sprintf(dirname, "S%iF%i", options.string_number, i + 1 ) ;
161 
162  f->mkdir(dirname)->cd() ;
163 
164  for( int j = 0 ; j < (int)ToT_vs_time[0].size() ; ++j ) {
165 
166  if (ToT_vs_time[i][j]==NULL) continue ;
167 
168  if( ToT_vs_time[i][j]->Integral(1 , ToT_vs_time[i][j]->GetNbinsX() - 1 , 1 , ToT_vs_time[i][j]->GetNbinsY() - 1)>0 ) {
169 
170  ToT_vs_time[i][j]->Write() ;
171 
172  ToT[i][j]->Write() ;
173 
174  time[i][j]->Write() ;
175 
176  }
177 
178  }
179 
180  f->cd() ;
181 
182  }
183 
184  f->Close() ;
185 
186  delete (f) ;
187 
188 }
189 
190 #endif
unsigned int pulse_period_16ns
int up_pmts
Utility class to parse command line options.
Definition: JParser.hh:1410
virtual const pointer_type & next()
Get next element.
int string_number
Logical location of module.
int stagger_16ns
int down_pmts
Structure to store the different command line arguments for JRunAnalyzer.
Definition: JRunAnalyzer.cc:40
string ofname
Definition: JRunAnalyzer.cc:44
Data structure for detector geometry and calibration.
int overall_delay_16ns
JMultipleFileScanner ifnames
void write_output(IO options, vector< vector< TH2D * > > ToT_vs_time, vector< vector< TH1D * > > ToT, vector< vector< TH1D * > > time)
Writes a .root file with the nanobeacon pulses found by JPulseFinder.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
#define ERROR(A)
Definition: JMessage.hh:64
double voltage
General purpose messaging.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
virtual bool hasNext()
Check availability of next element.
int read(const int argc, const char *const argv[])
Parse the program&#39;s command line options.
Definition: JParser.hh:1673
int number_neighbors
Utility class to parse command line options.
string detector_file
Definition: JRunAnalyzer.cc:46
int read_user_options(IO &options, int argc, char **argv)
Parses the command line options and fills an IO structure with them.
Definition: JRunAnalyzer.cc:59