]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TRD/TRDHALFCHAMBERSTATUSda.cxx
New MFT analysis tools
[u/mrichter/AliRoot.git] / TRD / TRDHALFCHAMBERSTATUSda.cxx
... / ...
CommitLineData
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"
34#include "TSystem.h"
35//
36// AliRoot includes
37//
38#include "AliRawReader.h"
39#include "AliRawReaderDate.h"
40//#include "AliTRDrawFastStream.h"
41//#include "AliTRDrawStreamBase.h"
42#include "AliLog.h"
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
56void SendToAmoreDB(TObject *o, unsigned long32 runNb);
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
76 if (argc!=2) {
77 printf("Wrong number of arguments\n");
78 return -1;
79 }
80
81
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);
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();
113
114 unsigned long32 runNb=0; //run number
115
116 // setting
117 //AliTRDrawFastStream::DisableSkipData();
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 }
134 if (status!=0) {
135 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
136 break;
137 }
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){
148
149 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
150 rawReader->Select("TRD");
151
152 calipad.ProcessEvent((AliRawReader *) rawReader,nevents);
153 nevents++;
154 delete rawReader;
155
156 }
157
158 nevents_total++;
159
160 // get the run number
161 runNb = event->eventRunNb;
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;
170 }
171 }
172
173 Int_t neventused = calipad.GetNumberEventNotEmpty();
174
175 /* report progress */
176 printf("%d events processed and %d used\n",nevents_total,neventused);
177
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();
183
184
185 /* Send to amore */
186 SendToAmoreDB(&calipad,runNb);
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 }
194
195 return status;
196
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);
224}
225
226