ROOTANA
Loading...
Searching...
No Matches
midas2root.cxx
Go to the documentation of this file.
1// Example Program for converting MIDAS format to ROOT format.
2//
3// T. Lindner (Jan 2016)
4//
5// Example is for the CAEN V792 ADC module
6
7#include <stdio.h>
8#include <iostream>
9#include <time.h>
10#include <vector>
11
12#include "TRootanaEventLoop.hxx"
13#include "TFile.h"
14#include "TTree.h"
15
16#include "TAnaManager.hxx"
17
18#ifdef USE_V792
19#include "TV792Data.hxx"
20#endif
21
22class Analyzer: public TRootanaEventLoop {
23
24public:
25
26 // An analysis manager. Define and fill histograms in
27 // analysis manager.
29
30 // The tree to fill.
32
35#ifdef USE_V792
36 // CAEN V792 tree variables
37 int nchannels;
38 int adc_value[32];
39#endif
40
41
43
44 };
45
46 virtual ~Analyzer() {};
47
48 void Initialize(){
49
50
51 }
52
53
54 void BeginRun(int transition,int run,int time){
55
56 // Create a TTree
57 fTree = new TTree("midas_data","MIDAS data");
58
59 fTree->Branch("timestamp",&timestamp,"timestamp/I");
60 fTree->Branch("serialnumber",&serialnumber,"serialnumber/I");
61
62#ifdef USE_V792
63 fTree->Branch("nchannels",&nchannels,"nchannels/I");
64 fTree->Branch("adc_value",adc_value,"adc_value[nchannels]/I");
65#endif
66
67 }
68
69
70 void EndRun(int transition,int run,int time){
71 printf("\n");
72 }
73
74
75
76 // Main work here; create ttree events for every sequenced event in
77 // Lecroy data packets.
79
80 serialnumber = dataContainer.GetMidasEvent().GetSerialNumber();
81 if(serialnumber%10 == 0) printf(".");
82 timestamp = dataContainer.GetMidasEvent().GetTimeStamp();
83
84#ifdef USE_V792
85 TV792Data *data = dataContainer.GetEventData<TV792Data>("ADC0");
86 if(data){
87 nchannels = 32;
88 for(int i = 0; i < nchannels;i++) adc_value[i] = 0;
89
90 /// Get the Vector of ADC Measurements.
91 std::vector<VADCMeasurement> measurements = data->GetMeasurements();
92 for(unsigned int i = 0; i < measurements.size(); i++){ // loop over measurements
93
94 int chan = measurements[i].GetChannel();
95 uint32_t adc = measurements[i].GetMeasurement();
96
97 if(chan >= 0 && chan < nchannels)
98 adc_value[chan] = adc;
99 }
100 }
101#endif
102
103 fTree->Fill();
104
105 return true;
106
107 };
108
109 // Complicated method to set correct filename when dealing with subruns.
110 std::string SetFullOutputFileName(int run, std::string midasFilename)
111 {
112 char buff[128];
113 Int_t in_num = 0, part = 0;
114 Int_t num[2] = { 0, 0 }; // run and subrun values
115 // get run/subrun numbers from file name
116 for (int i=0; ; ++i) {
117 char ch = midasFilename[i];
118 if (!ch) break;
119 if (ch == '/') {
120 // skip numbers in the directory name
121 num[0] = num[1] = in_num = part = 0;
122 } else if (ch >= '0' && ch <= '9' && part < 2) {
123 num[part] = num[part] * 10 + (ch - '0');
124 in_num = 1;
125 } else if (in_num) {
126 in_num = 0;
127 ++part;
128 }
129 }
130 if (part == 2) {
131 if (run != num[0]) {
132 std::cerr << "File name run number (" << num[0]
133 << ") disagrees with MIDAS run (" << run << ")" << std::endl;
134 exit(1);
135 }
136 sprintf(buff,"output_%.6d_%.4d.root", run, num[1]);
137 printf("Using filename %s\n",buff);
138 } else {
139 sprintf(buff,"output_%.6d.root", run);
140 }
141 return std::string(buff);
142 };
143
144
145
146
147
148};
149
150
151int main(int argc, char *argv[])
152{
153
155 return Analyzer::Get().ExecuteLoop(argc, argv);
156
157}
158
std::string SetFullOutputFileName(int run, std::string midasFilename)
void BeginRun(int transition, int run, int time)
bool ProcessMidasEvent(TDataContainer &dataContainer)
TAnaManager * anaManager
Definition ana.cxx:23
int serialnumber
TTree * fTree
void Initialize()
void EndRun(int transition, int run, int time)
virtual ~Analyzer()
int timestamp
static TRootanaEventLoop & Get(void)
int ExecuteLoop(int argc, char *argv[])
Method to actually process the Midas information, either as file or online.
static void CreateSingleton()
Class for storing data from CAEN V792 module.
Definition TV792Data.hxx:53
std::vector< VADCMeasurement > & GetMeasurements()
Get the Vector of TDC Measurements.
Definition TV792Data.hxx:77
int main(int argc, char *argv[])