]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/TRDHALFCHAMBERSTATUSda.cxx
Fixing a bug with DCA
[u/mrichter/AliRoot.git] / TRD / TRDHALFCHAMBERSTATUSda.cxx
CommitLineData
ef7aea93 1/*
2
3Contact: r.bailhache@gsi.de
4Link:
5Reference run: 104892
6Run Type: PHYSICS
7DA Type: MON
8Number of events needed: many
9Input Files: TRD raw files
10Output Files: trdCalibrationhcs.root
11Trigger types used: PHYSICS_EVENT
12
13*/
14
15#define RESULT_FILE "trdHalfChamberStatus.root"
16#define FILE_ID "HALFCHAMBERSTATUS"
17
18extern "C" {
19#include <daqDA.h>
20}
21
22#include "event.h"
23#include "monitor.h"
24#include <stdio.h>
25#include <stdlib.h>
26
27//
28// Root includes
29//
30#include <TFile.h>
31#include <TStopwatch.h>
32#include "TROOT.h"
33#include "TPluginManager.h"
2c61d953 34#include "TSystem.h"
ef7aea93 35//
36// AliRoot includes
37//
38#include "AliRawReader.h"
39#include "AliRawReaderDate.h"
fd50bb14 40//#include "AliTRDrawFastStream.h"
41//#include "AliTRDrawStreamBase.h"
df7153c8 42#include "AliLog.h"
ef7aea93 43//#include "AliCDBManager.h"
44
45//
46//AMORE
47//
48#include <AmoreDA.h>
49
50//
51// AliRoot TRD calib classes
52//
53#include "AliTRDCalibChamberStatus.h"
54
55//functios, implementation below
2c61d953 56void SendToAmoreDB(TObject *o, unsigned long32 runNb);
ef7aea93 57
58/* Main routine
59 Arguments: list of DATE raw data files
60*/
61int main(int argc, char **argv) {
62
63 /* magic line from Rene */
64 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
65 "*",
66 "TStreamerInfo",
67 "RIO",
68 "TStreamerInfo()");
69
70 int status;
71
72
73 /* log start of process */
74 printf("TRD DA HALFCHAMBERSTATUS started\n");
75
df7153c8 76 if (argc!=2) {
ef7aea93 77 printf("Wrong number of arguments\n");
78 return -1;
79 }
80
81
df7153c8 82 /* define data source : this is argument 1 */
83 status=monitorSetDataSource( argv[1] );
84 if (status!=0) {
85 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
86 return -1;
87 }
88
89
90 /* declare monitoring program */
91 status=monitorDeclareMp( __FILE__ );
92 if (status!=0) {
93 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
94 return -1;
95 }
96
97
98 /* define wait event timeout - 1s max */
99 monitorSetNowait();
100 monitorSetNoWaitNetworkTimeout(1000);
ef7aea93 101
102 /* init some counters */
103 int nevents_total=0;
104 int nevents =0;
105
106 //Instance of AliCDBManager: needed by AliTRDRawStream
107 //AliCDBManager *man = AliCDBManager::Instance();
108 //man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
109 //man->SetRun(0);
110 // AliTRDCalibPadStatus object
111 AliTRDCalibChamberStatus calipad = AliTRDCalibChamberStatus();
112 calipad.Init();
fd50bb14 113
2c61d953 114 unsigned long32 runNb=0; //run number
ef7aea93 115
116 // setting
fd50bb14 117 //AliTRDrawFastStream::DisableSkipData();
df7153c8 118 AliLog::SetGlobalLogLevel(AliLog::kFatal);
119
120 /* read the file until EOF */
121 for(;;) {
122 struct eventHeaderStruct *event;
123 eventTypeType eventT;
124
125 /* check shutdown condition */
126 if (daqDA_checkShutdown()) {break;}
127
128 /* get next event */
129 status=monitorGetEventDynamic((void **)&event);
130 if (status==MON_ERR_EOF) {
131 printf("End of File detected\n");
132 break; /* end of monitoring file has been reached */
133 }
ef7aea93 134 if (status!=0) {
df7153c8 135 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
136 break;
ef7aea93 137 }
df7153c8 138
139 /* retry if got no event */
140 if (event==NULL) {
141 continue;
142 }
143
144 /* use event - here, just write event id to result file */
145 eventT=event->eventType;
146
147 if(eventT==PHYSICS_EVENT){
ef7aea93 148
df7153c8 149 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
150 rawReader->Select("TRD");
151
068b874f 152 calipad.ProcessEvent((AliRawReader *) rawReader,nevents);
df7153c8 153 nevents++;
154 delete rawReader;
ef7aea93 155
df7153c8 156 }
157
158 nevents_total++;
159
160 // get the run number
2c61d953 161 runNb = event->eventRunNb;
df7153c8 162
163 /* free resources */
164 free(event);
165
166 /* exit when last event received, no need to wait for TERM signal */
167 if (eventT==END_OF_RUN) {
168 printf("EOR event detected\n");
169 break;
ef7aea93 170 }
171 }
df7153c8 172
fd50bb14 173 Int_t neventused = calipad.GetNumberEventNotEmpty();
174
ef7aea93 175 /* report progress */
fd50bb14 176 printf("%d events processed and %d used\n",nevents_total,neventused);
df7153c8 177
ef7aea93 178 /* write file in any case to see what happens in case of problems*/
179 TFile *fileTRD = new TFile(RESULT_FILE,"recreate");
180 calipad.AnalyseHisto();
181 calipad.Write("calibchamberstatus");
182 fileTRD->Close();
fd50bb14 183
2c61d953 184
185 /* Send to amore */
186 SendToAmoreDB(&calipad,runNb);
ef7aea93 187
188 /* store the result file on FES */
189 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
190 if (status) {
191 printf("Failed to export file : %d\n",status);
192 return -1;
193 }
ef7aea93 194
195 return status;
196
2c61d953 197}
198void SendToAmoreDB(TObject *o, unsigned long32 runNb)
199{
200 //AMORE
201 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
202 //cheet a little -- temporary solution (hopefully)
203 //
204 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
205 //table in which the calib objects are stored. This table is dropped each time AmoreDA
206 //is initialised. This of course makes a problem if we would like to store different
207 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
208 //the AMORE_DA_NAME env variable is overwritten.
209
210 gSystem->Setenv("AMORE_DA_NAME","TRD-dataHALFCHAMBERSTATUS");
211 //
212 // end cheet
213 TDatime time;
214 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
215
216 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
217 Int_t statusDA=0;
218 statusDA+=amoreDA.Send("DataHalfChamberStatus",o);
219 statusDA+=amoreDA.Send("Info",&info);
220 if ( statusDA!=0 )
221 printf("TRDQAda: Waring: Failed to write one of the calib objects to the AMORE database\n");
222 // reset env var
223 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
068b874f 224}
225
226