AlcapDAQ  1
MVacuumHisto.cpp
Go to the documentation of this file.
1 /********************************************************************\
2 
3 Name: MVacuumHisto.cpp
4 Created by: Chen Wu
5 
6 Contents: Create histograms for vacuum monitor
7 
8 \********************************************************************/
9 
10 /* Standard includes */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string>
14 #include <map>
15 #include <utility>
16 #include <time.h>
17 
18 /* MIDAS includes */
19 #include "midas.h"
20 
21 /* ROOT includes */
22 #include <TH1.h>
23 #include <TH2.h>
24 
25 /* AlCap includes */
26 //#include "TOctalFADCIsland.h"
27 //#include "TOctalFADCBankReader.h"
28 #include "TVacuumData.h"
29 
30 #define MAX_PRESSURE_POINTS 7200
31 
32 using std::string;
33 using std::map;
34 using std::vector;
35 using std::pair;
36 
37 /*-- Module declaration --------------------------------------------*/
38 INT MVacuumHisto_init(void);
39 INT MVacuumHisto(EVENT_HEADER*, void*);
40 
41 extern HNDLE hDB;
42 extern TVacuumData* gVacuum;
43 
44 static TH1F* hVacuumPressure;
45 static TH1I* hVacuumStatus;
46 
47 ANA_MODULE MVacuumHisto_module =
48 {
49  "MVacuumHisto", /* module name */
50  "Chen Wu", /* author */
51  MVacuumHisto, /* event routine */
52  NULL, /* BOR routine */
53  NULL, /* EOR routine */
54  MVacuumHisto_init, /* init routine */
55  NULL, /* exit routine */
56  NULL, /* parameter structure */
57  0, /* structure size */
58  NULL, /* initial parameters */
59 };
60 
64 {
65  hVacuumPressure = new TH1F("Vacuum_Pressure","Pressure (mbar)",MAX_PRESSURE_POINTS,-(double)MAX_PRESSURE_POINTS/60,0);
66  hVacuumPressure->GetXaxis()->SetTitle("Time to now (min)");
67  hVacuumPressure->GetYaxis()->SetTitle("Pressure (mbar)");
68  hVacuumStatus = new TH1I("Vacuum_Status","Status",MAX_PRESSURE_POINTS,-(double)MAX_PRESSURE_POINTS/60,0);
69  hVacuumStatus->GetXaxis()->SetTitle("Time to now (min)");
70  hVacuumStatus->GetYaxis()->SetTitle("Status of Vacuum Gauge");
71 
72  return SUCCESS;
73 }
74 
75 INT MVacuumHisto(EVENT_HEADER *pheader, void *pevent)
76 {
77  // Get the event number
78  //int midas_event_number = pheader->serial_number;
79 
80  // Fill Diagnostic histogram
81  //hNOctalFADCIslandsReadPerBlock->Fill(bank_name.c_str(), midas_event_number,
82  //fadc_islands.size());
83 
84  float *ppressure;
85  INT *pstatus;
86 
87  // printf("In caen ER!\n");
88 
89  char bank_name[8];
90 
91  int eventid = EVENT_ID(pevent);
92  if (eventid != 24) return SUCCESS;
93 
94  time_t block_time = pheader->time_stamp;
95  int time_sec = (int) block_time;
96 
97 // char banklist[STRING_BANKLIST_MAX];
98 // int nbanks = bk_list(pevent, banklist);
99 // printf("nbanks = %d, %s\n", nbanks, banklist);
100  //printf("eventid = %d\n",eventid);
101  int midas_event_number = pheader->serial_number;
102  //printf("serial_number = %d\n", midas_event_number);
103 // char fdate[] = "%Y-%m-%d", ftime[] = "%H:%M:%S";
104 // struct tm block_tm;
105 // localtime_r(&block_time, &block_tm);
106 // char sdate[100], stime[100];
107 // strftime(sdate, 100, fdate, &block_tm);
108 // strftime(stime, 100, ftime, &block_tm);
109 // printf("Current block stored (%d) on %s at %s\n",
110 // time_sec, sdate, stime);
111 
112  sprintf(bank_name,"PRM%i",0); // only one gauge
113  unsigned int bank_len = bk_locate(pevent, "PRM0", &ppressure);
114 // printf("MIDAS bank [%s] size %d, %d, %f----------------------------------------\n",bank_name,bank_len,ppressure==NULL,ppressure==NULL?-456:*ppressure);
115 
116  sprintf(bank_name,"PRS%i",0); // only one gauge
117  bank_len = bk_locate(pevent, bank_name, &pstatus);
118 // printf("MIDAS bank [%s] size %d, %d , %d----------------------------------------\n",bank_name,bank_len,pstatus==NULL,pstatus==NULL?-123:*pstatus);
119 
120  // By default, banks size is 1
121  if (ppressure!=NULL&&pstatus!=NULL){
122  gVacuum->AddPoint(time_sec, *pstatus, *ppressure);
123  for (int ibin = 1; ibin <= MAX_PRESSURE_POINTS; ibin++){
124  if (ibin!=MAX_PRESSURE_POINTS){
125  hVacuumPressure->SetBinContent(ibin,hVacuumPressure->GetBinContent(ibin+1));
126  hVacuumStatus->SetBinContent(ibin,hVacuumPressure->GetBinContent(ibin+1));
127  }
128  else{
129  hVacuumPressure->SetBinContent(ibin,*ppressure);
130  hVacuumStatus->SetBinContent(ibin,*pstatus);
131  }
132  }
133  }
134  else{
135  printf("###!!!Cannot find point!!!###\n");
136  }
137 
138  return SUCCESS;
139 }