FEDRA emulsion software from the OPERA Collaboration
fb2db.cpp File Reference
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <TEnv.h>
#include <TString.h>
#include <TSystem.h>
#include "TOracleServerE2WFB.h"
#include "EdbScanProc.h"
#include "EdbLog.h"
Include dependency graph for fb2db.cpp:

Functions

int AddBrick (EdbFeedback &fb, int BRICK, const char *dir, TEnv &cenv)
 
int AddFeedback (EdbFeedback &fb, const char *fname, TEnv &cenv)
 
int AddList (EdbFeedback &fb, const char *listfile, TEnv &cenv)
 
int CheckList (EdbFeedback &fb, const char *listfile, TEnv &cenv)
 
bool InitDB (EdbFeedback &fb, TEnv &cenv, int do_commit)
 
int main (int argc, char *argv[])
 
int ParseFileName (const char *filename, ULong64_t &brick, ULong64_t &event)
 
int ParseFileName (const char *filename, ULong64_t &brick, ULong64_t &event, TString &dir)
 
void print_help_message ()
 
void set_default (TEnv &cenv)
 
void set_default_BE (TEnv &cenv)
 
void set_default_NA (TEnv &cenv)
 

Function Documentation

◆ AddBrick()

int AddBrick ( EdbFeedback fb,
int  BRICK,
const char *  dir,
TEnv &  cenv 
)
347{
348 fprintf(stderr,"AddBrick started\n");
351 time_t ti = time(NULL);
352
353 /*********** Loading X ray mark sets in global RS to get ZEROX,ZEROY ***********/
354 EdbMarksSet msXG;
355 sproc.ReadMarksSet(msXG,BRICK,"map.XG",'_','S');
356 float ZEROX = msXG.eXmin;
357 float ZEROY = msXG.eYmin;
358
359 /*********** Loading Optical ray mark sets in local (and corrected) RS to get brick dimension ***********/
360 int X_MARKS = cenv.GetValue("fb2db.X_MARKS" , 1);
361
362 EdbMarksSet msOL;
363 if (X_MARKS) sproc.ReadMarksSet(msOL,BRICK,"map.LL",'_','L');
364 else sproc.ReadMarksSet(msOL,BRICK,"map.OL",'_','S');
365 float MINX = msOL.eXmin + ZEROX;
366 float MAXX = msOL.eXmax + ZEROX;
367 float MINY = msOL.eYmin + ZEROY;
368 float MAXY = msOL.eYmax + ZEROY;
369 float MINZ = -72800.;
370 float MAXZ = 0.;
371 float ZEROZ = MAXZ;
372 const char *BS_ID = cenv.GetValue("fb2db.BS_ID" , "'OPERA NA SET 04'");
373
374 char databrick[500];
375 sprintf(databrick,"%d, %f, %f, %f, %f, %f, %f, %s, %d, %f, %f, %f", 1000000+BRICK, MINX, MAXX, MINY, MAXY, MINZ, MAXZ, BS_ID, BRICK, ZEROX, ZEROY, ZEROZ);
376 db.eDB->AddEventBrick(databrick);
377
378 /*********** Getting brick id ***********/
379 int id_eventbrick = db.eDB->GetId_EventBrick( Form("%d",BRICK), BS_ID, 0);
380 Log(1,"fb2db","The brick %d %s is inside database now!\n",id_eventbrick, BS_ID);
381
382 /***********************************/
383 /********** Adding plates **********/
384 /***********************************/
385
386 char filename[255];
387 sprintf(filename,"%s/b%06d/b%06d.geometry",sproc.eProcDirClient.Data(),BRICK,BRICK);
388
389 FILE *fp;
390
391 if ((fp=fopen(filename,"r"))==NULL) {
392 fprintf(stderr,"Sorry, I cannot open the file %s\n",filename); return 0;
393 }
394
395 while (!feof(fp))
396 {
397 int iplate;
398 float z;
399 if (fscanf(fp,"%d %f",&iplate,&z)!=2) continue;
400
401 char dataplate[50];
402 sprintf(dataplate,"%d, %f",iplate, z);
403 db.eDB->AddPlate( id_eventbrick, dataplate);
404 }
405 db.eDB->FinishTransaction();
406
407 time_t tf = time(NULL);
408 fprintf(stderr,"AddBrick completed\n");
409 fprintf(stderr,"Elapsed time = %ld seconds\n",tf-ti);
410 return 1;
411}
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
EdbTrackP * ti[10]
Definition: RecDispMC_Profiles.C:54
const char filename[256]
Definition: RecDispNU.C:83
FILE * stderr
Definition: EdbFiducial.h:88
Float_t eXmin
Definition: EdbFiducial.h:96
Float_t eYmin
Definition: EdbFiducial.h:97
Float_t eYmax
Definition: EdbFiducial.h:97
Float_t eXmax
Definition: EdbFiducial.h:96
scanned data processing
Definition: EdbScanProc.h:12
TString eProcDirClient
directory path for root data
Definition: EdbScanProc.h:14
int ReadMarksSet(EdbMarksSet &ms, int brick, const char *filename, char spacer='_', char shape='S')
Definition: EdbScanProc.cxx:3033
Int_t AddPlate(char *data)
Definition: TOracleServerE.cxx:390
EdbScanProc * sproc
Definition: comptonmap.cpp:29
TEnv cenv("emrec")
TOracleServerE * db
Definition: test_oracle.C:8
#define NULL
Definition: nidaqmx.h:84
Definition: RecDispMC.C:95

◆ AddFeedback()

int AddFeedback ( EdbFeedback fb,
const char *  fname,
TEnv &  cenv 
)
327{
328 ULong64_t brickid=0,eventid=0;
329 if( !ParseFileName( fname, brickid, eventid ) ) return 0;
330 if(brickid>0&&brickid<1000000) brickid+=1000000;
331 printf("\n-------------------------------------------------------\n");
332 printf("Load feedback file %s into database for brick %lld, event %lld\n", fname, brickid, eventid);
333 printf("---------------------------------------------------------\n");
334 fb.eEventBrick=brickid;
335 fb.eEvent=eventid;
336 fb.ReadFBFile(fname);
337 if(fb.eERROR!=0) fb.eDB->eDoCommit=0;
338 if(gEDBDEBUGLEVEL>2) fb.PrintFB();
339
340 fb.LoadFBintoDB();
342 return 1;
343}
ULong64_t eEvent
Definition: TOracleServerE2WFB.h:190
int ReadFBFile(const char *file)
Definition: TOracleServerE2WFB.cxx:602
int LoadFBintoDB()
Definition: TOracleServerE2WFB.cxx:465
ULong64_t eEventBrick
Definition: TOracleServerE2WFB.h:189
void PrintFB()
Definition: TOracleServerE2WFB.cxx:720
TOracleServerE2WFB * eDB
Definition: TOracleServerE2WFB.h:184
Int_t eERROR
Definition: TOracleServerE2WFB.h:194
Bool_t eDoCommit
Definition: TOracleServerE2WFB.h:18
Bool_t FinishTransaction()
Definition: TOracleServerE2WFB.cxx:46
int ParseFileName(const char *filename, ULong64_t &brick, ULong64_t &event)
Definition: fb2db.cpp:298
gEDBDEBUGLEVEL
Definition: energy.C:7
const char * fname
Definition: mc2raw.cxx:41

◆ AddList()

int AddList ( EdbFeedback fb,
const char *  listfile,
TEnv &  cenv 
)
268{
269 Log(2,"fb2db::AddList", "started");
270 FILE *f = fopen( listfile, "r" );
271 char str[1024];
272
273 while( fgets( str, sizeof(str), f) )
274 {
275 char fname[1024];
276 if( 1 != sscanf(str,"%s", fname )) {
277 Log(1,"fb2db::AddList","ERROR! bad filename line: %s", str);
278 continue;
279 }
280
281 ULong64_t brickid=0,eventid=0;
282 TString onlinedir;
283 if( !ParseFileName( fname, brickid, eventid, onlinedir ) ) continue;
284 Log(2,"fb2db::ParseFileName","brick = %lld, event = %lld, onlinedir=%s",brickid, eventid,onlinedir.Data());
285
286 if( !fb.eDB->IfEventBrick(1000000+brickid, cenv.GetValue("fb2db.BS_ID" , "'OPERA NA SET 04'") ) )
287 {
288 if( !AddBrick(fb, brickid, onlinedir, cenv) ) return 0;
289 }
290
291 AddFeedback( fb, fname, cenv );
292
293 }
294 return 0;
295}
FILE * f
Definition: RecDispMC.C:150
ULong64_t IfEventBrick(ULong64_t id_eventbrick, const char *id_set)
Definition: TOracleServerE2WFB.cxx:88
int AddBrick(EdbFeedback &fb, int BRICK, const char *dir, TEnv &cenv)
Definition: fb2db.cpp:346
int AddFeedback(EdbFeedback &fb, const char *fname, TEnv &cenv)
Definition: fb2db.cpp:326

◆ CheckList()

int CheckList ( EdbFeedback fb,
const char *  listfile,
TEnv &  cenv 
)
240{
241 Log(3,"fb2db::CheckList","started");
242 FILE *f = fopen( listfile, "r" );
243 if( !f ) Log(1,"fb2db::CheckList","ERROR listfile %s is not found!", listfile);
244 char str[1024];
245
246 const char *BS_ID = cenv.GetValue("fb2db.BS_ID" , "'OPERA NA SET 04'");
247 while( fgets( str, sizeof(str), f) )
248 {
249 char fname[1024];
250 if( 1 != sscanf(str,"%s", fname )) {
251 Log(1,"fb2db::AddList","ERROR! bad filename line: %s", str);
252 continue;
253 }
254 ULong64_t brickid=0,eventid=0;
255 TString onlinedir;
256 if( !ParseFileName( fname, brickid, eventid, onlinedir ) ) continue;
257 Log(2,"fb2db::ParseFileName","brick = %lld, event = %lld, onlinedir=%s",brickid, eventid,onlinedir.Data());
258
259 int id = brickid>1000000? brickid: 1000000+brickid;
260 fb.eDB->IfEventBrick(id,BS_ID);
261 fb.eDB->IfEventRec(id);
262 }
263 return 0;
264}
ULong64_t IfEventRec(ULong64_t id_eventbrick)
Definition: TOracleServerE2WFB.cxx:114

◆ InitDB()

bool InitDB ( EdbFeedback fb,
TEnv &  cenv,
int  do_commit 
)
217{
218 const char *dbname = cenv.GetValue("fb2db.dbname" , "connection_string");
219 const char *username = cenv.GetValue("fb2db.username" , "username");
220 const char *password = cenv.GetValue("fb2db.password" , "password");
221 const char *rdb = cenv.GetValue("fb2db.rdb" , "");
222
223 printf("Init database \t\t%s%s\n", dbname, rdb);
224 if( fb.InitDB( dbname, username, password) ) {
225 fb.eDB->eLab = cenv.GetValue("fb2db.labName" , "NAPOLI");
226 fb.eDB->eLa = cenv.GetValue("fb2db.labN" , "NA");
227 fb.eDB->SetTransactionRW();
228 sscanf( cenv.GetValue("fb2db.id_machine" , "6000000000010002"), "%lld", &(fb.eIdMachine) );
229 sscanf( cenv.GetValue("fb2db.id_programsettings" , "81000100000000087"), "%lld", &(fb.eIdProgramsettings) );
230 sscanf( cenv.GetValue("fb2db.id_requester" , "6000000000100375"), "%lld", &(fb.eIdRequester) );
231 fb.eDB->eDoCommit = do_commit;
232 fb.Print();
233 return 1;
234 }
235 return 0;
236}
ULong64_t eIdMachine
Definition: TOracleServerE2WFB.h:185
int InitDB(const char *conn, const char *user, const char *pwd)
Definition: TOracleServerE2WFB.cxx:457
ULong64_t eIdProgramsettings
Definition: TOracleServerE2WFB.h:186
ULong64_t eIdRequester
Definition: TOracleServerE2WFB.h:187
void Print()
Definition: TOracleServerE2WFB.cxx:440
TString eLa
as "NAPOLI"
Definition: TOracleServerE2WFB.h:20
Int_t SetTransactionRW()
Definition: TOracleServerE2WFB.h:28
TString eLab
Definition: TOracleServerE2WFB.h:19

◆ main()

int main ( int  argc,
char *  argv[] 
)
97{
98 if (argc < 2) { print_help_message(); return 0; }
99
100 TEnv cenv("fb2db");
102 cenv.ReadFile( "fb2db.rootrc" ,kEnvLocal);
103
104 gEDBDEBUGLEVEL = cenv.GetValue("fb2db.EdbDebugLevel" , 1);
105
106 int do_checkbrick=0;
107 int do_addbrick=0, brick=0;
108 char *dir=0;
109 char *lab=0;
110
111 int do_feedback=0;
112 char *fname=0;
113
114 char *listfile=0;
115 int do_addlist=0;
116 int do_checklist=0;
117 int do_commit=0;
118
119 for(int i=1; i<argc; i++ ) {
120
121 char *key = argv[i];
122
123 if(!strncmp(key,"-file=",6))
124 {
125 do_feedback=1;
126 if(strlen(key)>6) fname=key+6;
127 }
128 else if(!strncmp(key,"-addbrick=",10))
129 {
130 if(strlen(key)>10) {
131 brick = atoi(key+10);
132 do_addbrick=1;
133 }
134 }
135 else if(!strncmp(key,"-addlist=",9))
136 {
137 if(strlen(key)>9) {
138 listfile = key+9;
139 do_addlist=1;
140 }
141 }
142 else if(!strncmp(key,"-checklist=",11))
143 {
144 if(strlen(key)>11) {
145 listfile = key+11;
146 do_checklist=1;
147 }
148 }
149 else if(!strncmp(key,"-checkbrick=",12))
150 {
151 if(strlen(key)>12) {
152 brick = atoi(key+12);
153 do_checkbrick=1;
154 }
155 }
156 else if(!strncmp(key,"-online=",8))
157 {
158 if(strlen(key)>8) dir=key+8;
159 }
160 else if(!strncmp(key,"-commit",7))
161 {
162 do_commit=1;
163 }
164 else if(!strncmp(key,"-lab=",5))
165 {
166 lab = key+5;
167 }
168 else if(!strncmp(key,"-v=",3))
169 {
170 gEDBDEBUGLEVEL = atoi(key+3);
171 }
172 }
173
174 if(lab)
175 {
176 if(!strncmp(lab,"NA",2) ) { set_default_NA(cenv); }
177 else if(!strncmp(lab,"BE",2) ) { set_default_BE(cenv); }
178 }
179 cenv.WriteFile("fb2db.save.rootrc");
180
181 EdbFeedback fb;
182 if(do_feedback || do_addbrick || do_addlist || do_checkbrick || do_checklist )
183 {
184 if( !InitDB( fb, cenv, do_commit)) return 0;
185 }
186
187 if(do_feedback)
188 {
189 if(!fname) { print_help_message(); return 0; }
190 AddFeedback( fb, fname, cenv );
191 }
192 else if(do_addbrick)
193 {
194 AddBrick( fb, brick, dir, cenv);
195 }
196 else if( do_addlist )
197 {
198 AddList(fb, listfile, cenv);
199 }
200 else if(do_checkbrick)
201 {
202 const char *BS_ID = cenv.GetValue("fb2db.BS_ID" , "'OPERA NA SET 04'");
203 int id = brick>1000000? brick: 1000000+brick;
204 fb.eDB->IfEventBrick(id,BS_ID);
205 fb.eDB->IfEventRec(id);
206 }
207 else if(do_checklist)
208 {
209 CheckList(fb, listfile, cenv);
210 }
211
212 return 1;
213}
BRICK brick
Definition: RecDispMC.C:103
Definition: TOracleServerE2WFB.h:180
void set_default(TEnv &cenv)
Definition: fb2db.cpp:57
void print_help_message()
Definition: fb2db.cpp:23
void set_default_NA(TEnv &cenv)
Definition: fb2db.cpp:74
bool InitDB(EdbFeedback &fb, TEnv &cenv, int do_commit)
Definition: fb2db.cpp:216
void set_default_BE(TEnv &cenv)
Definition: fb2db.cpp:85
int CheckList(EdbFeedback &fb, const char *listfile, TEnv &cenv)
Definition: fb2db.cpp:239
int AddList(EdbFeedback &fb, const char *listfile, TEnv &cenv)
Definition: fb2db.cpp:267

◆ ParseFileName() [1/2]

int ParseFileName ( const char *  filename,
ULong64_t &  brick,
ULong64_t &  event 
)
299{
300 if( gSystem->AccessPathName(fname) ) {
301 Log(1,"fb2db::ParseFileName","ERROR: can not access file: %s", fname);
302 return 0;
303 }
304 if(2 != sscanf(gSystem->BaseName(fname),"b%lld_e%lld.feedback",&brickid,&eventid)) {
305 Log(1,"Error parsing feedback filename (expected bXXXX_eXXXXX.feedback): %s", fname);
306 return 0;
307 }
308 return 1;
309}

◆ ParseFileName() [2/2]

int ParseFileName ( const char *  filename,
ULong64_t &  brick,
ULong64_t &  event,
TString &  dir 
)
313{
314 if(ParseFileName( fname, brickid, eventid) ) {
315 const char *dir1 = gSystem->DirName(fname);
316 if(!dir1) return 0;
317 const char *dir = gSystem->DirName(dir1);
318 if(!dir) return 0;
319 if( strlen(dir1) < 2 ) return 0;
320 onlinedir=dir;
321 return 1;
322 }
323 return 0;
324}

◆ print_help_message()

void print_help_message ( )
24{
25 cout<< "\nUsage: \n\t fb2db -file=feedback_file [-commit -v=V -lab=LA]\n";
26 cout<< "\t\t Assumed that feedbackfile name is like bBBBB_eEEEE.feedback as b010234_e11293015645.feedback\n";
27 cout<< "\t\t brick id and event id extracted from the file name are used for data insertion into db\n";
28
29 cout<< "\n\t fb2db -addbrick=BRICK -online=onlinedir\n";
30 cout<< "\t\t assumed that in onlinedir/bBRICK there are all necessary files";
31
32 cout<< "\n\t fb2db -checkbrick=BRICK \n";
33 cout<< "\t\t check if the brick structure was already loaded";
34
35 cout<< "\n\t fb2db -addlist=listfile \n";
36 cout<< "\t\t add all feedbacks from the listfile formated like that:\n";
37 cout<< "\t\t /full_path_to_a_valid_brick_directory/bBBBBBBB_eEEEEEEEEE.feedback \n\t\t ...";
38
39 cout<< "\n\t fb2db -checklist=listfile -v=1\n";
40 cout<< "\t\t check for a leested feedbacks if the brick structure and reconstruction are in DB (use -v=1 for compact output)";
41
42 cout<< "\n\n\t-----------------------------------------------------------------------------------------";
43 cout<< "\n\t By default the application is started in test mode and does not commit transactions";
44 cout<< "\n\t TO LOAD DATA USE -commit OPTION";
45 cout<< "\n\t-------------------------------------------------------------------------------------------";
46
47 cout<< "\n\n\t If the input parameters file (fb2db.rootrc) is not present in the current dir - the default";
48 cout<< "\n\t parameters are used. After the execution them are saved into fb2db.save.rootrc file\n";
49
50 cout<< "\n\t Options: \n";
51 cout<< "\t\t -lab=LA default settings for a given lab (now defined for NA,BE) \n";
52 cout<< "\t\t -v=V verbosity level (0-4) \n";
53 cout<<endl;
54}

◆ set_default()

void set_default ( TEnv &  cenv)
58{
59 cenv.SetValue("fb2db.dbname" , "connection_string");
60 cenv.SetValue("fb2db.username" , "username");
61 cenv.SetValue("fb2db.password" , "password");
62 cenv.SetValue("fb2db.rdb" , "");
63 cenv.SetValue("fb2db.X_MARKS" , 1);
64 cenv.SetValue("fb2db.labName" , "LAB");
65 cenv.SetValue("fb2db.labN" , "LA");
66 cenv.SetValue("fb2db.BS_ID" , "'OPERA LA SET XX'");
67 cenv.SetValue("fb2db.id_machine" , "0000000000000000");
68 cenv.SetValue("fb2db.id_programsettings" , "00000000000000000");
69 cenv.SetValue("fb2db.id_requester" , "0000000000000000");
70 cenv.SetValue("fb2db.EdbDebugLevel" , 1);
71}

◆ set_default_BE()

void set_default_BE ( TEnv &  cenv)
86{
87 cenv.SetValue("fb2db.labName" , "BERN");
88 cenv.SetValue("fb2db.labN" , "BE");
89 cenv.SetValue("fb2db.BS_ID" , "'OPERA BE SET 04'");
90 cenv.SetValue("fb2db.id_machine" , "5000000000000022");
91 cenv.SetValue("fb2db.id_programsettings" , "81000100000000087");
92 cenv.SetValue("fb2db.id_requester" , "5000000003280005");
93}

◆ set_default_NA()

void set_default_NA ( TEnv &  cenv)
75{
76 cenv.SetValue("fb2db.labName" , "NAPOLI");
77 cenv.SetValue("fb2db.labN" , "NA");
78 cenv.SetValue("fb2db.BS_ID" , "'OPERA NA SET 04'");
79 cenv.SetValue("fb2db.id_machine" , "6000000000010002");
80 cenv.SetValue("fb2db.id_programsettings" , "81000100000000087");
81 cenv.SetValue("fb2db.id_requester" , "6000000000100375");
82}