ToolDAQFramework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
TriggerOutput.cpp
Go to the documentation of this file.
1 #include "TriggerOutput.h"
2 
4 
5 
6 bool TriggerOutput::Initialise(std::string configfile, DataModel &data){
7 
8  if(configfile!="") m_variables.Initialise(configfile);
9  //m_variables.Print();
10 
11  m_verbose = 0;
12  m_variables.Get("verbose", m_verbose);
13  m_variables.Get("trigger_od", m_trigger_OD);
14 
15  //Setup and start the stopwatch
16  bool use_stopwatch = false;
17  m_variables.Get("use_stopwatch", use_stopwatch);
18  m_stopwatch = use_stopwatch ? new util::Stopwatch("TriggerOutput") : 0;
19 
20  m_stopwatch_file = "";
21  m_variables.Get("stopwatch_file", m_stopwatch_file);
22 
24 
25  m_data= &data;
26 
27  //open the output file
28  Log("DEBUG: TriggerOutput::Initialise opening output file...", DEBUG2, m_verbose);
29  if(! m_variables.Get("outfilename", m_output_filename)) {
30  Log("ERROR: outfilename configuration not found. Cancelling initialisation", ERROR, m_verbose);
31  return false;
32  }
33  m_output_file = new TFile(m_output_filename.c_str(), "RECREATE");
34 
35 
36  //setup the out triggers tree
37  Log("DEBUG: TriggerOutput::Initialise setting up output trigger tree...", DEBUG2, m_verbose);
38  m_triggers_tree = new TTree("triggers","triggers Tree");
39  m_triggers_tree->Branch("type", &the_type, "type/I");
40  m_triggers_tree->Branch("readout_start_time", &the_readout_start_time, "readout_start_time/D");
41  m_triggers_tree->Branch("readout_end_time", &the_readout_end_time, "readout_end_time/D");
42  m_triggers_tree->Branch("mask_start_time", &the_mask_start_time, "mask_start_time/D");
43  m_triggers_tree->Branch("mask_end_time", &the_mask_end_time, "mask_end_time/D");
44  m_triggers_tree->Branch("trigger_time", &the_trigger_time, "trigger_time/D");
45  m_triggers_tree->Branch("trigger_info", &the_trigger_info);
46 
47 
48  //setup the out header tree
49  Log("DEBUG: TriggerOutput::Initialise setting up output header tree...", DEBUG2, m_verbose);
50  m_header_tree = new TTree("header","header Tree");
51  m_header_tree->Branch("interpose_interval", &m_interpose_interval, "interpose_interval/F");
52  m_interpose_interval = m_data->get_interpose_interval();
53  m_header_tree->Fill();
54 
55 
56  //fill the output event-independent trees
57  Log("DEBUG: TriggerOutput::Initialise filling event-independent trees...", DEBUG2, m_verbose);
58 
59  if(m_stopwatch) Log(m_stopwatch->Result("Initialise"), INFO, m_verbose);
60 
61  return true;
62 }
63 
64 
67 
68 
69  TriggerInfo * triggers = m_trigger_OD ? &(m_data->ODTriggers) : &(m_data->IDTriggers);
70 
72  unsigned int num_triggers = triggers->m_num_triggers;
74  std::vector<TriggerType_t> type = triggers->m_type;
76  std::vector<TimeDelta> readout_start_time = triggers->m_readout_start_time;
78  std::vector<TimeDelta> readout_end_time = triggers->m_readout_end_time;
80  std::vector<TimeDelta> mask_start_time = triggers->m_mask_start_time;
82  std::vector<TimeDelta> mask_end_time = triggers->m_mask_end_time;
84  std::vector<TimeDelta> trigger_time = triggers->m_trigger_time;
86  std::vector<std::vector<float> > info = triggers->m_info;
87 
88  m_ss << " TriggerOutput: Number of triggers " << num_triggers;
90  for(int i=0; i<num_triggers; i++){
91  the_type = type[i];
92  the_readout_start_time = absolute_time(readout_start_time[i]);
93  the_readout_end_time = absolute_time(readout_end_time[i]);
94  the_mask_start_time = absolute_time(mask_start_time[i]);
95  the_mask_end_time = absolute_time(mask_end_time[i]);
96  the_trigger_time = absolute_time(trigger_time[i]);
97  the_trigger_info = info[i];
98  m_ss << " TriggerOutput: trigger " << i << " type " << WCSimEnumerations::EnumAsString(the_type) << " readout_start_time " << the_readout_start_time << " readout_end_time " << the_readout_end_time << " mask_start_time " << the_mask_start_time << " mask_end_time " << the_mask_end_time << " trigger_time " << the_trigger_time ;
99  for(unsigned int ii = 0; ii < info[i].size(); ii++)
100  m_ss << " info " << ii << " = " << info[i][ii];
101 
102  StreamToLog(INFO);
103 
104  m_triggers_tree->Fill();
105  }
106 
108 
109  return true;
110 }
111 
112 
114 
115  if(m_stopwatch) {
117  m_stopwatch->Start();
118  }
119 
120  //multiple TFiles may be open. Ensure we save to the correct one
121  m_output_file->cd(TString::Format("%s:/", m_output_filename.c_str()));
122  m_header_tree->Write();
123  m_triggers_tree->Write();
124 
125  delete m_header_tree;
126  delete m_triggers_tree;
127 
128  m_output_file->Close();
129 
130  delete m_output_file;
131 
132  if(m_stopwatch) {
133  Log(m_stopwatch->Result("Finalise"), INFO, m_verbose);
134  delete m_stopwatch;
135  }
136 
137  return true;
138 }
139 
140 
142 
143  return d/TimeDelta::ns;
144 
145 }
TriggerType_t the_type
The type of Trigger.
Definition: TriggerOutput.h:44
std::string Result(std::string method_name, std::string output_file="")
Definition: Stopwatch.cpp:38
std::string m_output_filename
Output ROOT filename that this tool RECREATE&#39;s.
Definition: TriggerOutput.h:33
double the_trigger_time
The actual time of the trigger.
Definition: TriggerOutput.h:54
void Start()
Start the stopwatch.
Definition: Stopwatch.cpp:18
double the_mask_end_time
The ending time of the hit mask.
Definition: TriggerOutput.h:52
double the_mask_start_time
The starting time of the hit mask.
Definition: TriggerOutput.h:50
StopwatchTimes Stop()
Stop the stopwatch, returning the CPU time.
Definition: Stopwatch.cpp:24
std::vector< TimeDelta > m_readout_end_time
The ending time of the trigger window.
Definition: TriggerInfo.h:36
std::vector< std::vector< float > > m_info
Additional information, specific to the trigger.
Definition: TriggerInfo.h:44
bool Initialise(std::string configfile, DataModel &data)
std::vector< float > the_trigger_info
extra info from the trigger
Definition: TriggerOutput.h:56
double absolute_time(TimeDelta d)
std::vector< TimeDelta > m_mask_end_time
The ending time of the hit mask.
Definition: TriggerInfo.h:40
TTree * m_triggers_tree
Tree containing triggers.
Definition: TriggerOutput.h:39
void StreamToLog(int level)
Definition: TriggerOutput.h:67
float m_interpose_interval
Definition: TriggerOutput.h:41
TTree * m_header_tree
header
Definition: TriggerOutput.h:37
std::vector< TimeDelta > m_trigger_time
The actual time of the trigger.
Definition: TriggerInfo.h:42
static std::string EnumAsString(Distribution_t dist)
std::vector< TimeDelta > m_mask_start_time
The starting time of the hit mask.
Definition: TriggerInfo.h:38
static const TimeDelta ns
TimeDelta of 1 ns.
Definition: TimeDelta.h:57
TFile * m_output_file
Output ROOT file.
Definition: TriggerOutput.h:35
std::vector< TimeDelta > m_readout_start_time
The starting time of the trigger window.
Definition: TriggerInfo.h:34
std::string m_stopwatch_file
Image filename to save the histogram to, if required.
Definition: TriggerOutput.h:61
double the_readout_end_time
The ending time of the trigger window.
Definition: TriggerOutput.h:48
void Log(const std::string &message, const int message_level)
Format messages in the same way as for tools.
Definition: Utilities.cpp:276
bool m_trigger_OD
Trigger on OD digits, rather than ID digits?
Definition: TriggerOutput.h:30
double the_readout_start_time
The starting time of the trigger window.
Definition: TriggerOutput.h:46
util::Stopwatch * m_stopwatch
The stopwatch, if we&#39;re using one.
Definition: TriggerOutput.h:59
unsigned int m_num_triggers
The number of triggers.
Definition: TriggerInfo.h:30
std::vector< TriggerType_t > m_type
The type of Trigger.
Definition: TriggerInfo.h:32
std::stringstream m_ss
Definition: TriggerOutput.h:65