AlcapDAQ  1
MOctalFADCProcessRaw.cpp
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: MOctalFADCProcessRaw
4  Created by: Michael Murray
5 
6  Contents: Module to extract TOctalFADCIsland objects from
7  the data banks corresponding to Fred Gray's Octal
8  FADC digitizer. This processes the raw data only,
9  making no assumptions about the attached detector,
10  digitization frequency, etc.
11 
12 \********************************************************************/
13 
14 /* Standard includes */
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string>
18 #include <map>
19 #include <utility>
20 
21 /* MIDAS includes */
22 #include "midas.h"
23 
24 /* ROOT includes */
25 #include <TH1.h>
26 #include <TH2.h>
27 
28 /* AlCap includes */
29 #include "TOctalFADCIsland.h"
30 #include "TOctalFADCBankReader.h"
31 #include "TGlobalData.h"
32 #include "TSetupData.h"
33 
34 using std::string;
35 using std::map;
36 using std::vector;
37 using std::pair;
38 
39 /*-- Module declaration --------------------------------------------*/
41 INT MOctalFADCProcessRaw(EVENT_HEADER*, void*);
42 
43 extern HNDLE hDB;
44 extern TGlobalData* gData;
45 extern TSetupData* gSetup;
46 
48 
49 static vector<TOctalFADCBankReader*> fadc_bank_readers;
50 
52 {
53  "MOctalFADCProcessRaw", /* module name */
54  "Michael Murray", /* author */
55  MOctalFADCProcessRaw, /* event routine */
56  NULL, /* BOR routine */
57  NULL, /* EOR routine */
58  MOctalFADCProcessRaw_init, /* init routine */
59  NULL, /* exit routine */
60  NULL, /* parameter structure */
61  0, /* structure size */
62  NULL, /* initial parameters */
63 };
64 
68 {
69  // This histogram has the bank names labeled on the X-axis, and the midas
70  // block number on the Y-axis.
71  // This uses the TH1::kCanRebin mechanism to expand automatically to the
72  // number of FADC banks.
74  "hNOctalFADCIslandsReadPerBlock",
75  "Number of FADC Islands read by block",
76  1,0,1, 10000,0,10000);
77  hNOctalFADCIslandsReadPerBlock->SetBit(TH1::kCanRebin);
78 
79  std::map<std::string, std::string> bank_to_detector_map = gSetup->fBankToDetectorMap;
80  for(std::map<std::string, std::string>::iterator mapIter = bank_to_detector_map.begin();
81  mapIter != bank_to_detector_map.end(); mapIter++) {
82 
83  std::string bankname = mapIter->first;
84 
85  // We only want the FADC banks here
86  if (TSetupData::IsFADC(bankname))
87  fadc_bank_readers.push_back(new TOctalFADCBankReader(bankname));
88  }
89 
90  return SUCCESS;
91 }
92 
96 INT MOctalFADCProcessRaw(EVENT_HEADER *pheader, void *pevent)
97 {
98  // Get the event number
99  int midas_event_number = pheader->serial_number;
100 
102  // Make TPulseIsland objects for each of the TOctalFADCIslands.
103 
104  // Some typedefs
105  typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap;
106  typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair;
107  typedef map<string, vector<TPulseIsland*> >::iterator map_iterator;
108 
109  // Fetch a reference to the gData structure that stores a map
110  // of (bank_name, vector<TPulseIsland*>) pairs
111  TStringPulseIslandMap& pulse_islands_map =
113 
114  // Delete the islands found in the previous block. Don't clear
115  // the map of (bank_name, vector) pairs. Once we use a bank name
116  // once, it will have a (possibly empty) entry in this map for the
117  // whole run.
118  for(map_iterator iter = pulse_islands_map.begin();
119  iter != pulse_islands_map.end(); iter++){
120  vector<TPulseIsland*>& islands = iter->second;
121  // Delete the pointers to TPulseIslands, then clear the vector
122  for(unsigned int j=0; j<islands.size(); j++) {
123  if(islands[j]) { delete islands[j]; islands[j] = NULL; }
124  }
125  islands.clear();
126  }
127 
128  // Get islands from all banks and add them to the global structure
129  for(unsigned int i=0; i<fadc_bank_readers.size(); i++) {
130  string bank_name = fadc_bank_readers[i]->GetBankName();
131 
132  // Read the islands with the bank reader
134  fadc_bank_readers[i]->ProcessEvent(pheader, pevent);
135  vector<TOctalFADCIsland*> fadc_islands =
136  fadc_bank_readers[i]->GetIslandVectorCopy();
137 
138  // Make vector of TPulseIsland from TOctalFADCIsland. Now this module
139  // owns the memory associated with these.
140  vector<TPulseIsland*> pulse_islands;
141  for(unsigned int j=0; j<fadc_islands.size(); j++) {
142  pulse_islands.push_back(new TPulseIsland(
143  fadc_islands[j]->GetTime(), fadc_islands[j]->GetSampleVector(),bank_name));
144  }
145 
146  // Add a pair (bank_name, vector_of_islands) to the std::map in gData
147  pulse_islands_map[bank_name] = pulse_islands;
148 
149  // Fill Diagnostic histogram
150  hNOctalFADCIslandsReadPerBlock->Fill(bank_name.c_str(), midas_event_number,
151  fadc_islands.size());
152 
153  // print for testing
154  if(midas_event_number == 1) {
155  printf("TEST MESSAGE: Read %d events from bank %s in event %d\n",
156  fadc_bank_readers[i]->GetNIslands(),
157  fadc_bank_readers[i]->GetBankName().c_str(),
158  midas_event_number);
159  }
160  }
161 
162  return SUCCESS;
163 }