]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/TRDHALFCHAMBERSTATUSda.cxx
Updates of the DA for the TRD to export data to AMORE (Raphaelle)
[u/mrichter/AliRoot.git] / TRD / TRDHALFCHAMBERSTATUSda.cxx
1 /*
2
3 Contact: r.bailhache@gsi.de
4 Link:
5 Reference run: 104892
6 Run Type: PHYSICS
7 DA Type: MON
8 Number of events needed: many
9 Input Files: TRD raw files
10 Output Files: trdCalibrationhcs.root
11 Trigger types used: PHYSICS_EVENT
12
13 */
14
15 #define RESULT_FILE  "trdHalfChamberStatus.root"
16 #define FILE_ID "HALFCHAMBERSTATUS"
17
18 extern "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
56 void SendToAmoreDB(TObject *o, unsigned long32 runNb);
57
58 /* Main routine
59       Arguments: list of DATE raw data files
60 */
61 int 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   unsigned long32 runNb=0;      //run number
114
115   // setting
116   AliTRDrawFastStream::DisableSkipData();
117   AliLog::SetGlobalLogLevel(AliLog::kFatal); 
118
119   /* read the file  until EOF */
120   for(;;) {
121     struct eventHeaderStruct *event;
122     eventTypeType eventT;
123     
124     /* check shutdown condition */
125     if (daqDA_checkShutdown()) {break;}
126     
127     /* get next event */
128     status=monitorGetEventDynamic((void **)&event);
129     if (status==MON_ERR_EOF) {
130       printf("End of File detected\n");
131       break; /* end of monitoring file has been reached */
132     }
133     if (status!=0) {
134       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
135       break;
136     }
137     
138     /* retry if got no event */
139     if (event==NULL) {
140       continue;
141     }
142     
143     /* use event - here, just write event id to result file */
144     eventT=event->eventType;
145     
146     if(eventT==PHYSICS_EVENT){
147       
148       AliRawReader *rawReader = new AliRawReaderDate((void*)event);
149       rawReader->Select("TRD");
150       
151       calipad.ProcessEvent((AliRawReader *) rawReader,nevents);
152       nevents++;
153       delete rawReader;
154       
155     }
156     
157     nevents_total++;
158     
159     // get the run number
160     runNb = event->eventRunNb;
161     
162     /* free resources */
163     free(event);
164     
165     /* exit when last event received, no need to wait for TERM signal */
166     if (eventT==END_OF_RUN) {
167       printf("EOR event detected\n");
168       break;
169     }
170   }
171   
172
173   /* report progress */
174   printf("%d events processed and %d used\n",nevents_total,nevents);
175   
176   /* write file in any case to see what happens in case of problems*/
177   TFile *fileTRD = new TFile(RESULT_FILE,"recreate");
178   calipad.AnalyseHisto();
179   calipad.Write("calibchamberstatus");
180   fileTRD->Close();   
181
182   /* Send to amore */
183   SendToAmoreDB(&calipad,runNb);
184      
185   /* store the result file on FES */
186   status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
187   if (status) {
188     printf("Failed to export file : %d\n",status);
189     return -1;
190   }
191
192   
193   return status;
194
195 }
196 void SendToAmoreDB(TObject *o, unsigned long32 runNb)
197 {
198   //AMORE
199   const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
200   //cheet a little -- temporary solution (hopefully)
201   //
202   //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
203   //table in which the calib objects are stored. This table is dropped each time AmoreDA
204   //is initialised. This of course makes a problem if we would like to store different
205   //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
206   //the AMORE_DA_NAME env variable is overwritten.
207   
208   gSystem->Setenv("AMORE_DA_NAME","TRD-dataHALFCHAMBERSTATUS");
209   //
210   // end cheet
211   TDatime time;
212   TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
213   
214   amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
215   Int_t statusDA=0;
216   statusDA+=amoreDA.Send("DataHalfChamberStatus",o);
217   statusDA+=amoreDA.Send("Info",&info);
218   if ( statusDA!=0 )
219     printf("TRDQAda: Waring: Failed to write one of the calib objects to the AMORE database\n");
220   // reset env var
221   if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
222 }