3 Contact: r.bailhache@gsi.de
8 Number of events needed: many
9 Input Files: TRD raw files
10 Output Files: trdCalibrationhcs.root
11 Trigger types used: PHYSICS_EVENT
15 #define RESULT_FILE "trdHalfChamberStatus.root"
16 #define FILE_ID "HALFCHAMBERSTATUS"
31 #include <TStopwatch.h>
33 #include "TPluginManager.h"
38 #include "AliRawReader.h"
39 #include "AliRawReaderDate.h"
40 #include "AliTRDrawFastStream.h"
41 #include "AliTRDrawStreamBase.h"
43 //#include "AliCDBManager.h"
51 // AliRoot TRD calib classes
53 #include "AliTRDCalibChamberStatus.h"
55 //functios, implementation below
56 void SendToAmoreDB(TObject *o, unsigned long32 runNb);
59 Arguments: list of DATE raw data files
61 int main(int argc, char **argv) {
63 /* magic line from Rene */
64 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
73 /* log start of process */
74 printf("TRD DA HALFCHAMBERSTATUS started\n");
77 printf("Wrong number of arguments\n");
82 /* define data source : this is argument 1 */
83 status=monitorSetDataSource( argv[1] );
85 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
90 /* declare monitoring program */
91 status=monitorDeclareMp( __FILE__ );
93 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
98 /* define wait event timeout - 1s max */
100 monitorSetNoWaitNetworkTimeout(1000);
102 /* init some counters */
106 //Instance of AliCDBManager: needed by AliTRDRawStream
107 //AliCDBManager *man = AliCDBManager::Instance();
108 //man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
110 // AliTRDCalibPadStatus object
111 AliTRDCalibChamberStatus calipad = AliTRDCalibChamberStatus();
113 unsigned long32 runNb=0; //run number
116 AliTRDrawFastStream::DisableSkipData();
117 AliLog::SetGlobalLogLevel(AliLog::kFatal);
119 /* read the file until EOF */
121 struct eventHeaderStruct *event;
122 eventTypeType eventT;
124 /* check shutdown condition */
125 if (daqDA_checkShutdown()) {break;}
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 */
134 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
138 /* retry if got no event */
143 /* use event - here, just write event id to result file */
144 eventT=event->eventType;
146 if(eventT==PHYSICS_EVENT){
148 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
149 rawReader->Select("TRD");
151 calipad.ProcessEvent((AliRawReader *) rawReader,nevents);
159 // get the run number
160 runNb = event->eventRunNb;
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");
173 /* report progress */
174 printf("%d events processed and %d used\n",nevents_total,nevents);
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");
183 SendToAmoreDB(&calipad,runNb);
185 /* store the result file on FES */
186 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
188 printf("Failed to export file : %d\n",status);
196 void SendToAmoreDB(TObject *o, unsigned long32 runNb)
199 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
200 //cheet a little -- temporary solution (hopefully)
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.
208 gSystem->Setenv("AMORE_DA_NAME","TRD-dataHALFCHAMBERSTATUS");
212 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
214 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
216 statusDA+=amoreDA.Send("DataHalfChamberStatus",o);
217 statusDA+=amoreDA.Send("Info",&info);
219 printf("TRDQAda: Waring: Failed to write one of the calib objects to the AMORE database\n");
221 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);