/[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.17 - (hide annotations) (download)
Mon Nov 26 08:01:15 2007 UTC (17 years ago) by mocchiut
Branch: MAIN
CVS Tags: v5r00
Changes since 1.16: +2 -2 lines
Compilation bug fixed

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     newrun->VALIDATION = glrun->VALIDATION ;
205     //
206     };
207     //
208     if ( newver && sinfo ){
209     //
210     newver->TRIG_ver = sinfo->TRIG_ver;
211     newver->TOF_ver = sinfo->TOF_ver;
212     newver->AC_ver = sinfo->AC_ver;
213     newver->TRK_ver = sinfo->TRK_ver;
214     newver->ORB_ver = sinfo->ORB_ver;
215     newver->CAL_ver = sinfo->CAL_ver;
216     newver->S4_ver = sinfo->S4_ver;
217 mocchiut 1.14 newver->DV_ver = sinfo->DV_ver;
218 mocchiut 1.8 newver->ND_ver = sinfo->ND_ver;
219     //
220     };
221 mocchiut 1.1 }
222    
223 mocchiut 1.8 Int_t ItoRunInfo::Update(UInt_t run, TString Detector, TString Version){
224 mocchiut 1.1 //
225     isreadonly = false;
226     idRun = run;
227     //
228 mocchiut 1.10 Bool_t debug = false;
229 mocchiut 1.1 //
230     Bool_t ismydir = false;
231     //
232     if ( !strcmp(processFolder.Data(),"") ){
233     processFolder = "runinfoFolder";
234     ismydir = true;
235     };
236     //
237     GL_RUN *oldrun = new GL_RUN();
238     GL_RUN *newrun = new GL_RUN();
239     SoftInfo *oldver = new SoftInfo();
240     SoftInfo *newver = new SoftInfo();
241     //
242 mocchiut 1.8 this->GL_RUN::Clear();
243     version->Clear();
244 mocchiut 1.1 //
245     norun = 0;
246     //
247     Bool_t found = false;
248     Int_t error = 0;
249     //
250     TTree *oldtree = 0;
251     //
252     // Try to get the tree Run in the processed file
253     //
254     oldtree = (TTree*)file->Get("Run");
255     //
256     // Look for detector's versions if we are updating a single detector
257     //
258     if ( debug ) printf("Detector -%s- \n",Detector.Data());
259     if ( !strcmp(Detector.Data(),"NONE") ){
260     version->TRIG_ver = Version;
261     version->TOF_ver = Version;
262     version->AC_ver = Version;
263     version->TRK_ver = Version;
264     version->ORB_ver = Version;
265     version->CAL_ver = Version;
266     version->S4_ver = Version;
267 mocchiut 1.14 version->DV_ver = Version;
268 mocchiut 1.1 version->ND_ver = Version;
269     } else {
270     if ( !strcmp(Detector.Data(),"TRIG") ) version->TRIG_ver = Version;
271     if ( !strcmp(Detector.Data(),"TOF") ) version->TOF_ver = Version;
272     if ( !strcmp(Detector.Data(),"AC") ) version->AC_ver = Version;
273     if ( !strcmp(Detector.Data(),"TRK") ) version->TRK_ver = Version;
274     if ( !strcmp(Detector.Data(),"CALO") ) version->CAL_ver = Version;
275     if ( !strcmp(Detector.Data(),"S4") ) version->S4_ver = Version;
276 mocchiut 1.14 if ( !strcmp(Detector.Data(),"DV") ) version->DV_ver = Version;
277 mocchiut 1.1 if ( !strcmp(Detector.Data(),"ND") ) version->ND_ver = Version;
278     if ( !strcmp(Detector.Data(),"ORB") ) version->ORB_ver = Version;
279 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);
280 mocchiut 1.1 };
281     //
282     if ( !oldtree ) {
283     //
284     if ( strcmp(Detector.Data(),"NONE") ) return(-803);
285     updating = false;
286     if ( debug ) printf(" RunInfo: creating Run tree in this file\n");
287     //
288     } else {
289     //
290     updating = true;
291     if ( debug ) printf(" RunInfo: updating versioning information \n");
292     //
293     };
294     //
295     file->cd();
296     //
297     // Prepare a new tree to upgrade the contents of the old tree
298     //
299     newtree = new TTree("Run-new","PAMELA Level2 data from the GL_RUN table");
300     newtree->Branch("RunInfo","GL_RUN",&newrun);
301     newtree->Branch("SoftInfo","SoftInfo",&newver);
302     //
303     //
304     if ( !updating ){
305 mocchiut 1.8 if ( idRun == 0 ){
306 mocchiut 1.1 if ( debug ) printf("\n RUNINFO - ERROR: reprocessing data but no RunInfo tree in Level2 file. \n");
307 mocchiut 1.2 return(-805);
308 mocchiut 1.1 };
309     //
310     error = Query_GL_RUN(idRun, dbc);
311     //
312     if ( error ){
313     if ( debug ) printf("\n RUNINFO - ERROR: Query_GL_RUN exited with non zero error\n");
314     return(error);
315     };
316 mocchiut 1.8 if ( ID == 0 ){
317     if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %u \n",idRun);
318 mocchiut 1.1 return(-5);
319     };
320     //
321     //
322 mocchiut 1.8 CopyFromTo((GL_RUN*)this,newrun,version,newver);
323 mocchiut 1.1 //
324     // fill the tree;
325     //
326     newtree->Fill();
327     //
328     totnorun = 1;
329     reprocessing = false;
330     first_file_entry = 0;
331 mocchiut 1.15 if ( EV_TO >= EV_FROM ) last_file_entry = (UInt_t)(EV_TO - EV_FROM);
332 mocchiut 1.1 norun = 1;
333 mocchiut 1.8 runlist->AddAt((Int_t)ID,0);
334 mocchiut 1.1 //
335     newtree->SetName("Run");
336     //
337     file->cd();
338 mocchiut 1.8 //
339 mocchiut 1.3 delete newver;
340     delete newrun;
341     delete oldver;
342     delete oldrun;
343 mocchiut 1.1 //
344     return(0);
345     //
346     } else {
347     //
348     //
349     oldtree->SetBranchAddress("RunInfo",&oldrun);
350     oldtree->SetBranchAddress("SoftInfo",&oldver);
351     //
352     totnorun = oldtree->GetEntries();
353     //
354 mocchiut 1.7 if ( totnorun > 500 ){
355     if ( debug ) printf("\n RUNINFO - ERROR: can not handle more than 500 runs!\n");
356     return(-806);
357     };
358 mocchiut 1.1 //
359     found = false;
360     //
361     for ( UInt_t run = 0; run < totnorun; run++){
362     //
363     oldtree->GetEntry(run);
364     //
365 mocchiut 1.8 CopyFromTo(oldrun,newrun,oldver,newver);
366 mocchiut 1.1 //
367 mocchiut 1.8 file_entries += (oldrun->EV_TO - oldrun->EV_FROM + 1);
368 mocchiut 1.1 //
369     if ( debug ) printf("totnorun %i idRun %i newrun->ID %i \n",(int)totnorun,(int)idRun,(int)newrun->ID);
370     //
371 mocchiut 1.8 if ( idRun == 0 || idRun == newrun->ID ) {
372 mocchiut 1.1 //
373 mocchiut 1.8 if ( debug ) printf(" Updating run number %u \n",idRun);
374 mocchiut 1.1 //
375     found = true;
376     //
377     runlist->AddAt(newrun->ID,norun);
378     norun++;
379     //
380     if ( !strcmp(Detector.Data(),"NONE") ){
381     //
382     // update infromations querying the DB
383     //
384     error = Query_GL_RUN(newrun->ID, dbc);
385     //
386     if ( error ){
387     if ( debug ) printf("\n RUNINFO - ERROR: Query_GL_RUN exited with non zero error\n");
388     return(error);
389     };
390     //
391 mocchiut 1.8 CopyFromTo((GL_RUN*)this,newrun,NULL,NULL);
392     //
393 mocchiut 1.1 } else {
394     //
395     if ( !strcmp(Detector.Data(),"TRIG") ){
396     newver->TRIG_ver = version->TRIG_ver;
397     newver->TOF_ver = oldver->TOF_ver;
398     newver->AC_ver = oldver->AC_ver;
399     newver->TRK_ver = oldver->TRK_ver;
400     newver->ORB_ver = oldver->ORB_ver;
401     newver->CAL_ver = oldver->CAL_ver;
402     newver->S4_ver = oldver->S4_ver;
403 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
404 mocchiut 1.1 newver->ND_ver = oldver->ND_ver;
405     if ( strcmp(oldver->TRIG_ver.Data(),"") ) reprocessing = true;
406     };
407     if ( !strcmp(Detector.Data(),"TOF") ){
408     newver->TRIG_ver = oldver->TRIG_ver;
409     newver->TOF_ver = version->TOF_ver;
410     newver->AC_ver = oldver->AC_ver;
411     newver->TRK_ver = oldver->TRK_ver;
412     newver->ORB_ver = oldver->ORB_ver;
413     newver->CAL_ver = oldver->CAL_ver;
414 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
415 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
416     newver->ND_ver = oldver->ND_ver;
417     if ( strcmp(oldver->TOF_ver.Data(),"") ) reprocessing = true;
418     };
419     if ( !strcmp(Detector.Data(),"AC") ){
420     newver->TRIG_ver = oldver->TRIG_ver;
421     newver->TOF_ver = oldver->TOF_ver;
422     newver->TRK_ver = oldver->TRK_ver;
423     newver->ORB_ver = oldver->ORB_ver;
424     newver->CAL_ver = oldver->CAL_ver;
425 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
426 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
427     newver->ND_ver = oldver->ND_ver;
428     newver->AC_ver = version->AC_ver;
429     if ( strcmp(oldver->AC_ver.Data(),"") ) reprocessing = true;
430     };
431     if ( !strcmp(Detector.Data(),"TRK") ){
432     newver->TRIG_ver = oldver->TRIG_ver;
433     newver->TOF_ver = oldver->TOF_ver;
434     newver->CAL_ver = oldver->CAL_ver;
435     newver->ORB_ver = oldver->ORB_ver;
436 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
437 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
438     newver->ND_ver = oldver->ND_ver;
439     newver->AC_ver = oldver->AC_ver;
440     newver->TRK_ver = version->TRK_ver;
441     if ( strcmp(oldver->TRK_ver.Data(),"") ) reprocessing = true;
442     };
443     if ( !strcmp(Detector.Data(),"ORB") ){
444     newver->TRIG_ver = oldver->TRIG_ver;
445     newver->TOF_ver = oldver->TOF_ver;
446     newver->CAL_ver = oldver->CAL_ver;
447     newver->TRK_ver = oldver->TRK_ver;
448 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
449 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
450     newver->ND_ver = oldver->ND_ver;
451     newver->AC_ver = oldver->AC_ver;
452     newver->ORB_ver = version->ORB_ver;
453 mocchiut 1.3 if ( strcmp(oldver->ORB_ver.Data(),"") ) reprocessing = true;
454 mocchiut 1.1 };
455     if ( !strcmp(Detector.Data(),"CALO") ){
456     newver->TRIG_ver = oldver->TRIG_ver;
457     newver->TOF_ver = oldver->TOF_ver;
458 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
459 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
460     newver->ORB_ver = oldver->ORB_ver;
461     newver->ND_ver = oldver->ND_ver;
462     newver->AC_ver = oldver->AC_ver;
463     newver->TRK_ver = oldver->TRK_ver;
464     newver->CAL_ver = version->CAL_ver;
465     if ( strcmp(oldver->CAL_ver.Data(),"") ) reprocessing = true;
466     };
467     if ( !strcmp(Detector.Data(),"S4") ){
468     newver->TRIG_ver = oldver->TRIG_ver;
469     newver->TOF_ver = oldver->TOF_ver;
470     newver->ND_ver = oldver->ND_ver;
471     newver->AC_ver = oldver->AC_ver;
472     newver->TRK_ver = oldver->TRK_ver;
473     newver->ORB_ver = oldver->ORB_ver;
474     newver->CAL_ver = oldver->CAL_ver;
475 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
476 mocchiut 1.1 newver->S4_ver = version->S4_ver;
477     if ( strcmp(oldver->S4_ver.Data(),"") ) reprocessing = true;
478     };
479 mocchiut 1.14 if ( !strcmp(Detector.Data(),"DV") ){
480     newver->TRIG_ver = oldver->TRIG_ver;
481     newver->TOF_ver = oldver->TOF_ver;
482     newver->ND_ver = oldver->ND_ver;
483     newver->AC_ver = oldver->AC_ver;
484     newver->TRK_ver = oldver->TRK_ver;
485     newver->ORB_ver = oldver->ORB_ver;
486     newver->CAL_ver = oldver->CAL_ver;
487     newver->S4_ver = oldver->S4_ver;
488     newver->DV_ver = version->DV_ver;
489     if ( strcmp(oldver->DV_ver.Data(),"") ) reprocessing = true;
490     };
491 mocchiut 1.1 if ( !strcmp(Detector.Data(),"ND") ){
492     newver->TRIG_ver = oldver->TRIG_ver;
493     newver->TOF_ver = oldver->TOF_ver;
494 mocchiut 1.14 newver->DV_ver = oldver->DV_ver;
495 mocchiut 1.1 newver->S4_ver = oldver->S4_ver;
496     newver->AC_ver = oldver->AC_ver;
497     newver->ORB_ver = oldver->ORB_ver;
498     newver->TRK_ver = oldver->TRK_ver;
499     newver->CAL_ver = oldver->CAL_ver;
500     newver->ND_ver = version->ND_ver;
501     if ( strcmp(oldver->ND_ver.Data(),"") ) reprocessing = true;
502     };
503     };
504     //
505 mocchiut 1.15 if ( oldrun->EV_TO >= oldrun->EV_FROM ) last_file_entry = first_file_entry + (oldrun->EV_TO - oldrun->EV_FROM + 1);
506 mocchiut 1.1 //
507     } else {
508 mocchiut 1.8 if ( !found ) first_file_entry += (oldrun->EV_TO - oldrun->EV_FROM + 1);
509 mocchiut 1.1 };
510     //
511     file->cd();
512     newtree->Fill();
513     //
514     };
515     //
516     file->cd();
517     if ( oldtree ) oldtree->Delete("all");
518     newtree->SetName("Run");
519 mocchiut 1.8 //
520 mocchiut 1.3 delete newver;
521     delete newrun;
522     delete oldver;
523     delete oldrun;
524 mocchiut 1.1 //
525     if ( !found ){
526 mocchiut 1.8 if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %u \n",idRun);
527 mocchiut 1.1 return(-5);
528     };
529     //
530     // newtree->Write();
531     };
532     return(0);
533     }
534    
535 mocchiut 1.8 Int_t ItoRunInfo::Read(UInt_t idRun){
536 mocchiut 1.1 //
537     isreadonly = true;
538     //
539     Bool_t debug = false;
540     //
541     SoftInfo *newver = new SoftInfo();
542     GL_RUN *newrun = new GL_RUN();
543     //
544     // Try to get the tree Run in the processed file
545     //
546     newtree = (TTree*)file->Get("Run");
547     //
548     if ( !newtree ) {
549     //
550     printf("\n RUNINFO - ERROR: no RunInfo tree in Level2 file. \n");
551     return(-801);
552     //
553     } else {
554     //
555     printf(" RunInfo: opening RunInfo tree \n");
556     //
557     newtree->SetBranchAddress("RunInfo",&newrun);
558     newtree->SetBranchAddress("SoftInfo",&newver);
559     //
560     totnorun = newtree->GetEntries();
561     //
562 mocchiut 1.7 if ( totnorun > 500 ){
563     if ( debug ) printf("\n RUNINFO - ERROR: can not handle more than 500 runs!\n");
564     return(-806);
565     };
566 mocchiut 1.1 //
567     first_file_entry = 0;
568     //
569     for ( UInt_t run = 0; run < totnorun; run++){
570     //
571     newtree->GetEntry(run);
572     //
573 mocchiut 1.8 file_entries += (newrun->EV_TO - newrun->EV_FROM + 1);
574 mocchiut 1.1 //
575     if ( debug ) printf("totnorun %i newrun->ID %i \n",(int)totnorun,(int)newrun->ID);
576     //
577 mocchiut 1.8 CopyFromTo(newrun,(GL_RUN*)this,newver,version);
578     if ( idRun == ID || idRun == 0 ){
579 mocchiut 1.1 runlist->AddAt(newrun->ID,norun);
580     norun++;
581     };
582 mocchiut 1.15 if ( newrun->EV_TO >= newrun->EV_FROM ) last_file_entry = first_file_entry + (newrun->EV_TO - newrun->EV_FROM + 1);
583 mocchiut 1.1 };
584     };
585     if ( debug ) printf("norun %i \n",(int)norun);
586     Int_t error = 0;
587     error = GetRunInfo(idRun);
588 mocchiut 1.3 delete newver;
589     delete newrun;
590 mocchiut 1.1 if ( error ) return(error);
591     return(0);
592     }
593    
594     void ItoRunInfo::Close(){
595     reprocessing = false;
596     updating = false;
597     first_file_entry = 0;
598     last_file_entry = 0;
599 mocchiut 1.8 file_entries = 0;
600 mocchiut 1.1 norun = 0;
601 mocchiut 1.7 delete runlist;
602 mocchiut 1.14 // file = new TFile();
603     file = 0;
604 mocchiut 1.1 if ( isreadonly ) newtree->Delete();
605     }
606    
607 mocchiut 1.17 void ItoRunInfo::Clear(Option_t *t){
608 mocchiut 1.1 if ( newtree ) newtree->Delete();
609     }
610    
611     UInt_t ItoRunInfo::GetRunForEntry(UInt_t entry){
612     //
613 mocchiut 1.5 UInt_t startfrom = 0;
614     //
615     if ( entry >= (UInt_t)first_file_entry && entry <= (UInt_t)last_file_entry ) return(ID);
616 mocchiut 1.1 //
617 mocchiut 1.5 if ( entry > (UInt_t)last_file_entry ){
618     for ( UInt_t nrun = 0; nrun < norun; nrun++){
619 mocchiut 1.8 if ( ID == (UInt_t)runlist->At(nrun) ) {
620 mocchiut 1.5 startfrom = nrun+1;
621     break;
622     };
623     };
624     } else {
625     startfrom = 0;
626     };
627     //
628     if ( startfrom >= norun ) startfrom = 0;
629     //
630     retry:
631     //
632     for ( UInt_t nrun = startfrom; nrun < norun; nrun++){
633 mocchiut 1.8 GetRunInfo((UInt_t)runlist->At(nrun));
634 mocchiut 1.4 if ( entry >= (UInt_t)first_file_entry && entry <= (UInt_t)last_file_entry ){
635     return((UInt_t)runlist->At(nrun));
636 mocchiut 1.1 };
637     };
638 mocchiut 1.5 if ( startfrom ){
639     startfrom = 0;
640     goto retry;
641     };
642     printf(" ERROR! run not found \n");
643 mocchiut 1.1 return(0);
644     }
645    
646 mocchiut 1.8 Int_t ItoRunInfo::GetRunInfo(UInt_t run){
647 mocchiut 1.1 Bool_t found = false;
648     SoftInfo *nwver = new SoftInfo();
649     GL_RUN *nwrun = new GL_RUN();
650     //
651     newtree->SetBranchAddress("RunInfo",&nwrun);
652     newtree->SetBranchAddress("SoftInfo",&nwver);
653     //
654     last_file_entry = 0;
655     first_file_entry = 0;
656     //
657     totnorun = newtree->GetEntries();
658     //
659     for ( UInt_t nrun = 0; nrun < totnorun; nrun++){
660     newtree->GetEntry(nrun);
661     //
662 mocchiut 1.8 if ( nwrun->ID == run || run == 0 ){
663     CopyFromTo(nwrun,(GL_RUN*)this,nwver,version);
664 mocchiut 1.1 found = true;
665 mocchiut 1.15 if ( nwrun->EV_TO >= nwrun->EV_FROM ) last_file_entry = first_file_entry + (nwrun->EV_TO - nwrun->EV_FROM + 1);
666 mocchiut 1.1 };
667 mocchiut 1.8 if ( !found ) first_file_entry += (nwrun->EV_TO - nwrun->EV_FROM + 1);
668 mocchiut 1.1 };
669 mocchiut 1.3 delete nwver;
670     delete nwrun;
671 mocchiut 1.4 if ( found ) return(0);
672 mocchiut 1.1 return(-800);
673     }
674 mocchiut 1.5

  ViewVC Help
Powered by ViewVC 1.1.23