Skip to content
Snippets Groups Projects
Commit 32d761ae authored by Stephen A. Wood's avatar Stephen A. Wood
Browse files

Get detector name -> ID mapping from the map file comments

parent 5f0ea19f
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ inline static bool IsComment( const string& s, string::size_type pos ) ...@@ -33,7 +33,7 @@ inline static bool IsComment( const string& s, string::size_type pos )
} }
//_____________________________________________________________________________ //_____________________________________________________________________________
THcDetectorMap::THcDetectorMap() : fNchans(0) THcDetectorMap::THcDetectorMap() : fNchans(0), fNIDs(0)
{ {
} }
...@@ -64,25 +64,18 @@ Int_t THcDetectorMap::FillMap(THaDetMap *detmap, const char *detectorname) ...@@ -64,25 +64,18 @@ Int_t THcDetectorMap::FillMap(THaDetMap *detmap, const char *detectorname)
// Translate detector name into and ID // Translate detector name into and ID
// For now just long if then else. Could get it from the comments // For now just long if then else. Could get it from the comments
// at the beginning of the map file. // at the beginning of the map file.
Int_t did; Int_t did=-1;
if(strcasecmp(detectorname,"HDC")==0) { for(Int_t i=0; i < fNIDs; i++) {
did = 1; if(strcasecmp(detectorname,fIDMap[i].name) == 0) {
} else if (strcasecmp(detectorname,"HSCIN")==0) { did = fIDMap[i].id;
did = 2; break;
} else if (strcasecmp(detectorname,"HCER")==0) { }
did = 3; }
} else if (strcasecmp(detectorname,"HCAL")==0) { if(did < 0) {
did = 4; cout << "FillMap Error: No detector ID registered for " << detectorname << endl;
} else if (strcasecmp(detectorname,"HMISC")==0) { cout << " Using detector id of 0" << endl;
did = 5;
} else if (strcasecmp(detectorname,"GMISC")==0) {
did = 6;
} else if (strcasecmp(detectorname,"HAERO")==0) {
did = 7;
} else {
did = 0; did = 0;
} }
// Start SHMS with S? What about SOS?
mlist.clear(); mlist.clear();
// cout << "fNchans=" << fNchans << endl; // cout << "fNchans=" << fNchans << endl;
...@@ -207,10 +200,24 @@ void THcDetectorMap::Load(const char *fname) ...@@ -207,10 +200,24 @@ void THcDetectorMap::Load(const char *fname)
while(getline(ifile,line)) { while(getline(ifile,line)) {
// BLank line or comment // BLank line or comment
if(line.empty() if(line.empty()) continue;
|| (start = line.find_first_not_of( whtspc )) == string::npos if((start = line.find_first_not_of( whtspc )) == string::npos) continue;
|| IsComment(line, start) ) if(IsComment(line, start)) { // Check for ID assignments
// Get rid of all white space
while((pos=line.find_first_of(whtspc)) != string::npos) {
line.erase(pos,1);
}
line.erase(0,1); // Erase "!"
if(! ((pos=line.find("_ID=")) == string::npos)) {
fIDMap[fNIDs].name = new char [pos+1];
strncpy(fIDMap[fNIDs].name,line.c_str(),pos);
fIDMap[fNIDs].name[pos] = '\0';
start = (pos += 4); // Move to after "="
while(isdigit(line.at(pos++)));
fIDMap[fNIDs++].id = atoi(line.substr(start,pos).c_str());
}
continue; continue;
}
// cout << "MAPA: " << line << endl; // cout << "MAPA: " << line << endl;
...@@ -294,6 +301,12 @@ void THcDetectorMap::Load(const char *fname) ...@@ -294,6 +301,12 @@ void THcDetectorMap::Load(const char *fname)
fNchans++; fNchans++;
} }
} }
cout << endl << " Detector ID Map" << endl << endl;
for(Int_t i=0; i < fNIDs; i++) {
cout << i << " ";
cout << fIDMap[i].name << " " << fIDMap[i].id << endl;
}
cout << endl;
} }
...@@ -49,6 +49,13 @@ class THcDetectorMap : public TObject { ...@@ -49,6 +49,13 @@ class THcDetectorMap : public TObject {
}; };
std::list<ModChanList> mlist; std::list<ModChanList> mlist;
struct IDMap {
char* name;
Int_t id;
};
IDMap fIDMap[50];
Int_t fNIDs; /* Number of detector IDs */
bool compare(const ChaninMod *first, const ChaninMod *second); bool compare(const ChaninMod *first, const ChaninMod *second);
protected: protected:
......
...@@ -71,7 +71,7 @@ THaAnalysisObject::EStatus THcHodoscope::Init( const TDatime& date ) ...@@ -71,7 +71,7 @@ THaAnalysisObject::EStatus THcHodoscope::Init( const TDatime& date )
// appropriate detector ID in the FillMap call // appropriate detector ID in the FillMap call
if( gHcDetectorMap->FillMap(fDetMap, "HSCIN") < 0 ) { if( gHcDetectorMap->FillMap(fDetMap, "HSCIN") < 0 ) {
Error( Here(here), "Error filling detectormap for %s.", Error( Here(here), "Error filling detectormap for %s.",
"detectorname"); "HSCIN");
return kInitError; return kInitError;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment