29 |
#include <varDump/VarDumpEvent.h> |
#include <varDump/VarDumpEvent.h> |
30 |
#include <varDump/VarDumpRecord.h> |
#include <varDump/VarDumpRecord.h> |
31 |
#include <physics/S4/S4Event.h> |
#include <physics/S4/S4Event.h> |
|
|
|
32 |
// |
// |
33 |
#include <PamelaDBOperations.h> |
#include <PamelaDBOperations.h> |
34 |
// |
// |
35 |
using namespace std; |
using namespace std; |
36 |
using namespace pamela; |
using namespace pamela; |
|
//using namespace yngn::util; |
|
37 |
|
|
38 |
/** |
/** |
39 |
* Constructor. |
* Constructor. |
168 |
}; |
}; |
169 |
|
|
170 |
/** |
/** |
171 |
|
* Store the olderthan variable |
172 |
|
* @param olderthan |
173 |
|
*/ |
174 |
|
void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
175 |
|
olderthan = oldthan; |
176 |
|
}; |
177 |
|
|
178 |
|
/** |
179 |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
180 |
*/ |
*/ |
181 |
Bool_t PamelaDBOperations::SetID_RAW(){ |
Bool_t PamelaDBOperations::SetID_RAW(){ |
187 |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
188 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
189 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
190 |
if (result == NULL) throw -4; |
if ( result == NULL ) throw -4; |
191 |
row = result->Next(); |
row = result->Next(); |
192 |
if (row == NULL) return false; |
if ( !row ) return(false); |
193 |
delete result; |
delete result; |
194 |
id = (UInt_t)atoll(row->GetField(0)); |
id = (UInt_t)atoll(row->GetField(0)); |
195 |
return(true); |
return(true); |
556 |
lastPkt = glrun->GetRUNTRAILER_PKT(); |
lastPkt = glrun->GetRUNTRAILER_PKT(); |
557 |
}; |
}; |
558 |
// |
// |
559 |
if ( mishead && mistrail && lastev+1 == firstev ) throw -14; // run with no events, no runtrailer, no runheader... unsupported |
if ( mishead && mistrail && lastev+1 == firstev ) throw -14; // run with no events, no runtrailer, no runheader... unsupported should never arrive here |
560 |
// |
// |
561 |
if ( mishead ) { |
if ( mishead ) { |
562 |
glrun->Set_GL_RUNH0(); |
glrun->Set_GL_RUNH0(); |
674 |
}; |
}; |
675 |
// |
// |
676 |
TTree *T = 0; |
TTree *T = 0; |
677 |
|
Int_t signal = 0; |
678 |
// |
// |
679 |
UInt_t nevent = 0; |
UInt_t nevent = 0; |
680 |
UInt_t recEntries = 0; |
UInt_t recEntries = 0; |
728 |
// |
// |
729 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
730 |
existsts = true; |
existsts = true; |
731 |
goto out; |
goto eout; |
732 |
}; |
}; |
733 |
// |
// |
734 |
}; |
}; |
736 |
}; |
}; |
737 |
if ( !existsts ) { // try with runheader and runtrailer |
if ( !existsts ) { // try with runheader and runtrailer |
738 |
// |
// |
739 |
|
if ( IsDebug() ) printf(" No ts mcmd \n"); |
740 |
|
signal = 2; |
741 |
|
// |
742 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
TTree *rh=(TTree*)file->Get("RunHeader"); |
743 |
if ( !rh || rh->IsZombie() ) throw -17; |
if ( !rh || rh->IsZombie() ) throw -17; |
744 |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
748 |
// |
// |
749 |
rt->SetBranchAddress("RunTrailer", &runt); |
rt->SetBranchAddress("RunTrailer", &runt); |
750 |
// |
// |
|
// Int_t rhev = rh->GetEntries(); |
|
|
// Int_t rtev = rt->GetEntries(); |
|
|
// |
|
751 |
if ( rhev > 0 ){ |
if ( rhev > 0 ){ |
752 |
rh->GetEntry(0); |
rh->GetEntry(0); |
753 |
// |
// |
758 |
// |
// |
759 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
760 |
existsts = true; |
existsts = true; |
761 |
goto out; |
goto eout; |
762 |
}; |
}; |
763 |
// |
// |
764 |
}; |
}; |
765 |
if ( rtev > 0 ){ |
if ( rtev > 0 ){ |
766 |
|
// |
767 |
|
if ( IsDebug() ) printf(" No runheader \n"); |
768 |
|
signal = 6; |
769 |
|
// |
770 |
rt->GetEntry(0); |
rt->GetEntry(0); |
771 |
// |
// |
772 |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
776 |
// |
// |
777 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
778 |
existsts = true; |
existsts = true; |
779 |
goto out; |
goto eout; |
780 |
}; |
}; |
781 |
// |
// |
782 |
|
} else { |
783 |
|
if ( IsDebug() ) printf(" No runheader \n"); |
784 |
}; |
}; |
785 |
}; |
}; |
786 |
// |
// |
787 |
if ( !existsts ){ // try with inclination mcmd |
if ( !existsts ){ // try with inclination mcmd |
788 |
|
// |
789 |
|
if ( IsDebug() ) printf(" No runtrailer \n"); |
790 |
|
signal = 14; |
791 |
|
// |
792 |
Double_t timesync = 0.; |
Double_t timesync = 0.; |
793 |
for (UInt_t i=0; i<nevent;i++){ |
for (UInt_t i=0; i<nevent;i++){ |
794 |
// |
// |
817 |
TYPE = 666; |
TYPE = 666; |
818 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
819 |
existsts = true; |
existsts = true; |
820 |
goto out; |
goto eout; |
821 |
}; |
}; |
822 |
}; |
}; |
823 |
}; |
}; |
824 |
// |
// |
825 |
if ( !existsts && obt0 ){ // insert timesync by hand |
if ( !existsts && obt0 ){ // insert timesync by hand |
826 |
|
// |
827 |
|
if ( IsDebug() ) printf(" No incl mcmd \n"); |
828 |
|
signal = 30; |
829 |
|
// |
830 |
OBT = obt0; |
OBT = obt0; |
831 |
TSYNC = tsync; |
TSYNC = tsync; |
832 |
TYPE = 999; |
TYPE = 999; |
833 |
existsts = true; |
existsts = true; |
834 |
goto out; |
goto eout; |
835 |
}; |
}; |
836 |
// |
// |
837 |
out: |
eout: |
838 |
// |
// |
839 |
if ( !existsts ) throw -3; |
if ( !existsts ) throw -3; |
840 |
// |
// |
850 |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
851 |
// |
// |
852 |
delete result; |
delete result; |
853 |
return(0); |
return(signal); |
854 |
} |
} |
855 |
|
|
856 |
/** |
/** |
928 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
929 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
930 |
// |
// |
931 |
if ( !result ) return(8); |
if ( !result ) throw -4;; |
932 |
row = result->Next(); |
row = result->Next(); |
933 |
if ( !row ) return(16); |
if ( !row ) return(16); |
934 |
if ( row->GetField(1) ){ |
if ( row->GetField(1) ){ |
935 |
this->SetBOOTnumber((UInt_t)atoll(row->GetField(1))); |
this->SetBOOTnumber((UInt_t)atoll(row->GetField(1))); |
936 |
return(1); |
return(1); |
937 |
}; |
}; |
938 |
if ( !row->GetField(0) ) return(8); |
if ( !row->GetField(0) ) throw -26; |
939 |
// |
// |
940 |
UInt_t idRaw = (UInt_t)atoll(row->GetField(0)); |
UInt_t idRaw = (UInt_t)atoll(row->GetField(0)); |
941 |
// |
// |
945 |
trDumpEv = (TTree*)file->Get("VarDump"); |
trDumpEv = (TTree*)file->Get("VarDump"); |
946 |
if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20; |
if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20; |
947 |
// |
// |
|
if (trDumpEv == NULL) return(2); |
|
|
// |
|
948 |
VarDumpEvent *vde = 0; |
VarDumpEvent *vde = 0; |
949 |
VarDumpRecord *vdr = 0; |
VarDumpRecord *vdr = 0; |
950 |
// |
// |
951 |
trDumpEv->SetBranchAddress("VarDump", &vde); |
trDumpEv->SetBranchAddress("VarDump", &vde); |
952 |
if (trDumpEv->GetEntries() > 0){ |
if ( trDumpEv->GetEntries() > 0 ){ |
953 |
trDumpEv->GetEntry(0); |
Bool_t found = false; |
954 |
vde->Records->GetEntries(); |
for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){ |
955 |
if ( !vde->Records->GetEntries() ){ |
trDumpEv->GetEntry(i); |
956 |
if ( !this->GetBOOTnumber() ) return(4); |
vde->Records->GetEntries(); |
957 |
} else { |
if ( vde->Records->GetEntries()>0 ){ |
958 |
|
found = true; |
959 |
|
goto fill; |
960 |
|
}; |
961 |
|
}; |
962 |
|
fill: |
963 |
|
if ( found ){ |
964 |
|
// |
965 |
vdr = (VarDumpRecord*)vde->Records->At(6); |
vdr = (VarDumpRecord*)vde->Records->At(6); |
966 |
|
// |
967 |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
968 |
|
// |
969 |
|
} else { |
970 |
|
if ( !this->GetBOOTnumber() ) return(4); |
971 |
}; |
}; |
972 |
} else { |
} else { |
973 |
if ( !this->GetBOOTnumber() ) return(2); |
if ( !this->GetBOOTnumber() ) return(2); |
1053 |
// |
// |
1054 |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
1055 |
// |
// |
1056 |
if ( (ptt-1) < 0 ) throw -15; |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
1057 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
1058 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
1059 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
1159 |
if ( (UInt_t)evbeft < upperentry-1 ){ |
if ( (UInt_t)evbeft < upperentry-1 ){ |
1160 |
if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER!\n"); |
if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER!\n"); |
1161 |
// |
// |
1162 |
if ( (ptt-1) < 0 ) throw -15; |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
1163 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
1164 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
1165 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
2136 |
if ( firstev == lastev+1 ) { // no events inside the run! |
if ( firstev == lastev+1 ) { // no events inside the run! |
2137 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
2138 |
// |
// |
|
// if ( IsDebug() ) printf(" -> fill the DB \n"); |
|
|
// |
|
2139 |
this->FillClass(); |
this->FillClass(); |
2140 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
2141 |
// |
// |
2346 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
2347 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
2348 |
// |
// |
2349 |
if ( !nevents ) return(0); |
if ( !nevents ) return(1); |
2350 |
// |
// |
2351 |
for (UInt_t i=0; i < nevents; i++){ |
for (UInt_t i=0; i < nevents; i++){ |
2352 |
tr->GetEntry(i); |
tr->GetEntry(i); |
2663 |
tr2->SetBranchAddress("Header", &eh2); |
tr2->SetBranchAddress("Header", &eh2); |
2664 |
nevents2 = tr2->GetEntries(); |
nevents2 = tr2->GetEntries(); |
2665 |
// |
// |
2666 |
if ( !nevents1 && !nevents2 ) return(0); |
if ( !nevents1 && !nevents2 ) return(1); |
2667 |
// |
// |
2668 |
t2 = -1; |
t2 = -1; |
2669 |
Int_t pret2 = 0; |
Int_t pret2 = 0; |
2835 |
stringstream oss; |
stringstream oss; |
2836 |
oss.str(""); |
oss.str(""); |
2837 |
// |
// |
|
CalibS4Event *calibS4 = new CalibS4Event(); |
|
2838 |
TTree *tr = 0; |
TTree *tr = 0; |
2839 |
EventHeader *eh = 0; |
EventHeader *eh = 0; |
2840 |
PscuHeader *ph = 0; |
PscuHeader *ph = 0; |
2848 |
tr = (TTree*)file->Get("CalibS4"); |
tr = (TTree*)file->Get("CalibS4"); |
2849 |
if ( !tr || tr->IsZombie() ) throw -24; |
if ( !tr || tr->IsZombie() ) throw -24; |
2850 |
// |
// |
|
tr->SetBranchAddress("CalibS4", &calibS4); |
|
2851 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
2852 |
// |
// |
2853 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
2854 |
// |
// |
2855 |
if ( !nevents ) return(0); |
if ( !nevents ) return(1); |
2856 |
// |
// |
2857 |
for (UInt_t i = 0; i < nevents; i++){ |
for (UInt_t i = 0; i < nevents; i++){ |
2858 |
// |
// |
2859 |
tr->GetEntry(i); |
tr->GetEntry(i); |
|
TArrayD params = S4_paramfit(calibS4); |
|
2860 |
// |
// |
2861 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
2862 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
2946 |
}; |
}; |
2947 |
// |
// |
2948 |
oss.str(""); |
oss.str(""); |
2949 |
oss << " INSERT INTO GL_S4_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,PARAM_FIT0,PARAM_FIT1,OBT,PKT,BOOT_NUMBER,VALIDATION) " |
oss << " INSERT INTO GL_S4_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,OBT,PKT,BOOT_NUMBER) " |
2950 |
<< " VALUES (NULL,' " |
<< " VALUES (NULL,' " |
2951 |
<< idroot << "','" |
<< idroot << "','" |
2952 |
<< i << "','" |
<< i << "','" |
2953 |
<< fromtime << "','" |
<< fromtime << "','" |
2954 |
<< totime << "','" |
<< totime << "','" |
|
<< dec << params.At(0) << "','" |
|
|
<< dec << params.At(1) << "','" |
|
2955 |
<< obt << "','" |
<< obt << "','" |
2956 |
<< pkt << "','" |
<< pkt << "','" |
2957 |
<< this->GetBOOTnumber() << "','" |
<< this->GetBOOTnumber() << "');"; |
|
<< valid << "');"; |
|
2958 |
// |
// |
2959 |
if ( IsDebug() ) printf(" Insert the new calibration: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" Insert the new calibration: query is \n %s \n",oss.str().c_str()); |
2960 |
// |
// |
2975 |
return(0); |
return(0); |
2976 |
}; |
}; |
2977 |
|
|
2978 |
|
/** |
2979 |
/* |
* Scan the fragment table and move old fragments to the GL_RUN table |
|
* Fit function Received from Valeria Malvezzi 06/02/2006 |
|
|
*/ |
|
|
Double_t fitf(Double_t *x, Double_t *par){ |
|
|
Double_t fitval =(par[0]*x[0])+par[1]; |
|
|
return fitval; |
|
|
} |
|
|
|
|
|
/* |
|
|
* Fit the S4 calibration with a straight line - Received from Valeria Malvezzi 06/02/2006 |
|
2980 |
*/ |
*/ |
2981 |
TArrayD PamelaDBOperations::S4_paramfit(pamela::CalibS4Event *S4CalibEvent){ |
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){ |
2982 |
|
// |
2983 |
//----------- variable initialization ------------------------------------------------- |
TSQLResult *result = 0; |
2984 |
|
TSQLRow *row = 0; |
2985 |
Double_t mip[3]={1, 30, 300}; |
TSQLResult *result2 = 0; |
2986 |
Double_t adc[3] = {0.,0.,0.}; |
TSQLRow *row2 = 0; |
2987 |
|
// |
2988 |
TArrayD parametri(2); |
UInt_t moved = 0; |
2989 |
|
UInt_t timelim = 0; |
2990 |
valid = 1; |
TDatime *time = new TDatime(); |
2991 |
|
// |
2992 |
//------------ Fit calibrations and find parameters to calibrate data ------------------ |
stringstream oss; |
2993 |
pamela::S4::S4Event *s4Record; |
oss.str(""); |
2994 |
|
// |
2995 |
for (Int_t j = 0; j < 4; j++){ |
// |
2996 |
for (Int_t i = 0; i < 128; i++){ |
// |
2997 |
s4Record = (pamela::S4::S4Event*)S4CalibEvent->Records->At((j*128 + i)); |
if ( olderthan < 0 ){ |
2998 |
switch (j) { |
if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n"); |
2999 |
case 0 :{ |
return(1); |
3000 |
adc[0]=adc[0]+((s4Record->S4_DATA)-32); |
}; |
3001 |
break; |
// |
3002 |
}; |
// timelim = now - olderthan |
3003 |
case 1 :{ |
// |
3004 |
adc[1]=adc[1]+((s4Record->S4_DATA)-32); |
time->Set(); |
3005 |
break; |
timelim = (UInt_t)time->Convert() - olderthan; |
3006 |
}; |
time->Set(timelim,false); |
3007 |
case 3 :{ |
// |
3008 |
adc[2]=adc[2]+((s4Record->S4_DATA)-32); |
// check if there are entries older than "olderthan" seconds from now |
3009 |
break; |
// |
3010 |
}; |
oss.str(""); |
3011 |
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
3012 |
|
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
3013 |
|
// |
3014 |
|
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
3015 |
|
result = conn->Query(oss.str().c_str()); |
3016 |
|
// |
3017 |
|
if ( result ){ |
3018 |
|
// |
3019 |
|
row = result->Next(); |
3020 |
|
// |
3021 |
|
if ( row ){ |
3022 |
|
// |
3023 |
|
oss.str(""); |
3024 |
|
oss << " ID= "<< row->GetField(0); |
3025 |
|
// |
3026 |
|
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
3027 |
|
// |
3028 |
|
oss.str(""); |
3029 |
|
oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " |
3030 |
|
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
3031 |
|
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
3032 |
|
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
3033 |
|
<< " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " |
3034 |
|
<< " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
3035 |
|
<< " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " |
3036 |
|
<< " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " |
3037 |
|
<< " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
3038 |
|
<< " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" |
3039 |
|
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
3040 |
|
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
3041 |
|
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
3042 |
|
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; |
3043 |
|
// |
3044 |
|
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
3045 |
|
result2 = conn->Query(oss.str().c_str()); |
3046 |
|
// |
3047 |
|
if ( !result2 ) throw -4; |
3048 |
|
// |
3049 |
|
row2 = result2->Next(); |
3050 |
|
// |
3051 |
|
if ( !row2 ){ |
3052 |
|
// |
3053 |
|
if ( IsDebug() ) printf(" The run is new \n"); |
3054 |
|
if ( IsDebug() ) printf(" -> fill the DB \n"); |
3055 |
|
// |
3056 |
|
glrun->SetID(0); |
3057 |
|
glrun->Fill_GL_RUN(conn); |
3058 |
|
// |
3059 |
|
oss.str(""); |
3060 |
|
oss << " SELECT ID FROM GL_RUN WHERE " |
3061 |
|
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " |
3062 |
|
<< " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " |
3063 |
|
<< " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " |
3064 |
|
<< " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " |
3065 |
|
<< " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; |
3066 |
|
// |
3067 |
|
if ( IsDebug() ) printf(" Look for the ID of the inserted run: query is \n %s \n",oss.str().c_str()); |
3068 |
|
result2 = conn->Query(oss.str().c_str()); |
3069 |
|
// |
3070 |
|
if ( !result2 ) throw -4; |
3071 |
|
// |
3072 |
|
row2 = result2->Next(); |
3073 |
|
// |
3074 |
|
if ( !row2 ) throw -25; |
3075 |
|
// |
3076 |
|
oss.str(""); |
3077 |
|
oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0); |
3078 |
|
if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str()); |
3079 |
|
result2 = conn->Query(oss.str().c_str()); |
3080 |
|
// |
3081 |
|
if ( !result2 ) throw -4; |
3082 |
|
// |
3083 |
|
moved++; |
3084 |
|
// |
3085 |
|
} else { |
3086 |
|
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
3087 |
}; |
}; |
3088 |
|
if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); |
3089 |
|
// |
3090 |
|
// |
3091 |
|
oss.str(""); |
3092 |
|
oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0); |
3093 |
|
if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str()); |
3094 |
|
result2 = conn->Query(oss.str().c_str()); |
3095 |
|
// |
3096 |
|
if ( !result2 ) throw -4; |
3097 |
|
// |
3098 |
}; |
}; |
3099 |
}; |
}; |
3100 |
|
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
3101 |
adc[0]=adc[0]/128; |
return(0); |
3102 |
adc[1]=adc[1]/128; |
}; |
|
adc[2]=adc[2]/128; |
|
|
|
|
|
TGraph *fitpar = new TGraph (3, adc, mip); |
|
|
TF1 *func = new TF1("fitf", fitf, -0., 1000., 2); // definizione della funzione, 2 = num. parametri |
|
|
|
|
|
func->SetParameters(0.3,1.); //inizializzazione dei parametri a 1 |
|
|
func->SetParNames("m","q"); //definisce il nome dei parametri |
|
|
fitpar->Fit(func,"qr"); //fitta fitpar con la funzione func nel range definito nella funzione |
|
|
//fitpar->Fit(func,"r"); //fitta fitpar con la funzione func nel range definito nella funzione |
|
|
|
|
|
parametri[0] = func -> GetParameter(0); |
|
|
parametri[1] = func -> GetParameter(1); |
|
|
|
|
|
if ( parametri[0] < 0. || parametri[0] > 0.5 || parametri[1] < 0.8 || parametri[1] > 1. ) valid = 0; |
|
3103 |
|
|
3104 |
if ( IsDebug() ) printf(" par1 = %g par2 = %g\n",parametri[0],parametri[1]); |
/** |
3105 |
|
* Check if runs are good, i.e. if the tracker calibration is correctly associated.. |
3106 |
return parametri; |
*/ |
3107 |
|
Int_t PamelaDBOperations::ValidateRuns(){ |
3108 |
|
// |
3109 |
|
TSQLResult *result = 0; |
3110 |
|
// TSQLRow *row = 0; |
3111 |
|
// |
3112 |
|
UInt_t timelim = 0; |
3113 |
|
TDatime *time = new TDatime(); |
3114 |
|
// |
3115 |
|
stringstream oss; |
3116 |
|
oss.str(""); |
3117 |
|
// |
3118 |
|
// |
3119 |
|
// |
3120 |
|
if ( olderthan < 0 ){ |
3121 |
|
if ( IsDebug() ) printf(" Do not validate runs \n"); |
3122 |
|
return(1); |
3123 |
|
}; |
3124 |
|
// |
3125 |
|
// timelim = now - olderthan |
3126 |
|
// |
3127 |
|
time->Set(); |
3128 |
|
timelim = (UInt_t)time->Convert() - olderthan; |
3129 |
|
time->Set(timelim,false); |
3130 |
|
// |
3131 |
|
// First of all validate runs with default calibration: |
3132 |
|
// |
3133 |
|
oss.str(""); |
3134 |
|
oss << " UPDATE GL_RUN SET VALIDATION=1 WHERE" |
3135 |
|
<< " VALIDATION = 0 AND TRK_CALIB_USED=104 AND " |
3136 |
|
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
3137 |
|
// |
3138 |
|
if ( IsDebug() ) printf(" Validate runs with trk default calibration inserted before %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
3139 |
|
result = conn->Query(oss.str().c_str()); |
3140 |
|
// |
3141 |
|
if ( !result ) throw -4; |
3142 |
|
// |
3143 |
|
return(0); |
3144 |
}; |
}; |