AlcapDAQ  1
Functions | Variables
MOctalFADCProcessRaw.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <map>
#include <utility>
#include "midas.h"
#include <TH1.h>
#include <TH2.h>
#include "TOctalFADCIsland.h"
#include "TOctalFADCBankReader.h"
#include "TGlobalData.h"
#include "TSetupData.h"

Go to the source code of this file.

Functions

INT MOctalFADCProcessRaw_init (void)
 
INT MOctalFADCProcessRaw (EVENT_HEADER *, void *)
 

Variables

HNDLE hDB
 
TGlobalDatagData
 
TSetupDatagSetup
 
static TH2 * hNOctalFADCIslandsReadPerBlock
 
static vector
< TOctalFADCBankReader * > 
fadc_bank_readers
 
ANA_MODULE MOctalFADCProcessRaw_module
 

Function Documentation

INT MOctalFADCProcessRaw ( EVENT_HEADER *  pheader,
void *  pevent 
)

This method processes one MIDAS block, producing a vector of TOctalFADCIsland objects from the raw Octal FADC data.

Todo:
Check for errors when reading/processing the FADC banks

Definition at line 96 of file MOctalFADCProcessRaw.cpp.

References bank_name, TGlobalData::fPulseIslandToChannelMap, GetTime(), hNOctalFADCIslandsReadPerBlock, i, printf(), and SUCCESS.

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 }
INT MOctalFADCProcessRaw_init ( )

This method initializes histograms.

Definition at line 67 of file MOctalFADCProcessRaw.cpp.

References TSetupData::fBankToDetectorMap, hNOctalFADCIslandsReadPerBlock, TSetupData::IsFADC(), and SUCCESS.

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 }

Variable Documentation

vector<TOctalFADCBankReader*> fadc_bank_readers
static

Definition at line 49 of file MOctalFADCProcessRaw.cpp.

TGlobalData* gData

Definition at line 54 of file analyzer.cpp.

TSetupData* gSetup

Definition at line 55 of file analyzer.cpp.

HNDLE hDB

Definition at line 11 of file mucap_compress.cpp.

TH2* hNOctalFADCIslandsReadPerBlock
static

Definition at line 47 of file MOctalFADCProcessRaw.cpp.

Referenced by MOctalFADCProcessRaw(), and MOctalFADCProcessRaw_init().

ANA_MODULE MOctalFADCProcessRaw_module
Initial value:
=
{
"MOctalFADCProcessRaw",
"Michael Murray",
NULL,
NULL,
NULL,
NULL,
0,
NULL,
}

Definition at line 51 of file MOctalFADCProcessRaw.cpp.