// CbntDataset.cxx #include "dataset_CBNT/CbntDataset.h" #include #include #include #include "dataset_util/XmlElement.h" #include "dataset_util/DtdRegistry.h" #include "dataset_base/DatasetCreator.h" #include "dataset_CBNT/HbookFile.h" using std::string; using std::vector; using std::ostream; using std::cout; using std::endl; using std::auto_ptr; using dset::Url; using dset::Location; using dset::Dataset; using dset::DatasetCreator; using dset::GenericDataset; using dset::CbntDataset; //********************************************************************** // Local data. //********************************************************************** namespace { // For debugging. int verbose = 0; // HBOOK directory names. string NTDIR = "CBNT"; string PWDIR = " "; // Temporary registration of content index. // This should eventually move to ContentId. ContentId NO_KEY_ID = ContentId::register_id(311, CbntDataset::content_id_name()); } // end unnamed namespace //********************************************************************** // FORTRAN declarations. //********************************************************************** extern "C" { // Initialize HBOOK (and zebra and paw). int pawin_(); // Directory listing. void hldir_(const char* path, const char* opt, int lpath, int lopt); // Change directory. void hcdir_(const char* path, const char* opt, int lpath, int lopt); // Read into memory. void hrin_(int* id, int* cycle, int* offset); // hexist bool hexist_(int* id); // Print ntuple properties. void hprnt_(int* id); // Fetch ntuple blocks //void hbloks_(int* id); void hbloks_(const int* id, const int* maxnam, int* nnam, char bnames[][8]); // Description of the variables in a row. void hbname_(int* id, const char* bname, int* address, char* form); void evids_(int* id, int* nevt, int* runs, int* evts); } // end extern "C" //********************************************************************** // Helper functions. //********************************************************************** namespace { //********************************************************************** // HBOOK directory listing. void hldir(string path, string opt) { hldir_(path.c_str(), opt.c_str(), path.size(), opt.size()); } //********************************************************************** // HBOOK directory change. void hcdir(string path, string opt ="") { hcdir_(path.c_str(), opt.c_str(), path.size(), opt.size()); } //********************************************************************** // Return the block names in an ntuple. typedef vector StringList; unsigned int hbloks(int id, StringList& bnames) { bnames.erase(bnames.begin(), bnames.end()); const int maxblk = 1000; int nblk = maxblk; char cbnames[maxblk][8]; hbloks_(&id, &maxblk, &nblk, cbnames); if ( nblk > maxblk ) nblk = maxblk; for ( int iblk=0; iblk); //********************************************************************** } // end unnamed namespace //********************************************************************** // Member functions. //********************************************************************** // Constructor from file. CbntDataset::CbntDataset(Url file, bool locked) : m_have_evflags(false), m_file(file), m_phfile(0) { if ( ! m_file.is_valid() ) { set_error(11); return; } // Set full type. set_fulltype("CbntDataset"); // Set ID's. set_id(); // Set the location. Location loc; loc.files().push_back(file); if ( set_location(loc) != 0 ) { set_error(12); return; } assert( location().files().size() == 1 ); // Open the tuple. int ostat = hbook_file().open(); if ( ostat != 0 ) { set_error(1000 + ostat); return; } // Set directory. if ( verbose > 5 ) { cout << "Starting directory" << endl; hldir(PWDIR, "T"); cout << "Change directory" << endl; } hcdir(NTDIR); if ( verbose > 5 ) { cout << "Final directory" << endl; hldir(PWDIR, "T"); } // Fetch the ntuple block names. int id = 3333; int cycle = 999999; int offset = 0; hrin_(&id, &cycle, &offset); if ( ! hexist_(&id) ) { set_error(31); return; } StringList bnames; int nblk = hbloks(id, bnames); if ( nblk == 0 ) { set_error(32); return; } if ( verbose > 6 ) { cout << "# blocks = " << nblk << endl; for ( int iblk=0; iblk= maxevt ) { set_error(52); return; } for (int ievt=0; ievt