Update for Ds
[u/mrichter/AliRoot.git] / ITS / ITSSPDVertexDiamondda.cxx
CommitLineData
eb35e591 1/*
2Contact: cvetan.cheshkov@cern.ch
9141d382 3Link: http://alisoft.cern.ch/viewvc/trunk/ITS/ITSSPDVertexDiamondda.cxx?root=AliRoot&view=log , /afs/cern.ch/user/c/cheshkov/public/ITS/VD_da_test.date , /afs/cern.ch/user/c/cheshkov/public/08000058338016.30.root.date.gz
6bf5b296 4Reference Run: 58338
eb35e591 5Run Type: PHYSICS
6DA Type: MON
049f9cac 7Number of events needed: 100
9141d382 8Input Files: GRP/Geometry/Data , ITS/Align/Data , spd_noisy_ocdb , spd_dead_ocdb , TRIGGER/SPD/PITConditions (all the files are taken from SPD daqDetDB)
6bf5b296 9Output Files: SPDVertexDiamondDA.root
9141d382 10Trigger types used: PHYSICS, SPD-F0
eb35e591 11*/
12
eb35e591 13#define OUTPUT_FILE "SPDVertexDiamondDA.root"
eb35e591 14#define N_EVENTS_AUTOSAVE 50
eb35e591 15
16extern "C" {
17#include "daqDA.h"
18}
19
20#include "event.h"
21#include "monitor.h"
22
55c5e86d 23#ifdef ALI_AMORE
24#include <AmoreDA.h>
308c2f7c 25//int amore::da::Updated(char const*) {}
55c5e86d 26#endif
27
eb35e591 28#include <TPluginManager.h>
29#include <TROOT.h>
cf0b1cea 30#include <TH1.h>
31#include <TH2.h>
6bf5b296 32#include <TSystem.h>
ee0a8262 33#include <TGeoGlobalMagField.h>
eb35e591 34
e1f6be44 35#include "AliLog.h"
ee0a8262 36#include "AliMagF.h"
eb35e591 37#include "AliRawReaderDate.h"
eb35e591 38#include "AliCDBManager.h"
cf0b1cea 39#include "AliITSMeanVertexer.h"
eb35e591 40
41int main(int argc, char **argv) {
42
43 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
44 "*",
45 "TStreamerInfo",
46 "RIO",
47 "TStreamerInfo()");
eb35e591 48
49 int status;
50 if (argc<2) {
51 printf("Wrong number of arguments\n");
52 return -1;
53 }
54
55 /* define data source : this is argument 1 */
56 status=monitorSetDataSource( argv[1] );
57 if (status!=0) {
58 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
59 return -1;
60 }
61
62 /* declare monitoring program */
63 status=monitorDeclareMp( __FILE__ );
64 if (status!=0) {
65 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
66 return -1;
67 }
68
69 /* define wait event timeout - 1s max */
70 monitorSetNowait();
71 monitorSetNoWaitNetworkTimeout(1000);
72
73 /* log start of process */
74 printf("Vertex-Diamond SPD DA started\n");
75
76 /* init some counters */
77 int nevents_with_vertex = 0;
78 int nevents_physics=0;
79 int nevents_total=0;
80
81 struct eventHeaderStruct *event;
82 eventTypeType eventT;
83
84 // Get run number
85 if (getenv("DATE_RUN_NUMBER")==0) {
86 printf("DATE_RUN_NUMBER not properly set.\n");
87 return -1;
88 }
89 int runNr = atoi(getenv("DATE_RUN_NUMBER"));
90
6bf5b296 91 // Get the necessary OCDB files from the DAQ detector DB
92 if (gSystem->AccessPathName("localOCDB/GRP/Geometry/Data",kFileExists)) {
93 if (gSystem->mkdir("localOCDB/GRP/Geometry/Data",kTRUE) != 0) {
94 printf("Failed to create directory: localOCDB/GRP/Geometry/Data");
95 return -1;
96 }
97 }
98 status = daqDA_DB_getFile("GRP/Geometry/Data","localOCDB/GRP/Geometry/Data/Run0_999999999_v0_s0.root");
99 if (status) {
100 printf("Failed to get geometry file (GRP/Geometry/Data) from DAQdetDB, status=%d\n", status);
101 return -1;
102 }
103
104 if (gSystem->AccessPathName("localOCDB/ITS/Align/Data",kFileExists)) {
105 if (gSystem->mkdir("localOCDB/ITS/Align/Data",kTRUE) != 0) {
106 printf("Failed to create directory: localOCDB/ITS/Align/Data");
107 return -1;
108 }
109 }
110 status = daqDA_DB_getFile("ITS/Align/Data","localOCDB/ITS/Align/Data/Run0_999999999_v0_s0.root");
111 if (status) {
112 printf("Failed to get its-alignment file (ITS/Align/Data) from DAQdetDB, status=%d\n", status);
113 return -1;
114 }
115
116 if (gSystem->AccessPathName("localOCDB/ITS/Calib/SPDNoisy",kFileExists)) {
117 if (gSystem->mkdir("localOCDB/ITS/Calib/SPDNoisy",kTRUE) != 0) {
118 printf("Failed to create directory: localOCDB/ITS/Calib/SPDNoisy");
119 return -1;
120 }
121 }
122 status = daqDA_DB_getFile("spd_noisy_ocdb","localOCDB/ITS/Calib/SPDNoisy/Run0_999999999_v0_s0.root");
123 if (status) {
124 printf("Failed to get spd file (spd_noisy_ocdb) from DAQdetDB, status=%d\n", status);
125 return -1;
126 }
127
128 if (gSystem->AccessPathName("localOCDB/ITS/Calib/SPDDead",kFileExists)) {
129 if (gSystem->mkdir("localOCDB/ITS/Calib/SPDDead",kTRUE) != 0) {
130 printf("Failed to create directory: localOCDB/ITS/Calib/SPDDead");
131 return -1;
132 }
133 }
134 status = daqDA_DB_getFile("spd_dead_ocdb","localOCDB/ITS/Calib/SPDDead/Run0_999999999_v0_s0.root");
135 if (status) {
136 printf("Failed to get spd file (spd_dead_ocdb) from DAQdetDB, status=%d\n", status);
137 return -1;
138 }
139
9141d382 140 if (gSystem->AccessPathName("localOCDB/TRIGGER/SPD/PITConditions",kFileExists)) {
141 if (gSystem->mkdir("localOCDB/TRIGGER/SPD/PITConditions",kTRUE) != 0) {
142 printf("Failed to create directory: localOCDB/TRIGGER/SPD/PITConditions");
143 return -1;
144 }
145 }
146 status = daqDA_DB_getFile("TRIGGER/SPD/PITConditions","localOCDB/TRIGGER/SPD/PITConditions/Run0_999999999_v0_s0.root");
147 if (status) {
148 printf("Failed to get spd trigger file (TRIGGER/SPD/PITConditions) from DAQdetDB, status=%d\n", status);
149 return -1;
150 }
2a16d0d6 151
152 status = daqDA_DB_getFile("mfchebKGI_sym.root","localOCDB/mfchebKGI_sym.root");
153 if (status) {
154 printf("Failed to get spd file (mfchebKGI_sym.root) from DAQdetDB, status=%d\n", status);
155 return -1;
156 }
bdffed96 157
eb35e591 158 // Global initializations
ee0a8262 159
160 // The B filed is required in AliITSClusterFinderV2SPD
161 // for the Lorentz angle correction. B set to 0.
2a16d0d6 162 TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", 0., 0., AliMagF::k5kGUniform,AliMagF::kBeamTypeAA,-1,2,15,"localOCDB/mfchebKGI_sym.root"));
e1f6be44 163 AliLog::SetGlobalLogLevel(AliLog::kError);
eb35e591 164 AliCDBManager *man = AliCDBManager::Instance();
9141d382 165 man->SetDefaultStorage("local://localOCDB");
eb35e591 166 man->SetRun(runNr);
eb35e591 167
37add1d1 168 // Init mean vertexer
169 AliITSMeanVertexer *mv = new AliITSMeanVertexer();
170 if (!mv->Init()) {
171 printf("Initialization of mean vertexer object failed ! Check the log for details");
172 return -1;
173 }
eb35e591 174
55c5e86d 175 // Initialization of AMORE sender
176#ifdef ALI_AMORE
177 amore::da::AmoreDA vtxAmore(amore::da::AmoreDA::kSender);
178#endif
eb35e591 179 /* main loop (infinite) */
180 for(;;) {
181
182 /* check shutdown condition */
183 if (daqDA_checkShutdown()) {break;}
184
185 /* get next event (blocking call until timeout) */
186 status=monitorGetEventDynamic((void **)&event);
187 if (status==MON_ERR_EOF) {
188 printf ("End of File detected\n");
189 break; /* end of monitoring file has been reached */
190 }
191
192 if (status!=0) {
193 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
194 break;
195 }
196
197 /* retry if got no event */
198 if (event==NULL) {
199 continue;
200 }
201
202 nevents_total++;
203 eventT=event->eventType;
204 switch (event->eventType){
205
206 /* START OF RUN */
207 case START_OF_RUN:
208 break;
209 /* END START OF RUN */
210
211 /* END OF RUN */
212 case END_OF_RUN:
213 break;
214
215 case PHYSICS_EVENT:
216 nevents_physics++;
217 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
218
37add1d1 219 // Run mean-vertexer reco
220 if (mv->Reconstruct(rawReader)) nevents_with_vertex++;
eb35e591 221
37add1d1 222 // Auto save
6bf5b296 223 if ((nevents_physics%N_EVENTS_AUTOSAVE) == 0) {
37add1d1 224 mv->WriteVertices(OUTPUT_FILE);
eb35e591 225
6bf5b296 226#ifdef ALI_AMORE
227 // send the histos to AMORE pool
228 printf("AMORE send status: %d\n",vtxAmore.Send(mv->GetVertexXY()->GetName(),mv->GetVertexXY()));
229 printf("AMORE send status: %d\n",vtxAmore.Send(mv->GetVertexZ()->GetName(),mv->GetVertexZ()));
230#endif
231 }
232
eb35e591 233 delete rawReader;
eb35e591 234 }
235
236 /* free resources */
237 free(event);
238
239 /* exit when last event received, no need to wait for TERM signal */
240 if (eventT==END_OF_RUN) {
241 printf("EOR event detected\n");
242 break;
243 }
244 }
eb35e591 245
37add1d1 246 mv->WriteVertices(OUTPUT_FILE);
eb35e591 247
55c5e86d 248#ifdef ALI_AMORE
249 // send the histos to AMORE pool
cf0b1cea 250 printf("AMORE send status: %d\n",vtxAmore.Send(mv->GetVertexXY()->GetName(),mv->GetVertexXY()));
251 printf("AMORE send status: %d\n",vtxAmore.Send(mv->GetVertexZ()->GetName(),mv->GetVertexZ()));
55c5e86d 252#endif
253
37add1d1 254 delete mv;
eb35e591 255
256 /* write report */
257 printf("Run #%s, received %d events with vertex, out of %d physics and out of %d total events\n",getenv("DATE_RUN_NUMBER"),nevents_with_vertex,nevents_physics,nevents_total);
258
259 status=0;
260
261 /* export file to FXS */
262 if (daqDA_FES_storeFile(OUTPUT_FILE, "VertexDiamond")) {
263 status=-2;
264 }
265
266 return status;
267}