10 #include <utl/Reader.h>
11 #include <utl/ErrorLogger.h>
13 #include <fwk/CentralConfig.h>
18 #include <TDirectory.h>
20 #include <TEventList.h>
32 T2StatFileManager::~T2StatFileManager()
44 INFO_TERSE(
"Initializing T2StatFileManager ... ");
47 if (fBranch.GetChild(
"verbosity")) {
48 fBranch.GetChild(
"verbosity").GetData(fVerbosity);
49 cout <<
" T2StatFileManager verbosity level = " << fVerbosity << endl;
53 if (fBranch.GetChild(
"CommsCrisisTreat")) {
54 fBranch.GetChild(
"CommsCrisisTreat").GetData(fCommsCrisis);
58 cout <<
" Comms-Crisis Treatment = " << fCommsCrisis << endl;
60 fBranch.GetChild(
"files").GetData(fAllT2Files);
64 msg << fAllT2Files.size() <<
" T2Stat files to be processed.";
69 fDataTree =
new TChain(
"TreeT2Stat");
70 for (
unsigned int i = 0; i < fAllT2Files.size(); ++i) {
71 TFile*
const file = TFile::Open(fAllT2Files[i].c_str(),
"READ");
72 if (!file || file->IsZombie()) {
74 err <<
" T2StatFileManager input file=" << fAllT2Files[i].c_str()
75 <<
" is corrupt! This file will be skipped!";
79 cout <<
" Adding T2Stat file: " << fAllT2Files[i].c_str() <<
" ..."<<endl;
80 fDataTree->Add(fAllT2Files[i].c_str());
86 msg <<
" T2Stat files added.";
92 fAvailableComponents.insert(
"station_in_acquisition");
94 const unsigned int nentries = fDataTree->GetEntries();
98 msg << nentries <<
" entries to be processed... It can take a while..." << endl;
102 unsigned int treeTimeIn;
103 unsigned int treeTimeOut;
106 fDataTree->SetBranchAddress(
"Id", &treeId);
107 fDataTree->SetBranchAddress(
"tIn", &treeTimeIn);
108 fDataTree->SetBranchAddress(
"tOut", &treeTimeOut);
111 fDir =
new TDirectory(
"dir",
"dir", 0);
112 for (
unsigned int i = 0; i < nentries; ++i) {
113 fDataTree->GetEntry(i);
114 if (!i || treeTimeIn < fstartGPS)
115 fstartGPS = treeTimeIn;
116 if (!i || treeTimeOut > fendGPS)
117 fendGPS = treeTimeOut;
119 ostringstream listname;
120 listname <<
"Station_" << treeId;
122 if (fDir->FindObject(listname.str().c_str())) {
123 TEventList*
const list = (TEventList*)fDir->FindObject(listname.str().c_str());
125 cout <<
" Adding to StationList: " << listname.str().c_str() << endl;
127 list->Enter(fDataTree->GetEntryNumber(i));
129 TEventList*
const list =
new TEventList(listname.str().c_str(), listname.str().c_str(), 0, 0);
131 cout <<
" Creating StationList: " << listname.str().c_str() << endl;
132 list->Enter(fDataTree->GetEntryNumber(i));
134 list->DirectoryAutoAdd(fDir);
135 fStationList.push_back(treeId);
145 T2StatFileManager::GetOkFlag(
int& returnData,
146 const std::string& componentProperty,
147 const std::string& componentName,
152 fAvailableComponents.find(componentProperty) == fAvailableComponents.end()) {
153 return VManager::eNotFound;
158 warn <<
"*****************************************************\n"
159 " property=" << componentProperty <<
" component=" << componentName
161 for (IndexMap::const_iterator imap = componentIndex.begin();
162 imap != componentIndex.end(); ++imap) {
163 warn <<
"\"" << imap->first <<
"\"=\"" << imap->second <<
"\" ";
165 warn <<
") NOT found in data source for specified time!\n"
167 "*****************************************************";
170 return VManager::eNotFound;
173 if (componentProperty ==
"station_in_acquisition") {
174 if (componentName ==
"is_in_acquisition") {
175 returnData = GetStationStatus(componentIndex);
176 return VManager::eFound;
180 return VManager::eNotFound;
185 T2StatFileManager::ReadData()
189 INFO(
" enter ReadData ");
191 const unsigned int now = det::Detector::GetInstance().GetTime().GetGPSSecond();
192 if (now < fstartGPS || now > fendGPS) {
194 err <<
"Detector Time not found! GPSTime=" << now <<
", T2File limits: " << fstartGPS <<
" - "<< fendGPS;
203 T2StatFileManager::GetStationStatus(
const IndexMap& componentIndex)
206 const IndexMap::const_iterator iStationId = componentIndex.find(
"stationId");
207 if (iStationId == componentIndex.end()) {
208 INFO_TERSE(
"Called T2StatFileManager with wrong number of arguments!");
212 const unsigned int stationId = boost::lexical_cast<
unsigned int>(iStationId->second);
215 bool stationComm =
false;
217 for (
unsigned int i = 0; i < fStationList.size(); ++i)
218 if (fStationList[i] == stationId)
222 cout <<
"Looking for station: " << stationId << endl;
226 const unsigned int now = det::Detector::GetInstance().GetTime().GetGPSSecond();
228 unsigned int treeTimeIn;
229 unsigned int treeTimeOut;
232 fDataTree->SetBranchAddress(
"Id", &treeId);
233 fDataTree->SetBranchAddress(
"tIn", &treeTimeIn);
234 fDataTree->SetBranchAddress(
"tOut", &treeTimeOut);
237 ostringstream listname;
238 listname <<
"Station_" << stationId;
239 TEventList*
const list = (TEventList*)fDir->FindObject(listname.str().c_str());
240 const int entries = list->GetN();
242 cout << entries <<
" entries for station: " << stationId << endl;
243 for (
int i = 0; i < entries; ++i) {
244 fDataTree->GetEntry(list->GetEntry(i));
245 if (treeId != stationId) {
247 msg <<
"This should never happen!!! Found id " << treeId
248 <<
" in " << listname.str() <<
" list";
251 if (now < treeTimeIn)
253 if (now > treeTimeOut)
255 if (fCommsCrisis && treeTimeOut-treeTimeIn < 120)
261 if (fVerbosity > 1) {
263 warn <<
"*****************************************************\n"
264 " Station: " << stationId <<
" not commisioned\n"
265 "*****************************************************";
#define INFO_TERSE(message)
Macro for logging informational messages.
#define INFO(message)
Macro for logging informational messages.
void Init()
Initialise the registry.
#define REGISTER_S_MANAGER(_name_, _Type_)
#define WARNING(message)
Macro for logging warning messages.
std::map< std::string, std::string > IndexMap
#define ERROR(message)
Macro for logging error messages.
Status
Specifies success or (eventually) various possible failure modes.