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