/[PAMELA software]/DarthVader/RunInfo/src/RunInfo.cpp
ViewVC logotype

Annotation of /DarthVader/RunInfo/src/RunInfo.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (hide annotations) (download)
Fri Jan 29 05:49:27 2010 UTC (14 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: v9r00, v9r01
Changes since 1.18: +3 -3 lines
Check I/O problems while getting entry

1 mocchiut 1.1 //
2     #include <sstream>
3     //
4     #include <TObject.h>
5 mocchiut 1.8 #include <TChain.h>
6 mocchiut 1.1 #include <TSystem.h>
7 mocchiut 1.8 #include <TSystemFile.h>
8     #include <TArrayI.h>
9 mocchiut 1.1 #include <TFile.h>
10     #include <TTree.h>
11     #include <TDirectory.h>
12     #include <TSQLServer.h>
13     #include <TSQLRow.h>
14     #include <TSQLResult.h>
15     //
16     #include <GLTables.h>
17     #include <RunInfo.h>
18     ClassImp(SoftInfo);
19     ClassImp(ItoRunInfo);
20     //
21     using namespace std;
22     //
23    
24     SoftInfo::SoftInfo() {
25 mocchiut 1.16 Clear();
26 mocchiut 1.1 }
27    
28 mocchiut 1.17 void SoftInfo::Clear(Option_t *t){
29 mocchiut 1.8 TRIG_ver = "";
30     TOF_ver = "";
31     AC_ver = "";
32     TRK_ver = "";
33     ORB_ver = "";
34     CAL_ver = "";
35     ND_ver = "";
36     S4_ver = "";
37 mocchiut 1.14 DV_ver = "";
38 mocchiut 1.8 }
39    
40 mocchiut 1.14 UInt_t SoftInfo::GetSWinfo(TString Detector){
41     TString sver;
42     UInt_t version = 0;
43     if ( !strcmp(Detector.Data(),"TRIG") ){
44     sver = TRIG_ver;
45     };
46     if ( !strcmp(Detector.Data(),"TOF") ){
47     sver = TOF_ver;
48     };
49     if ( !strcmp(Detector.Data(),"AC") ){
50     sver = AC_ver;
51     };
52     if ( !strcmp(Detector.Data(),"TRK") ){
53     sver = TRK_ver;
54     };
55     if ( !strcmp(Detector.Data(),"CALO") ){
56     sver = CAL_ver;
57     };
58     if ( !strcmp(Detector.Data(),"S4") ){
59     sver = S4_ver;
60     };
61     if ( !strcmp(Detector.Data(),"DV") ){
62     sver = DV_ver;
63     };
64     if ( !strcmp(Detector.Data(),"ND") ){
65     sver = ND_ver;
66     };
67     if ( !strcmp(Detector.Data(),"ORB") ){
68     sver = ORB_ver;
69     };
70     sver.ReplaceAll("v",1," ",1);
71     sver.ReplaceAll("r",1," ",1);
72     version = (UInt_t)sver.Atoi();
73     return(version);
74     };
75 mocchiut 1.8
76 pam-fi 1.6 /**
77     * Fills a struct cSoftInfo with values from a SoftInfo object (to put data into a F77 common).
78     */
79     void SoftInfo::GetLevel2Struct(cSoftInfo *l2) const{
80     l2->FillTrigWith(TRIG_ver);
81     l2->FillTofWith(TOF_ver);
82     l2->FillAcWith(AC_ver);
83     l2->FillTrkWith(TRK_ver);
84     l2->FillOrbWith(ORB_ver);
85     l2->FillCalWith(CAL_ver);
86     l2->FillNdWith(ND_ver);
87     l2->FillS4With(S4_ver);
88     }
89     /***********************/
90    
91 mocchiut 1.1 ItoRunInfo::ItoRunInfo() {
92     reprocessing = false;
93     updating = false;
94     isreadonly = true;
95     first_file_entry = 0;
96     last_file_entry = 0;
97 mocchiut 1.8 file_entries = 0;
98     totnorun = 0;
99     this->GL_RUN::Clear();
100 mocchiut 1.1 version = new SoftInfo();
101     norun = 0;
102 mocchiut 1.8 runlist = new TArrayI(500);
103     file = NULL;
104 mocchiut 1.1 newtree = new TTree();
105     }
106    
107     ItoRunInfo::ItoRunInfo(TFile *processFl){
108     //
109     file=(TFile*)processFl;
110     dbc=NULL;
111     processFolder = "";
112 mocchiut 1.8 idRun = 0;
113 mocchiut 1.1 Detector = "NONE";
114     //
115     reprocessing = false;
116     updating = false;
117     first_file_entry = 0;
118     last_file_entry = 0;
119 mocchiut 1.8 file_entries = 0;
120 mocchiut 1.1 version = new SoftInfo();
121 mocchiut 1.13 // glrun = new GL_RUN();
122 mocchiut 1.1 norun = 0;
123     totnorun = 0;
124 mocchiut 1.8 runlist = new TArrayI(500);
125     //
126     }
127    
128    
129    
130 mocchiut 1.14 TChain *ItoRunInfo::GetRunTree(TList *fl){
131 mocchiut 1.8 //
132 mocchiut 1.13 TChain *Tout = new TChain("Run");
133 mocchiut 1.8 // loop over files and create chains
134     TIter next(fl);
135     TSystemFile *questo = 0;
136     while ( (questo = (TSystemFile*) next()) ) {
137     TString name = questo->GetName();
138 mocchiut 1.13 Tout->Add(name);
139 mocchiut 1.8 };
140     //
141 mocchiut 1.13 Tout->SetBranchAddress("RunInfo", GetPointerToRI());
142     printf("Run : set branch address RunInfo\n");
143     Tout->SetBranchAddress("SoftInfo", GetPointerToSI());
144     printf("Software : set branch address SoftInfo\n");
145 mocchiut 1.8 //
146     return Tout;
147 mocchiut 1.1 //
148     }
149    
150     ItoRunInfo::ItoRunInfo(TSQLServer *db, TFile *processFl, TString processFld){
151     //
152     file=(TFile*)processFl;
153     dbc=(TSQLServer*)db;
154     processFolder = processFld;
155     //
156     reprocessing = false;
157     updating = false;
158     first_file_entry = 0;
159     last_file_entry = 0;
160 mocchiut 1.8 file_entries = 0;
161 mocchiut 1.1 version = new SoftInfo();
162     norun = 0;
163     totnorun = 0;
164 mocchiut 1.8 runlist = new TArrayI(500);
165     //
166     }
167    
168     void ItoRunInfo::CopyFromTo(GL_RUN *glrun,GL_RUN *newrun,SoftInfo *sinfo, SoftInfo *newver){
169 mocchiut 1.1 //
170 mocchiut 1.8 if ( glrun && newrun ){
171     //
172 mocchiut 1.9 // printf("copy \n");
173     //
174 mocchiut 1.8 newrun->ID = glrun->ID ;
175     newrun->ID_RUN_FRAG = glrun-> ID_RUN_FRAG ;
176     newrun->ID_ROOT_L0 = glrun->ID_ROOT_L0 ;
177     newrun->ID_ROOT_L2 = glrun->ID_ROOT_L2 ;
178     newrun->RUNHEADER_TIME = glrun->RUNHEADER_TIME ;
179     newrun->RUNTRAILER_TIME = glrun->RUNTRAILER_TIME ;
180     newrun->EV_FROM = glrun->EV_FROM ;
181     newrun->EV_TO = glrun->EV_TO ;
182     newrun->TRK_CALIB_USED = glrun->TRK_CALIB_USED ;
183     newrun->EFF_WRK_SCHEDULE = glrun->EFF_WRK_SCHEDULE ;
184     newrun->PRH_VAR_TRG_MODE_A = glrun->PRH_VAR_TRG_MODE_A ;
185     newrun->PRH_VAR_TRG_MODE_B = glrun->PRH_VAR_TRG_MODE_B ;
186     newrun->ACQ_BUILD_INFO =glrun->ACQ_BUILD_INFO ;
187     newrun->ACQ_VAR_INFO = glrun->ACQ_VAR_INFO ;
188     newrun->RUNHEADER_OBT = glrun->RUNHEADER_OBT ;
189     newrun->RUNTRAILER_OBT = glrun->RUNTRAILER_OBT ;
190     newrun->RUNHEADER_PKT = glrun->RUNHEADER_PKT ;
191     newrun->RUNTRAILER_PKT = glrun->RUNTRAILER_PKT ;
192     newrun->NEVENTS = glrun->NEVENTS ;
193     newrun->LAST_TIMESYNC = glrun->LAST_TIMESYNC ;
194     newrun->OBT_TIMESYNC = glrun->OBT_TIMESYNC ;
195     newrun->COMPILATIONTIMESTAMP = glrun->COMPILATIONTIMESTAMP ;
196     newrun->FAV_WRK_SCHEDULE = glrun->FAV_WRK_SCHEDULE ;
197     newrun->RM_ACQ_AFTER_CALIB = glrun->RM_ACQ_AFTER_CALIB ;
198     newrun->RM_ACQ_SETTING_MODE = glrun->RM_ACQ_SETTING_MODE ;
199     newrun->PKT_COUNTER = glrun->PKT_COUNTER ;
200     newrun->PKT_READY_COUNTER = glrun->PKT_READY_COUNTER ;
201     newrun->TRK_CALIB_USED = glrun->TRK_CALIB_USED ;
202     newrun->CAL_DSP_MASK = glrun->CAL_DSP_MASK ;
203     newrun->BOOT_NUMBER = glrun->BOOT_NUMBER ;
204 mocchiut 1.18 newrun->PHYSENDRUN_MASK_S3S2S12 = glrun->PHYSENDRUN_MASK_S3S2S12 ;
205     newrun->PHYSENDRUN_MASK_S11CRC = glrun->PHYSENDRUN_MASK_S11CRC ;
206 mocchiut 1.8 newrun->VALIDATION = glrun->VALIDATION ;
207     //
208     };
209     //
210     if ( newver && sinfo ){
211     //
212     newver->TRIG_ver = sinfo->TRIG_ver;
213     newver->TOF_ver = sinfo->TOF_ver;
214     newver->AC_ver = sinfo->AC_ver;
215     newver->TRK_ver = sinfo->TRK_ver;
216     newver->ORB_ver = sinfo->ORB_ver;
217     newver->CAL_ver = sinfo->CAL_ver;
218     newver->S4_ver = sinfo->S4_ver;
219 mocchiut 1.14 newver->DV_ver = sinfo->DV_ver;
220 mocchiut 1.8 newver->ND_ver = sinfo->ND_ver;
221     //
222     };
223 mocchiut 1.1 }
224    
225 mocchiut 1.8 Int_t ItoRunInfo::Update(UInt_t run, TString Detector, TString Version){
226 mocchiut 1.1 //
227     isreadonly = false;
228     idRun = run;
229     //
230 mocchiut 1.10 Bool_t debug = false;
231 mocchiut 1.1 //
232     Bool_t ismydir = false;
233     //
234     if ( !strcmp(processFolder.Data(),"") ){
235     processFolder = "runinfoFolder";
236     ismydir = true;
237     };
238     //
239     GL_RUN *oldrun = new GL_RUN();
240     GL_RUN *newrun = new GL_RUN();
241     SoftInfo *oldver = new SoftInfo();
242     SoftInfo *newver = new SoftInfo();
243     //
244 mocchiut 1.8 this->GL_RUN::Clear();
245     version->Clear();
246 mocchiut 1.1 //
247     norun = 0;
248     //
249     Bool_t found = false;
250     Int_t error = 0;
251     //
252     TTree *oldtree = 0;
253     //
254     // Try to get the tree Run in the processed file
255     //
256     oldtree = (TTree*)file->Get("Run");
257     //
258     // Look for detector's versions if we are updating a single detector
259     //
260     if ( debug ) printf("Detector -%s- \n",Detector.Data());
261     if ( !strcmp(Detector.Data(),"NONE") ){
262     version->TRIG_ver = Version;
263     version->TOF_ver = Version;
264     version->AC_ver = Version;
265     version->TRK_ver = Version;
266     version->ORB_ver = Version;
267     version->CAL_ver = Version;
268     version->S4_ver = Version;
269 mocchiut 1.14 version->DV_ver = Version;
270 mocchiut 1.1 version->ND_ver = Version;
271     } else {
272     if ( !strcmp(Detector.Data(),"TRIG") ) version->TRIG_ver = Version;
273     if ( !strcmp(Detector.Data(),"TOF") ) version->TOF_ver = Version;
274     if ( !strcmp(Detector.Data(),"AC") ) version->AC_ver = Version;
275     if ( !strcmp(Detector.Data(),"TRK") ) version->TRK_ver = Version;
276     if ( !strcmp(Detector.Data(),"CALO") ) version->CAL_ver = Version;
277     if ( !strcmp(Detector.Data(),"S4") ) version->S4_ver = Version;
278 mocchiut 1.14 if ( !strcmp(Detector.Data(),"DV") ) version->DV_ver = Version;
279 mocchiut 1.1 if ( !strcmp(Detector.Data(),"ND") ) version->ND_ver = Version;
280     if ( !strcmp(Detector.Data(),"ORB") ) version->ORB_ver = Version;
281 mocchiut 1.14 if ( strcmp(Detector.Data(),"TRIG") && strcmp(Detector.Data(),"TOF") && strcmp(Detector.Data(),"AC") && strcmp(Detector.Data(),"TRK") && strcmp(Detector.Data(),"CALO") && strcmp(Detector.Data(),"S4") && strcmp(Detector.Data(),"ND") && strcmp(Detector.Data(),"ORB") && strcmp(Detector.Data(),"DV") ) return(-804);
282 mocchiut 1.1 };
283     //
284     if ( !oldtree ) {
285     //
286     if ( strcmp(Detector.Data(),"NONE") ) return(-803);
287     updating = false;
288     if ( debug ) printf(" RunInfo: creating Run tree in this file\n");
289     //
290     } else {
291     //
292     updating = true;
293     if ( debug ) printf(" RunInfo: updating versioning information \n");
294     //
295     };
296     //
297     file->cd();
298     //
299     // Prepare a new tree to upgrade the contents of the old tree
300     //
301     newtree = new TTree("Run-new","PAMELA Level2 data from the GL_RUN table");
302     newtree->Branch("RunInfo","GL_RUN",&newrun);
303     newtree->Branch("SoftInfo","SoftInfo",&newver);
304     //
305     //
306     if ( !updating ){
307 mocchiut 1.8 if ( idRun == 0 ){
308 mocchiut 1.1 if ( debug ) printf("\n RUNINFO - ERROR: reprocessing data but no RunInfo tree in Level2 file. \n");
309 mocchiut 1.2 return(-805);
310 mocchiut 1.1 };
311     //
312     error = Query_GL_RUN(idRun, dbc);
313     //
314     if ( error ){
315     if ( debug ) printf("\n RUNINFO - ERROR: Query_GL_RUN exited with non zero error\n");
316     return(error);
317     };
318 mocchiut 1.8 if ( ID == 0 ){
319     if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %u \n",idRun);
320 mocchiut 1.1 return(-5);
321     };
322     //
323     //
324 mocchiut 1.8 CopyFromTo((GL_RUN*)this,newrun,version,newver);
325 mocchiut 1.1 //
326     // fill the tree;
327     //
328     newtree->Fill();
329     //
330     totnorun = 1;
331     reprocessing = false;
332     first_file_entry = 0;
333 mocchiut 1.15 if ( EV_TO >= EV_FROM ) last_file_entry = (UInt_t)(EV_TO - EV_FROM);
334 mocchiut 1.1 norun = 1;
335 mocchiut 1.8 runlist->AddAt((Int_t)ID,0);
336 mocchiut 1.1 //
337     newtree->SetName("Run");
338     //
339     file->cd();
340 mocchiut 1.8 //
341 mocchiut 1.3 delete newver;
342     delete newrun;
343     delete oldver;
344     delete oldrun;
345 mocchiut 1.1 //
346     return(0);
347     //
348     } else {
349     //
350     //
351     oldtree->SetBranchAddress("RunInfo",&oldrun);
352     oldtree->SetBranchAddress("SoftInfo",&oldver);
353     //
354     totnorun = oldtree->GetEntries();
355     //
356 mocchiut 1.7 if ( totnorun > 500 ){
357     if ( debug ) printf("\n RUNINFO - ERROR: can not handle more than 500 runs!\n");
358     return(-806);
359     };
360 mocchiut 1.1 //
361     found = false;
362     //
363     for ( UInt_t run = 0; run < totnorun; run++){
364     //
365 mocchiut 1.19 if ( oldtree->GetEntry(run) <= 0 ) throw -36;
366 mocchiut 1.1 //
367 mocchiut 1.8 CopyFromTo(oldrun,newrun,oldver,newver);
368 mocchiut 1.1 //
369 mocchiut 1.8 file_entries += (oldrun->EV_TO - oldrun->EV_FROM + 1);
370 mocchiut 1.1 //
371     if ( debug ) printf("totnorun %i idRun %i newrun->ID %i \n",(int)totnorun,(int)idRun,(int)newrun->ID);
372     //
373 mocchiut 1.8 if ( idRun == 0 || idRun == newrun->ID ) {
374 mocchiut 1.1 //
375 mocchiut 1.8 if ( debug ) printf(" Updating run number %u \n",idRun);
376 mocchiut 1.1 //
377     found = true;
378     //
379     runlist->AddAt(newrun->ID,norun);
380     norun++;
381     //
382     if ( !strcmp(Detector.Data(),"NONE") ){
383     //
384     // update infromations querying the DB
385     //
386     error = Query_GL_RUN(newrun->ID, dbc);
387     //
388     if ( error ){
389     if ( debug ) printf("\n RUNINFO - ERROR: Query_GL_RUN exited with non zero error\n");
390     return(error);
391     };
392     //
393 mocchiut 1.8 CopyFromTo((GL_RUN*)this,newrun,NULL,NULL);
394     //
395 mocchiut 1.1 } else {
396     //
397     if ( !strcmp(Detector.Data(),"TRIG") ){
398     newver->TRIG_ver = version->TRIG_ver;
399     newver->TOF_ver = oldver->TOF_ver;
400     newver->AC_ver = oldver->AC_ver;
401     newver->TRK_ver = oldver->TRK_ver;
402     newver->ORB_ver = oldver->ORB_ver;
403     newver->CAL_ver = oldver->CAL_ver;
404     newver->S4_ver = oldver->S4_ver;
405 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
406 mocchiut 1.1 newver->ND_ver = oldver->ND_ver;
407     if ( strcmp(oldver->TRIG_ver.Data(),"") ) reprocessing = true;
408     };
409     if ( !strcmp(Detector.Data(),"TOF") ){
410     newver->TRIG_ver = oldver->TRIG_ver;
411     newver->TOF_ver = version->TOF_ver;
412     newver->AC_ver = oldver->AC_ver;
413     newver->TRK_ver = oldver->TRK_ver;
414     newver->ORB_ver = oldver->ORB_ver;
415     newver->CAL_ver = oldver->CAL_ver;
416 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
417 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
418     newver->ND_ver = oldver->ND_ver;
419     if ( strcmp(oldver->TOF_ver.Data(),"") ) reprocessing = true;
420     };
421     if ( !strcmp(Detector.Data(),"AC") ){
422     newver->TRIG_ver = oldver->TRIG_ver;
423     newver->TOF_ver = oldver->TOF_ver;
424     newver->TRK_ver = oldver->TRK_ver;
425     newver->ORB_ver = oldver->ORB_ver;
426     newver->CAL_ver = oldver->CAL_ver;
427 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
428 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
429     newver->ND_ver = oldver->ND_ver;
430     newver->AC_ver = version->AC_ver;
431     if ( strcmp(oldver->AC_ver.Data(),"") ) reprocessing = true;
432     };
433     if ( !strcmp(Detector.Data(),"TRK") ){
434     newver->TRIG_ver = oldver->TRIG_ver;
435     newver->TOF_ver = oldver->TOF_ver;
436     newver->CAL_ver = oldver->CAL_ver;
437     newver->ORB_ver = oldver->ORB_ver;
438 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
439 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
440     newver->ND_ver = oldver->ND_ver;
441     newver->AC_ver = oldver->AC_ver;
442     newver->TRK_ver = version->TRK_ver;
443     if ( strcmp(oldver->TRK_ver.Data(),"") ) reprocessing = true;
444     };
445     if ( !strcmp(Detector.Data(),"ORB") ){
446     newver->TRIG_ver = oldver->TRIG_ver;
447     newver->TOF_ver = oldver->TOF_ver;
448     newver->CAL_ver = oldver->CAL_ver;
449     newver->TRK_ver = oldver->TRK_ver;
450 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
451 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
452     newver->ND_ver = oldver->ND_ver;
453     newver->AC_ver = oldver->AC_ver;
454     newver->ORB_ver = version->ORB_ver;
455 mocchiut 1.3 if ( strcmp(oldver->ORB_ver.Data(),"") ) reprocessing = true;
456 mocchiut 1.1 };
457     if ( !strcmp(Detector.Data(),"CALO") ){
458     newver->TRIG_ver = oldver->TRIG_ver;
459     newver->TOF_ver = oldver->TOF_ver;
460 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
461 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
462     newver->ORB_ver = oldver->ORB_ver;
463     newver->ND_ver = oldver->ND_ver;
464     newver->AC_ver = oldver->AC_ver;
465     newver->TRK_ver = oldver->TRK_ver;
466     newver->CAL_ver = version->CAL_ver;
467     if ( strcmp(oldver->CAL_ver.Data(),"") ) reprocessing = true;
468     };
469     if ( !strcmp(Detector.Data(),"S4") ){
470     newver->TRIG_ver = oldver->TRIG_ver;
471     newver->TOF_ver = oldver->TOF_ver;
472     newver->ND_ver = oldver->ND_ver;
473     newver->AC_ver = oldver->AC_ver;
474     newver->TRK_ver = oldver->TRK_ver;
475     newver->ORB_ver = oldver->ORB_ver;
476     newver->CAL_ver = oldver->CAL_ver;
477 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
478 mocchiut 1.1 newver->S4_ver = version->S4_ver;
479     if ( strcmp(oldver->S4_ver.Data(),"") ) reprocessing = true;
480     };
481 mocchiut 1.14 if ( !strcmp(Detector.Data(),"DV") ){
482     newver->TRIG_ver = oldver->TRIG_ver;
483     newver->TOF_ver = oldver->TOF_ver;
484     newver->ND_ver = oldver->ND_ver;
485     newver->AC_ver = oldver->AC_ver;
486     newver->TRK_ver = oldver->TRK_ver;
487     newver->ORB_ver = oldver->ORB_ver;
488     newver->CAL_ver = oldver->CAL_ver;
489     newver->S4_ver = oldver->S4_ver;
490     newver->DV_ver = version->DV_ver;
491     if ( strcmp(oldver->DV_ver.Data(),"") ) reprocessing = true;
492     };
493 mocchiut 1.1 if ( !strcmp(Detector.Data(),"ND") ){
494     newver->TRIG_ver = oldver->TRIG_ver;
495     newver->TOF_ver = oldver->TOF_ver;
496 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
497 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
498     newver->AC_ver = oldver->AC_ver;
499     newver->ORB_ver = oldver->ORB_ver;
500     newver->TRK_ver = oldver->TRK_ver;
501     newver->CAL_ver = oldver->CAL_ver;
502     newver->ND_ver = version->ND_ver;
503     if ( strcmp(oldver->ND_ver.Data(),"") ) reprocessing = true;
504     };
505     };
506     //
507 mocchiut 1.15 if ( oldrun->EV_TO >= oldrun->EV_FROM ) last_file_entry = first_file_entry + (oldrun->EV_TO - oldrun->EV_FROM + 1);
508 mocchiut 1.1 //
509     } else {
510 mocchiut 1.8 if ( !found ) first_file_entry += (oldrun->EV_TO - oldrun->EV_FROM + 1);
511 mocchiut 1.1 };
512     //
513     file->cd();
514     newtree->Fill();
515     //
516     };
517     //
518     file->cd();
519     if ( oldtree ) oldtree->Delete("all");
520     newtree->SetName("Run");
521 mocchiut 1.8 //
522 mocchiut 1.3 delete newver;
523     delete newrun;
524     delete oldver;
525     delete oldrun;
526 mocchiut 1.1 //
527     if ( !found ){
528 mocchiut 1.8 if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %u \n",idRun);
529 mocchiut 1.1 return(-5);
530     };
531     //
532     // newtree->Write();
533     };
534     return(0);
535     }
536    
537 mocchiut 1.8 Int_t ItoRunInfo::Read(UInt_t idRun){
538 mocchiut 1.1 //
539     isreadonly = true;
540     //
541     Bool_t debug = false;
542     //
543     SoftInfo *newver = new SoftInfo();
544     GL_RUN *newrun = new GL_RUN();
545     //
546     // Try to get the tree Run in the processed file
547     //
548     newtree = (TTree*)file->Get("Run");
549     //
550     if ( !newtree ) {
551     //
552     printf("\n RUNINFO - ERROR: no RunInfo tree in Level2 file. \n");
553     return(-801);
554     //
555     } else {
556     //
557     printf(" RunInfo: opening RunInfo tree \n");
558     //
559     newtree->SetBranchAddress("RunInfo",&newrun);
560     newtree->SetBranchAddress("SoftInfo",&newver);
561     //
562     totnorun = newtree->GetEntries();
563     //
564 mocchiut 1.7 if ( totnorun > 500 ){
565     if ( debug ) printf("\n RUNINFO - ERROR: can not handle more than 500 runs!\n");
566     return(-806);
567     };
568 mocchiut 1.1 //
569     first_file_entry = 0;
570     //
571     for ( UInt_t run = 0; run < totnorun; run++){
572     //
573 mocchiut 1.19 if ( newtree->GetEntry(run) <= 0 ) throw -36;
574 mocchiut 1.1 //
575 mocchiut 1.8 file_entries += (newrun->EV_TO - newrun->EV_FROM + 1);
576 mocchiut 1.1 //
577     if ( debug ) printf("totnorun %i newrun->ID %i \n",(int)totnorun,(int)newrun->ID);
578     //
579 mocchiut 1.8 CopyFromTo(newrun,(GL_RUN*)this,newver,version);
580     if ( idRun == ID || idRun == 0 ){
581 mocchiut 1.1 runlist->AddAt(newrun->ID,norun);
582     norun++;
583     };
584 mocchiut 1.15 if ( newrun->EV_TO >= newrun->EV_FROM ) last_file_entry = first_file_entry + (newrun->EV_TO - newrun->EV_FROM + 1);
585 mocchiut 1.1 };
586     };
587     if ( debug ) printf("norun %i \n",(int)norun);
588     Int_t error = 0;
589     error = GetRunInfo(idRun);
590 mocchiut 1.3 delete newver;
591     delete newrun;
592 mocchiut 1.1 if ( error ) return(error);
593     return(0);
594     }
595    
596     void ItoRunInfo::Close(){
597     reprocessing = false;
598     updating = false;
599     first_file_entry = 0;
600     last_file_entry = 0;
601 mocchiut 1.8 file_entries = 0;
602 mocchiut 1.1 norun = 0;
603 mocchiut 1.7 delete runlist;
604 mocchiut 1.14 // file = new TFile();
605     file = 0;
606 mocchiut 1.1 if ( isreadonly ) newtree->Delete();
607     }
608    
609 mocchiut 1.17 void ItoRunInfo::Clear(Option_t *t){
610 mocchiut 1.1 if ( newtree ) newtree->Delete();
611     }
612    
613     UInt_t ItoRunInfo::GetRunForEntry(UInt_t entry){
614     //
615 mocchiut 1.5 UInt_t startfrom = 0;
616     //
617     if ( entry >= (UInt_t)first_file_entry && entry <= (UInt_t)last_file_entry ) return(ID);
618 mocchiut 1.1 //
619 mocchiut 1.5 if ( entry > (UInt_t)last_file_entry ){
620     for ( UInt_t nrun = 0; nrun < norun; nrun++){
621 mocchiut 1.8 if ( ID == (UInt_t)runlist->At(nrun) ) {
622 mocchiut 1.5 startfrom = nrun+1;
623     break;
624     };
625     };
626     } else {
627     startfrom = 0;
628     };
629     //
630     if ( startfrom >= norun ) startfrom = 0;
631     //
632     retry:
633     //
634     for ( UInt_t nrun = startfrom; nrun < norun; nrun++){
635 mocchiut 1.8 GetRunInfo((UInt_t)runlist->At(nrun));
636 mocchiut 1.4 if ( entry >= (UInt_t)first_file_entry && entry <= (UInt_t)last_file_entry ){
637     return((UInt_t)runlist->At(nrun));
638 mocchiut 1.1 };
639     };
640 mocchiut 1.5 if ( startfrom ){
641     startfrom = 0;
642     goto retry;
643     };
644     printf(" ERROR! run not found \n");
645 mocchiut 1.1 return(0);
646     }
647    
648 mocchiut 1.8 Int_t ItoRunInfo::GetRunInfo(UInt_t run){
649 mocchiut 1.1 Bool_t found = false;
650     SoftInfo *nwver = new SoftInfo();
651     GL_RUN *nwrun = new GL_RUN();
652     //
653     newtree->SetBranchAddress("RunInfo",&nwrun);
654     newtree->SetBranchAddress("SoftInfo",&nwver);
655     //
656     last_file_entry = 0;
657     first_file_entry = 0;
658     //
659     totnorun = newtree->GetEntries();
660     //
661     for ( UInt_t nrun = 0; nrun < totnorun; nrun++){
662 mocchiut 1.19 if ( newtree->GetEntry(nrun) <= 0 ) throw -36;
663 mocchiut 1.1 //
664 mocchiut 1.8 if ( nwrun->ID == run || run == 0 ){
665     CopyFromTo(nwrun,(GL_RUN*)this,nwver,version);
666 mocchiut 1.1 found = true;
667 mocchiut 1.15 if ( nwrun->EV_TO >= nwrun->EV_FROM ) last_file_entry = first_file_entry + (nwrun->EV_TO - nwrun->EV_FROM + 1);
668 mocchiut 1.1 };
669 mocchiut 1.8 if ( !found ) first_file_entry += (nwrun->EV_TO - nwrun->EV_FROM + 1);
670 mocchiut 1.1 };
671 mocchiut 1.3 delete nwver;
672     delete nwrun;
673 mocchiut 1.4 if ( found ) return(0);
674 mocchiut 1.1 return(-800);
675     }
676 mocchiut 1.5

  ViewVC Help
Powered by ViewVC 1.1.23