#include #include #include #include #include #include #include #include using namespace RAT; using namespace RAT::DU; #include #include #include #include #include #include using namespace std; ClassImp( RAT::DU::SOCReader ) SOCReader::SOCReader( const std::string& filename, const bool useMeta ) : fUseMeta(useMeta) { string data = getenv("GLG4DATA"); Log::Assert( data != "", "SOCReader::SOCReader: GLG4DATA is empty, where is the data?" ); fT = new TChain("T"); fRunT = new TChain("runT"); Add( filename ); fCurrentSOC = 0; fSOC = new DS::SOC(); fT->SetBranchAddress( "soc", &fSOC ); fT->GetEntry( fCurrentSOC ); fCurrentRun = 0; fRun = new DS::Run(); fRunT->SetBranchAddress( "run", &fRun ); fRunT->GetEntry( 0 ); BeginOfRun(); } SOCReader::SOCReader( const std::vector& filenames, const bool useMeta ) : fUseMeta(useMeta) { string data = getenv("GLG4DATA"); Log::Assert( data != "", "SOCReader::BeginOfRun: 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] ); fCurrentSOC = 0; fSOC = new DS::SOC(); fT->SetBranchAddress( "ds", &fSOC ); fT->GetEntry( fCurrentSOC ); fCurrentRun = 0; fRun = new DS::Run(); fRunT->SetBranchAddress( "run", &fRun ); fRunT->GetEntry( 0 ); BeginOfRun(); } SOCReader::~SOCReader() { delete fT; delete fRunT; delete fRun; delete fSOC; } void SOCReader::BeginOfRun() { DB* db = DB::Get(); 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 SOCReader::Add( const std::string& filename ) { // First consolidate the filename to avoid crashes due to // having no valid files TFileCollection * col = new TFileCollection(); col->Add(filename.c_str()); //Assert that the list is bigger than 0 Log::Assert(col->GetNFiles()>0, "SOCReader::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; fTotalSOC = fT->GetEntries(); fTotalRuns = fRunT->GetEntries(); DB::Get()->AllowDanger(); RAT::Log::ClearDBTraceMap(); DB::Get()->Clear(); // Need some way not to clear defaults DB::Get()->LoadDefaults(); if( fUseMeta ) { DS::Meta* metaInfo = reinterpret_cast( fT->GetFile()->Get( "meta" ) ); DBCommandLoader::LoadCommands( *metaInfo ); } } const DS::SOC& SOCReader::GetSOC( const size_t index ) { if( index >= fTotalSOC ) throw DS::DataNotFound( "SOCReader", "GetEV" ); const unsigned int previousRun = GetRun().GetRunID(); fT->GetEntry( index ); if( previousRun != GetRun().GetRunID() ) BeginOfRun(); return *fSOC; } const DS::Run& SOCReader::GetRun() { return GetRunByRunID( fSOC->GetRunID() ); } const DS::Run& SOCReader::GetRunByRunID( const size_t 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( "SOCReader", "GetRunByRunID" ); } const DS::Run& SOCReader::GetRunByIndex( const size_t index ) { if( index >= fTotalRuns ) throw DS::DataNotFound( "SOCReader", "GetRunByIndex" ); fRunT->GetEntry( index ); return *fRun; }