#include #include #include #include #include #include #include #include using namespace RAT; using namespace RAT::DU; #include #include #include #include #include ClassImp( RAT::DU::DSReader ) DSReader::DSReader( const std::string& filename, const bool useMeta ) : fUseMeta(useMeta) { string data = getenv("GLG4DATA"); Log::Assert( data != "", "DSReader::DSReader: GLG4DATA is empty, where is the data?" ); fT = new TChain("T"); fRunT = new TChain("runT"); Add( filename ); fCurrentEntry = 0; fDS = new DS::Entry(); fT->SetBranchAddress("ds", &fDS); fT->GetEntry( fCurrentEntry ); fCurrentRun = 0; fRun = new DS::Run(); fRunT->SetBranchAddress( "run", &fRun ); fRunT->GetEntry( 0 ); BeginOfRun(); } DSReader::DSReader( const std::vector& filenames, const bool useMeta ) : fUseMeta(useMeta) { string data = getenv("GLG4DATA"); Log::Assert( data != "", "DSReader::DSReader: GLG4DATA is empty, where is the data?" ); fT = new TChain("T"); fRunT = new TChain("runT"); for( size_t iFile = 0; iFile < filenames.size(); iFile++ ) Add( filenames[iFile] ); fCurrentEntry = 0; fDS = new DS::Entry(); fT->SetBranchAddress("ds", &fDS); fT->GetEntry( fCurrentEntry ); fCurrentRun = 0; fRun = new DS::Run(); fRunT->SetBranchAddress( "run", &fRun ); fRunT->GetEntry( 0 ); BeginOfRun(); } DSReader::~DSReader() { delete fT; delete fRunT; delete fRun; delete fDS; } void DSReader::BeginOfRun() { DB* db = DB::Get(); db->BeginOfRun(*fRun); if (!fRun->GetMCFlag() || fRun->GetRunID() != 0) { db->LoadDefaultPlaneLocks(); } try { db->Load( db->GetLink("DETECTOR")->GetS( "geo_file" ) ); db->Load( db->GetLink("DETECTOR")->GetS( "pmt_info_file" ) ); } catch(DBNotFoundError &e) { std::string msg = Form("%s : Attempting to fetch %s[%s].%s", e.what(), e.table.c_str(), e.index.c_str(), e.field.c_str()); msg += "\n Hint: Be sure that RAT::DB loads a DETECTOR table with the appropriate geometry and PMT information."; Log::Die(msg); } Utility::Get()->BeginOfRun(); db->EndOfBeginOfRun(); } void DSReader::Add( const std::string& filename ) { TFileCollection * col = new TFileCollection(); col->Add(filename.c_str()); //Assert that the list is bigger than 0 Log::Assert(col->GetNFiles()>0, "DSReader::Add: File name/pattern yields no valid files!"); // col will have already a consolidated list of existing files fT->AddFileInfoList(dynamic_cast(col->GetList())); fRunT->AddFileInfoList(dynamic_cast(col->GetList())); delete col; fTotalEntries = fT->GetEntries(); fTotalRuns = fRunT->GetEntries(); DB::Get()->AllowDanger(); RAT::Log::ClearDBTraceMap(); DB::Get()->Clear(); // Need some way not to clear defaults... DB::Get()->LoadDefaults(); // Load the Meta information fT->GetFile()->GetObject("meta",fMeta); if(fMeta){ MetaInformation::Get()->Initialise(fMeta); } else{ warn<<"*** DSReader::Add: WARNING ***"<Initialise(); } if( fUseMeta ){ DBCommandLoader::LoadCommands( *fMeta ); } } const DS::Entry& DSReader::GetEntry( const size_t entry ) { if( entry >= fTotalEntries ) throw DS::DataNotFound( "DSReader", "GetEntry" ); const unsigned int previousRun = GetRun().GetRunID(); fT->GetEntry( entry ); if( GetRun().GetRunID() != previousRun ) BeginOfRun(); return *fDS; } const DS::Run& DSReader::GetRun() { return GetRunByRunID( fDS->GetRunID() ); } const DS::Run& DSReader::GetRunByRunID( const unsigned int runID ) { if( runID == fRun->GetRunID() ) return *fRun; for( size_t iRun = 0; iRun < GetRunCount(); iRun++ ) { const DS::Run& run = GetRunByIndex( iRun ); if( run.GetRunID() == runID ) return run; } throw DS::DataNotFound( "DSReader", "GetRunByRunID" ); } const DS::Run& DSReader::GetRunByIndex( const size_t index ) { if( index >= fTotalRuns ) throw DS::DataNotFound( "DSReader", "GetRunByIndex" ); fRunT->GetEntry( index ); return *fRun; }