///////////////////////////////////////////////////////////////////// // // The following method generated a root tree from a .txt file. // The first branch is the time offset (time in seconds of the first // available measurement) and then the tree has a branch for each HV // channel: a structure thvinfo is saved with voltage, current, // status and time in seconds. // ///////////////////////////////////////////////////////////////////// #include #include #include #include #include void create_tree() { //gROOT->Reset(); int mod,ch; float Vm,Im; //,t; TString filename = "Sample.txt"; cout << "Tree root does not exist: --->>>> CREATING " << endl; TString fileout = filename; fileout.Resize(fileout.Sizeof()-5); fileout.Append(".root"); //char* fil = filename ; FILE *fp =fopen(filename.Data(),"r"); char line[100] ; char date[100] ; char time[100] ; char pm[100] ; int hour,minute,sec,mounth,day,year,sts; //,reftime //int inum = 0; time_t tfirst; TFile f(fileout,"RECREATE"); TTree HVtree("HVtree","HV on the modules"); TBranch *br; struct thvinfo { int sts; float vm,im; time_t t; }; thvinfo info; int index; int NMOD = 320; int i; for(i=0; itm_year = year - 1900; timeinfo->tm_mon = (mounth-1) ; timeinfo->tm_mday = day; timeinfo->tm_sec = sec ; timeinfo->tm_isdst = 1; if (strcmp( pm, "PM" ) == 0 ) { if (hour != 12){ hour = hour + 12; } }else{ if (hour == 12) { hour = 0; }; } timeinfo->tm_hour = hour ; timeinfo->tm_min = minute; time_t totsec = mktime ( timeinfo ); if (i==0) { cout << "Filling time offset..." << totsec << endl; tfirst = totsec; cout << ctime(&totsec) << endl; HVtree.SetBranchAddress( "offset" , &tfirst ); br = HVtree.GetBranch( "offset" ); br->Fill(); } i++; index = mod*100+ch; HVtree.SetBranchAddress( Form( "channel_%d", index ), &info.sts ); if ( ( i % 10000 ) == 0 ) cout << "Event " << i << " " << ctime(&info.t) << endl; info.sts = sts; info.vm = Vm; info.im = Im; info.t = totsec; br = HVtree.GetBranch( Form( "channel_%d", index ) ); br->Fill(); time_temp=totsec; } fclose(fp); filename = fileout ; cout << "Tree created " << endl; cout << "Last time--->" << time_temp << " " << ctime(&time_temp) << endl; HVtree.Print(); f.Write(); }