/[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.21 - (hide annotations) (download)
Tue May 15 14:35:31 2012 UTC (12 years, 6 months ago) by mocchiut
Branch: MAIN
Changes since 1.20: +2 -2 lines
Reprocessing bugs fixed, ToF bugs fixed, new software versions, new quaternions, IGRF bug fixed, code cleanup

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

  ViewVC Help
Powered by ViewVC 1.1.23