--- yodaUtility/YodaProfiler/PamelaDBOperations.cpp 2006/06/06 07:39:45 1.1 +++ yodaUtility/YodaProfiler/PamelaDBOperations.cpp 2006/06/10 18:07:03 1.2 @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -33,6 +34,16 @@ extern "C" { #include + //INITIZE(YEAR,DIMO) + extern void initize_(); + //FELDCOF(YEAR,DIMO) + extern void feldcof_(float*, float*); + //FELDG(LATI,LONGI,HEIGHT,BNORTH,BEAST,BDOWN,BABS) + extern void feldg_(float*, float*, float*, float*, float*, float*, float*); + //SHELLG(LATI,LONGI,HEIGHT,DIMO,XL,ICODE,BAB1) + extern void shellg_(float*, float*, float*, float*, float*, float*, float*); + //FINDB0(STPS,BDEL,VALUE,BEQU,RR0) + extern void findb0_(float*, float*, bool*, float*, float*); } using namespace log4cxx; @@ -300,6 +311,10 @@ getPacketsNames(packetsNames); for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ tr = (TTree*)file->Get(*Iter); + if (tr == NULL || tr->IsZombie()) { + cout << "Missing Tree: " << *Iter << "\n"; + continue; + } nevents = tr->GetEntries(); tr->SetBranchAddress("Header", &eh); for (UInt_t i = 0; i < nevents; i++){ @@ -752,9 +767,7 @@ if (secRow == NULL) throw YSQLQueryException("No Timesync!"); id_Raw = (ULong64_t)atof(secRow->GetField(0)); } - } - } //Collect the TM_HEADER to assign them the correct TIMESYNC @@ -773,9 +786,6 @@ while (true) { row = result->Next(); if (row == 0) break; - //diff = 1; - //if (syncOBT < (unsigned long)atol(row->GetField(0))) diff = -1; - //absTime = (syncTIME + konstant)*1000 + diff*((unsigned long)atol(row->GetField(0)) - syncOBT); absTime = (ULong64_t)atof(row->GetField(0)) + syncTIME; oss.str(""); oss << " UPDATE TM_HEADER " @@ -830,6 +840,22 @@ throw (YSQLNotConnectedException, YSQLQueryException, YNotExistingFileException, YExistingFileException) { if (conn == 0) throw YSQLNotConnectedException("Connection missing"); + stringstream oss; + TSQLResult *result, *secResult; + TSQLRow *row, *secRow; + ULong64_t offset_date; + + /*Took all the root file related to a specific raw file*/ + oss.str(""); + oss << "SELECT OFFSET_DATE FROM GL_RAW WHERE ID = '" << idRaw << "'"; + result = conn->Query(oss.str().c_str()); + row = result->Next(); + if (row != NULL && row != 0 && row->GetField(0) != NULL && row->GetField(0) != ""){ + offset_date = TDatime(row->GetField(0)).Convert(); + } else { + return NOK; + } + ///TBD: Put the check "IF THE REGISTRY ALREDY EXISTS" before this try. try { if (insertPamelaTM_HEADER(conn, idRaw)){ @@ -844,10 +870,6 @@ return NOK; } - stringstream oss; - TSQLResult *result, *secResult; - TSQLRow *row, *secRow; - const char *idRoot; string registryName; RegistryEvent *registry = new RegistryEvent(); @@ -860,14 +882,13 @@ oss.str(""); oss << "SELECT ID, PATH, NAME FROM GL_ROOT WHERE ID_RAW = '" << idRaw << "'"; result = conn->Query(oss.str().c_str()); - //cout << oss.str().c_str() << "\n"; - //if (result->GetRowCount() == 0) throw YSQLQueryException(oss.str().c_str()); row = result->Next(); if (row == 0) return NOK; idRoot = row->GetField(0); oss.str(""); oss << row->GetField(1) << "/" << row->GetField(2); + file = YFile::Open(oss.str().c_str(), "UPDATE"); pcksList packetsNames; pcksList::iterator Iter; @@ -876,7 +897,10 @@ for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ //cout << "Tree Name: " << *Iter << "\n"; tr = (TTree*)file->Get(*Iter); - + if (tr == NULL || tr->IsZombie()) { + cout << "Missing Tree: " << *Iter << "\n"; + continue; + } //Branch Registry exist? if (!tr->GetBranchStatus("Registry")){ branch = tr->Branch("Registry", "pamela::RegistryEvent", ®istry); @@ -887,22 +911,25 @@ branch->Reset(); } - //This select s temporary. Better selection on time should be done, oss.str(""); oss << "SELECT TLE1, TLE2, TLE3" << " FROM GL_TLE " - << " WHERE VALID_FROM_TIME = 0 "; + << " WHERE FROM_TIME >= 0 "; //cout << oss.str().c_str() << "\n"; result = conn->Query(oss.str().c_str()); row = result->Next(); - if (!(row == 0)){ - string tle1 = row->GetField(0); - string tle2 = row->GetField(1); - string tle3 = row->GetField(2); + if (!(row == NULL)){ + string tle1 = row->GetField(0); + string tle2 = row->GetField(1); + string tle3 = row->GetField(2); cTle tle(tle1, tle2, tle3); orbit = new cOrbit(tle); + } else { + cout << "TLE table empty." << "\n"; + return NOK; } + /*Took all the TM_HEADER rows related to a specific root file and TREE_NAME*/ oss.str(""); oss << "SELECT EVENT, TIME FROM TM_HEADER WHERE ID_ROOT = '" << idRoot << "' " @@ -912,10 +939,11 @@ //Fill the 'Registry' TBranch secRow = secResult->Next(); - while (!(secRow == 0)){ + initize_(); + while (secRow != NULL){ registry->event = (unsigned int)atoi(secRow->GetField(0)); - registry->absTime = (ULong64_t)atof(secRow->GetField(1)); - + registry->absTime = (ULong64_t)atof(secRow->GetField(1)) + (offset_date*1000); + setGeo(orbit, registry); branch->Fill(); secRow = secResult->Next(); /* @@ -2466,14 +2494,36 @@ return row->GetField(0); } -const char* PamelaDBOperations::setGeo(cOrbit *orbit, RegistryEvent ®) +const char* PamelaDBOperations::setGeo(cOrbit *orbit, RegistryEvent* ®) throw (YSQLNotConnectedException, YSQLQueryException){ cEci eci; cCoordGeo coo; - orbit->getPosition(reg.absTime, &eci); + TDatime time = TDatime((reg->absTime/1000)); + orbit->getPosition( (time.GetYear() + time.GetMonth()/12.), &eci); coo = eci.toGeo(); - reg.m_Lat = rad2deg(coo.m_Lat); - reg.m_Lon = rad2deg(coo.m_Lon); - reg.m_Alt = coo.m_Alt; - //rate->Fill(rad2deg(coo.m_Lon), rad2deg(coo.m_Lat)); + reg->m_Lat = rad2deg(coo.m_Lat); + reg->m_Lon = rad2deg(coo.m_Lon); + reg->m_Alt = coo.m_Alt; + cout << "coo.m_Lat " << dec << coo.m_Lat << "\n"; + cout << "rad2deg(coo.m_Lat) " << dec << rad2deg(coo.m_Lat) << "\n"; + float dimo = 0.0; + float year = time.GetYear(); + float bnorth, beast, bdown, babs; + float xl, icode, bab1; + float stps = 0.05; + float bdel = 0.001; + bool value = 0; + year = 2004; + float bequ, rr0; + feldcof_(&year, &dimo); + feldg_(®->m_Lat, ®->m_Lon, ®->m_Alt, &bnorth, &beast, &bdown, &babs); + shellg_(®->m_Lat, ®->m_Lon, ®->m_Alt, &dimo, &xl, &icode, &bab1); + findb0_(&stps, &bdel, &value, &bequ, &rr0); + reg->magnGeo = YMagnGeo(); + reg->magnGeo.setBNorth(bnorth); + reg->magnGeo.setBEast(beast); + reg->magnGeo.setBDown(bdown); + reg->magnGeo.setBAbs(babs); + reg->magnGeo.setL(xl); + reg->magnGeo.setBvsB0(babs/bequ); }