int TControlFunctions::InitRootFile() { #if (DEBUG_MSG) cout << "+ TControlfunctions::InitRootFile()" << endl; #endif // Create database file // return 0: file opened successful // return -1: file could not be opened // return -2: file info tree incurrupt or wrong version stringstream dbname; sema_gD->Wait(); dbname << gD.gDatabaseName << ".root"; TDatime dt; rootFile = new TFile(dbname.str().c_str(),"UPDATE","PaCTS TM Archive",FILE_COMPRESSION); if(rootFile->IsZombie()) { cout << "+ ERROR: opening file" << endl; return -1; } thisFileInfo.version = gD.gFileVersion; thisFileInfo.year = dt.GetYear(); thisFileInfo.month = dt.GetMonth(); thisFileInfo.hour = dt.GetHour(); thisFileInfo.minute = dt.GetMinute(); thisFileInfo.second = dt.GetSecond(); strcpy(thisFileInfo.dbname, gD.gDatabaseName.c_str()); string treeName("file_info"); string branchName("creation_info"); // already exists a file information tree? treeFileInfo = (TTree*) rootFile->Get(treeName.c_str()); if(treeFileInfo == NULL) { treeFileInfo = new TTree(treeName.c_str(),"General file information"); treeFileInfo->Branch(branchName.c_str(), &thisFileInfo, "fileVersion/F:year:month:hour:minute:second:database/C"); treeFileInfo->Fill(); treeFileInfo->Write(); } else { // The tree exists! Check the file information: if(!treeFileInfo->GetBranchStatus(branchName.c_str())) { cout << "+ ERROR: file info branch not found" << endl; rootFile->Close(); return -2; } else { TBranch* branch = NULL; branch = treeFileInfo->GetBranch(branchName.c_str()); treeFileInfo->SetBranchAddress(branchName.c_str(), &thisFileInfo); treeFileInfo->GetEntry(0); // Check file version if(thisFileInfo.version != gD.gFileVersion) { cout << "+ ERROR: wrong file version | " << "file: " << thisFileInfo.version << " " << "should be: " << gD.gFileVersion << endl; rootFile->Close(); return -2; } // Check databasename if(strcmp(thisFileInfo.dbname, gD.gDatabaseName.c_str()) > 0 || strcmp(thisFileInfo.dbname, gD.gDatabaseName.c_str()) < 0) { cout << "+ ERROR: wrong sql database | " << "file: " << thisFileInfo.dbname << " " << "should be: " << gD.gDatabaseName << endl; rootFile->Close(); return -2; } } } sema_gD->Post(); delete treeFileInfo; treeFileInfo = NULL; return 0; }