00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00020
00021
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string>
00025 #include <map>
00026 #include <utility>
00027 #include <sstream>
00028 #include <cmath>
00029
00030
00031 #include "midas.h"
00032
00033
00034 #include <TH1.h>
00035 #include <TDirectory.h>
00036
00037
00038 #include "TGlobalData.h"
00039 #include "TSetupData.h"
00040 #include "TPulseIsland.h"
00041
00042 using std::string;
00043 using std::map;
00044 using std::vector;
00045 using std::pair;
00046
00047
00048 INT MDQ_DAQLivetime_init(void);
00049 INT MDQ_DAQLivetime(EVENT_HEADER*, void*);
00050 INT MDQ_DAQLivetime_eor(INT);
00051
00052 extern HNDLE hDB;
00053 extern TGlobalData* gData;
00054 extern TSetupData* gSetup;
00055
00056 TH1F* hDQ_DAQLivetime;
00057
00058 ANA_MODULE MDQ_DAQLivetime_module =
00059 {
00060 "MDQ_DAQLivetime",
00061 "Andrew Edmonds",
00062 MDQ_DAQLivetime,
00063 NULL,
00064 MDQ_DAQLivetime_eor,
00065 MDQ_DAQLivetime_init,
00066 NULL,
00067 NULL,
00068 0,
00069 NULL,
00070 };
00071
00074 INT MDQ_DAQLivetime_init()
00075 {
00076
00077 if (!gDirectory->Cd("DataQuality_LowLevel")) {
00078
00079 std::string dir_name("DataQuality_LowLevel/");
00080 gDirectory->mkdir(dir_name.c_str());
00081 gDirectory->Cd(dir_name.c_str());
00082 }
00083
00084
00085 std::string histname = "hDQ_DAQLivetime";
00086 std::string histtitle = "DAQ Livetime of the Run";
00087 hDQ_DAQLivetime = new TH1F(histname.c_str(), histtitle.c_str(), 3,0,3);
00088 hDQ_DAQLivetime->GetXaxis()->SetTitle("");
00089 hDQ_DAQLivetime->GetYaxis()->SetTitle("DAQ Livetime");
00090
00091
00092 gDirectory->Cd("/MidasHists/");
00093 return SUCCESS;
00094 }
00095
00098 INT MDQ_DAQLivetime_eor(INT run_number) {
00099
00100
00101 HNDLE hDB, hKey;
00102 char keyName[200];
00103
00104 if(cm_get_experiment_database(&hDB, NULL) != CM_SUCCESS){
00105 printf("Warning: Could not connect to ODB database!\n");
00106 return false;
00107 }
00108
00109 sprintf(keyName, "/Runinfo/Start time binary");
00110 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){
00111 printf("Warning: Could not find key %s\n", keyName);
00112 return false;
00113 }
00114 KEY start_time_key;
00115 if(db_get_key(hDB, hKey, &start_time_key) != DB_SUCCESS){
00116 printf("Warning: Could not find key %s\n", keyName);
00117 return false;
00118 }
00119 DWORD StartTimes[start_time_key.num_values];
00120 int size = sizeof(StartTimes);
00121 if(db_get_value(hDB, 0, keyName, StartTimes, &size, TID_DWORD, 0) != DB_SUCCESS){
00122 printf("Warning: Could not retrieve values for key %s\n", keyName);
00123 return false;
00124 }
00125
00126 sprintf(keyName, "/Runinfo/Stop time binary");
00127 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){
00128 printf("Warning: Could not find key %s\n", keyName);
00129 return false;
00130 }
00131 KEY stop_time_key;
00132 if(db_get_key(hDB, hKey, &stop_time_key) != DB_SUCCESS){
00133 printf("Warning: Could not find key %s\n", keyName);
00134 return false;
00135 }
00136 DWORD StopTimes[stop_time_key.num_values];
00137 size = sizeof(StopTimes);
00138 if(db_get_value(hDB, 0, keyName, StopTimes, &size, TID_DWORD, 0) != DB_SUCCESS){
00139 printf("Warning: Could not retrieve values for key %s\n", keyName);
00140 return false;
00141 }
00142
00143 int duration = StopTimes[0] - StartTimes[0];
00144
00145 hDQ_DAQLivetime->Scale(1.0/duration);
00146
00147 return SUCCESS;
00148 }
00149
00152 INT MDQ_DAQLivetime(EVENT_HEADER *pheader, void *pevent)
00153 {
00154
00155 int midas_event_number = pheader->serial_number;
00156
00157
00158 typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap;
00159 typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair;
00160 typedef map<string, vector<TPulseIsland*> >::iterator map_iterator;
00161
00162
00163 double gate_length = 110;
00164 gate_length /= 1000;
00165 hDQ_DAQLivetime->Fill(1,gate_length);
00166 return SUCCESS;
00167 }
00168