1 //====================================
2 //last modified FK 6.NOV 2009
3 //====================================
8 #include "AliJBaseCard.h"
10 //ClassImp(AliJBaseCard);
12 AliJBaseCard::AliJBaseCard() :
22 AliJBaseCard::AliJBaseCard(const char *filename) :
31 strcpy(fcardname, filename); //needed in PrintOut()
33 if( strlen( filename ) > 0 ){
35 //---- r e a d t h e c a r d ----
36 ReadInputCard();//read config file fill Tvectors
41 AliJBaseCard& AliJBaseCard::operator=(const AliJBaseCard& obj){
47 AliJBaseCard::~AliJBaseCard(){
52 unsigned int AliJBaseCard::GetTVectorIndex(TString keyword, int tol){
54 // //returns findex of a TVector according to its position in std::hash_map
55 // std::hash_map< TString, unsigned int >::iterator iter = MapKeyWordToTVector.begin();
56 // iter = MapKeyWordToTVector.find(keyword);
57 // if(iter != MapKeyWordToTVector.end()){
58 // return (unsigned int) iter->second;
60 // cout << "ERROR: \""<<keyword.Data()<<"\" must be defined "<< endl;
69 //cout<<"ALIJBASECARD_SEARCH_MODE_HASHLIST"<<endl;
70 TNamed * ko = (TNamed*)fKeyTable.FindObject( keyword.Data() );
72 if(ko) ind = ko->GetUniqueID();
74 for( UInt_t ii=0;ii<fKeyWordVector.size();ii++ ){
75 if( fKeyWordVector[ii] == keyword ) return i;
78 cout << "ERROR: \""<<keyword.Data()<<"\" must be defined "<< endl;
81 cout << "Warning: \""<<keyword.Data()<<"\" is not exist. return default value "<< endl;
89 int AliJBaseCard::GetN(TString keyword){
90 //returns size of TVector
91 unsigned int findex = GetTVectorIndex(keyword);
92 return (int) fValuesVector[findex].GetNrows();
95 TVector * AliJBaseCard::GetVector(TString keyword ){
96 int findex = GetTVectorIndex(keyword);
97 return &fValuesVector[findex];
100 float AliJBaseCard::Get(TString keyword, int VectorComponent){
101 //returns VectorComponent Component of fValuesVector TVector for given keyword
102 int findex = GetTVectorIndex(keyword);
103 if(0<=VectorComponent && VectorComponent<GetNwithIndex(findex)){
104 return fValuesVector[findex](VectorComponent+1);
106 cout<<"ERROR: fValuesVector findex out of range "<<keyword.Data()<<endl;
107 cout << " Max findex: " << GetN(keyword) - 1<< " Asked: " << VectorComponent << endl;
112 TString AliJBaseCard::GetStr(TString keyword ){
113 int findex = GetTVectorIndex(keyword, 1);
114 if( findex < 0 ) return TString("");
115 return fValueString[findex];
119 void AliJBaseCard::InitCard(){
120 // set the length of fIndexVector and disable all indices
123 void AliJBaseCard::FinishCard(){
124 // recompute fast idices
127 void AliJBaseCard::ReadInputCard(){
130 char buffer[kMaxDimBuffer];
133 cout << "Reading fcard from file: " << fcardname << endl;
134 incard.open(fcardname,ios::in);
137 cout<<"ERROR: Config file <"<<fcardname<<"> not found!"<<endl;
143 while(!incard.eof()){ //loop over the input fcard
145 incard.getline(buffer,kMaxDimBuffer); //read a line
147 if(fnentry > 1000){//is the file reasonably long?
148 cout<<"Maximum number of 1000 lines reached in AliJBaseCard.C"<<endl;
152 ReadInputLine( buffer );
162 void AliJBaseCard::ReadInputLine( const char *buffer ){
167 TString tstr(buffer); //convert the line in the buffer to TString
169 if( tstr.BeginsWith("#") ) return;//skipp comments
170 tstr.ReplaceAll("\t"," ");//get rid of tabelators
172 //remove comment in line
173 Ssiz_t startOFcomment = tstr.First('#');
174 if(startOFcomment>0){
175 tstr.Remove(startOFcomment,tstr.Length() - startOFcomment);
178 //remove white spaces from the begining
179 if(tstr.BeginsWith(" ")){
180 Ssiz_t startOFkeyword = 0;
182 TString s = tstr[startOFkeyword];
183 if(s.CompareTo(" ")) break;
186 tstr.Replace(0,startOFkeyword,"",0);
190 TObjArray *lineContents = tstr.Tokenize(" ");
192 if(lineContents->GetEntriesFast() < 1) return;//skipp empty lines
194 //----- Read a keyword -----
195 TString entryname = ((TObjString*)(lineContents->At(0)))->String(); //read a key word
197 if(lineContents->GetEntriesFast() == 1){
198 cout<<"WARNING: single keyword "<<entryname.Data()<<" on line"<<endl;
202 //----- Read parameters -----
203 vector< float > items;//auxiliary vector
205 for(int i=1; i<lineContents->GetEntriesFast(); i++){ //loop over the numbers
206 TString token = ((TObjString*)(lineContents->At(i)))->String();//read a string
209 items.push_back(token.Atof());//if string is float number store it to vector
212 // cout<<"ERROR: char "<<token.Data()<<" among numbers"<<endl;
215 }//end of the for loop
218 //Fill TVectors and Map
219 fKeyWordVector.push_back( entryname.Data() );//put the new keyword at the end of the array
222 fValuesVector.push_back( TVector( 1, items.size(), &items[0]) );//store TVector to array
223 fValueString.push_back( ((TObjString*)(lineContents->At(1)))->String() );
225 // MapKeyWordToTVector.insert(pair<TString, unsigned int>(entryname.Data(),fKeyWordVector.size()-1));
226 AddToKeyTable( entryname, fValuesVector.size()-1 );
231 lineContents->~TObjArray();//remove array from heap
234 void AliJBaseCard::PrintOut(){
236 cout<<endl<<"======== "<<fcardname<<" ========="<<endl;
237 for(unsigned int i=0; i<fValuesVector.size();i++){
238 cout<<Form("%15s",fKeyWordVector[i].Data());//print keyword
239 cout<<" (dim ="<<fValuesVector[i].GetNrows()<<") ";//print size of TVector
240 for(int j=1; j<=fValuesVector[i].GetNrows(); j++){
241 cout<<fValuesVector[i][j]<<" ";//TVector components
248 void AliJBaseCard::WriteCard(TDirectory *file){
250 cout<<endl<<"====== Writing into file ========="<<endl;
252 if(!file->GetDirectory("JCard")) {
253 file->mkdir("JCard");//directory to store input parameters
256 for(unsigned int i=0;i<fValuesVector.size();i++){
257 fValuesVector[i].Write(fKeyWordVector[i]);