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();
114 unsigned long32 runNb=0; //run number
117 //AliTRDrawFastStream::DisableSkipData();
118 AliLog::SetGlobalLogLevel(AliLog::kFatal);
120 /* read the file until EOF */
122 struct eventHeaderStruct *event;
123 eventTypeType eventT;
125 /* check shutdown condition */
126 if (daqDA_checkShutdown()) {break;}
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 */
135 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
139 /* retry if got no event */
144 /* use event - here, just write event id to result file */
145 eventT=event->eventType;
147 if(eventT==PHYSICS_EVENT){
149 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
150 rawReader->Select("TRD");
152 calipad.ProcessEvent((AliRawReader *) rawReader,nevents);
160 // get the run number
161 runNb = event->eventRunNb;
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");
173 Int_t neventused = calipad.GetNumberEventNotEmpty();
175 /* report progress */
176 printf("%d events processed and %d used\n",nevents_total,neventused);
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");
186 SendToAmoreDB(&calipad,runNb);
188 /* store the result file on FES */
189 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
191 printf("Failed to export file : %d\n",status);
198 void SendToAmoreDB(TObject *o, unsigned long32 runNb)
201 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
202 //cheet a little -- temporary solution (hopefully)
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.
210 gSystem->Setenv("AMORE_DA_NAME","TRD-dataHALFCHAMBERSTATUS");
214 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
216 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
218 statusDA+=amoreDA.Send("DataHalfChamberStatus",o);
219 statusDA+=amoreDA.Send("Info",&info);
221 printf("TRDQAda: Waring: Failed to write one of the calib objects to the AMORE database\n");
223 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);