ROOTANA
midas2root_alt.cxx
Go to the documentation of this file.
1 // Example Program for converting MIDAS format to ROOT format.
2 //
3 // T. Lindner (Feb 2021)
4 //
5 // Example for creating a ROOT file for MIDAS bank without dedicated decoder.
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 class Analyzer: public TRootanaEventLoop {
19 
20 public:
21 
22  // An analysis manager. Define and fill histograms in
23  // analysis manager.
25 
26  // The tree to fill.
27  TTree *fTree;
28 
29  // save the current and voltage readings stored in this bank.
30  int timestamp;
31  float current_readings[9];
32  float voltage_readings[9];
33 
35 
36  UseBatchMode();
37  };
38 
39  virtual ~Analyzer() {};
40 
41  void Initialize(){
42 
43 
44  }
45 
46 
47  void BeginRun(int transition,int run,int time){
48 
49  // Create a TTree
50  fTree = new TTree("midas_data","MIDAS data");
51 
52  fTree->Branch("timestamp",&timestamp,"timestamp/I");
53  fTree->Branch("current_readings",current_readings,"current_readings[9]/F");
54  fTree->Branch("voltage_readings",voltage_readings,"voltage_readings[9]/F");
55 
56  }
57 
58 
59  void EndRun(int transition,int run,int time){
60  printf("\n");
61  }
62 
63 
64 
65  // Main work here; create ttree events for every sequenced event in
66  // Lecroy data packets.
67  bool ProcessMidasEvent(TDataContainer& dataContainer){
68 
69  timestamp = dataContainer.GetMidasEvent().GetTimeStamp();
70 
71  // Use generic data class to get the data bank.
72  // You need to know that the data is stored as a float.
73  // This particular bank is 18 floats, which pairs of float as current and voltage readings.
74  TGenericData *data = dataContainer.GetEventData<TGenericData>("BRV1");
75  if(data){
76  std::cout << "Found BRV1 bank" << std::endl;
77  std::cout << "Bank size: " << data->GetSize() << std::endl;
78  for(int i = 0; i < data->GetSize() ; i++){
79  std::cout << "Data["<<i<<"] is " << data->GetFloat()[i] << std::endl;
80  int index = i/2;
81  if(i%2==0){
82  current_readings[index] = data->GetFloat()[i];
83  }else{
84  voltage_readings[index] = data->GetFloat()[i];
85  }
86  }
87 
88  fTree->Fill();
89 
90  }
91 
92 
93  return true;
94 
95  };
96 
97 
98 
99 
100 };
101 
102 
103 int main(int argc, char *argv[])
104 {
105 
106  Analyzer::CreateSingleton<Analyzer>();
107  return Analyzer::Get().ExecuteLoop(argc, argv);
108 
109 }
110 
Definition: ana.cxx:14
void BeginRun(int transition, int run, int time)
bool ProcessMidasEvent(TDataContainer &dataContainer)
TAnaManager * anaManager
Definition: ana.cxx:23
TTree * fTree
Definition: midas2root.cxx:31
void Initialize()
float current_readings[9]
void EndRun(int transition, int run, int time)
virtual ~Analyzer()
int timestamp
Definition: midas2root.cxx:33
float voltage_readings[9]
T * GetEventData(const char *name)
Add a templated function that returns event data in the format that we want.
TMidasEvent & GetMidasEvent() const
int GetSize() const
const float * GetFloat() const
uint32_t GetTimeStamp() const
return the time stamp (unix time in seconds)
static TRootanaEventLoop & Get(void)
void UseBatchMode()
Use a batch mode, where we don't check ROOT status.
int ExecuteLoop(int argc, char *argv[])
Method to actually process the Midas information, either as file or online.
int main(int argc, char *argv[])